MCP Server Boilerplate
A basic MCP server that provides an addition tool and an API key retrieval tool, designed as a boilerplate for integration with Cursor AI.
README
MCP Server in Node.js
Overview
MCP (Model Context Protocol) is a framework that allows you to integrate custom tools into AI-assisted development environments—such as Cursor AI. MCP servers expose functionality (like data retrieval or code analysis) so that an LLM-based IDE can call these tools on demand. Learn more about MCP in the Model Context Protocol Introduction.
This project demonstrates an MCP server built in Node.js that provides two basic tools. One tool, add, accepts two numbers and returns their sum, while the other, getApiKey, retrieves the API key from the environment (via the API_KEY variable).
Requirements
- Node.js: Version 20 or higher is required.
Features
- MCP Integration: Exposes tool functionality to LLM-based IDEs.
- Addition Tool: Accepts two numeric parameters and returns their sum.
- Env Var Retrieval: Demonstrates how to load an example environment variable from the configuration file.
- Input Validation: Uses Zod for schema validation.
- Standard I/O Transport: Connects via
StdioServerTransportfor integration with development environments.
Installation
-
Clone the Repository
git clone <repository_url> cd <repository_directory> -
Install Dependencies
You can install the project dependencies in one of two ways:
Option 1: Install using the existing
package.jsonSimply run:
npm installOption 2: Install dependencies manually
If you prefer, delete the existing
package.jsonand install the required packages manually:npm install @modelcontextprotocol/sdk @coinpaprika/api-nodejs-client zodThen, update the newly generated
package.jsonfile to include the following line, which enables ES Modules:"type": "module"
Integrating with Cursor AI
This project includes a ./cursor subdirectory that contains an mcp.json file for configuring the MCP server. Cursor AI uses this file to automatically discover and launch your MCP server. Open the file and update the fields as follows:
The ./cursor/mcp.json Structure
Below is the full JSON structure of the configuration file:
{
"mcpServers": {
"MCP Server Boilerplate": {
"command": "/path/to/node",
"args": ["/path/to/mcp-server.js"],
"env": {
"API_KEY": "abc-1234567890"
}
}
}
}
-
mcpServers:
An object mapping server names to their configuration. -
MCP Server Boilerplate:
This is the key for your server configuration. You can name it as you like. -
command:
Specifies the absolute path to your Node.js executable. For example:/home/john/.nvm/versions/node/v20.13.1/bin/node -
args:
An array containing the absolute path to your MCP server file. For example:["/home/john/mcp-server-node/index.js"] -
env: (Optional)
Defines environment variables for your MCP server process. In this example, theAPI_KEYis set to"abc-1234567890". Adjust this value as needed for your environment.
You can verify the absolute path to your Node.js executable by running which node in your terminal.
Optional: Configuration Automation Scripts
Easily configure your local environment by automatically updating the mcp.json file with the correct absolute paths. To apply your local settings, run the following commands from your project root:
chmod +x ./scripts/update_config.sh
./scripts/update_config.sh
This script replaces the placeholder paths in mcp.json with your machine’s absolute paths for Python and the server script, ensuring your configuration settings are always accurate.
Optional: Global Cursor settings
You can also move the mcp.json file to your global Cursor AI configuration directory located at ~/.cursor to make the configuration available globally.
Using the MCP Tool in Cursor Composer (Agent Mode)
With the MCP server integrated into Cursor AI and with Agent mode enabled in Cursor Composer, simply use a natural language prompt like:
add 3 and 5
or
what is my API key?
The AI agent will infer the available add or getApiKey tool from your MCP server and execute it accordingly.
Code Overview
The project comprises the following key parts:
-
MCP Server Initialization:
The MCP server is instantiated usingMcpServerfrom the MCP SDK and connected viaStdioServerTransport. -
Tool Definitions:
- add:
Defined with a Zod schema that accepts two numbers (aandb) and returns their sum as text. - getApiKey:
Retrieves the API key from the environment variableAPI_KEYand returns it as text.
- add:
What is MCP?
Model Context Protocol (MCP) provides a standardized approach to integrate custom tools into AI-assisted development environments. With MCP, you can define tools that perform specific tasks—such as retrieving external data, validating code, or enforcing coding standards—and the AI assistant in your IDE can call these tools automatically based on context. This helps improve developer productivity, ensures consistent quality, and streamlines workflows.
References & Resources
- Model Context Protocol: typescript-sdk
- Use Your Own MCP on Cursor in 5 Minutes
- Model Context Protocol Introduction
License
This project is licensed under the MIT License.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。