
lucianoayres/mcp-server-node 是从 https://github.com/lucianoayres/mcp-server-node. 导入的 MCP 服务器候选
概览
lucianoayres/mcp-server-node 是从 https://github.com/lucianoayres/mcp-server-node. 导入的 MCP 服务器候选
概述(AI 翻译)
只需2分钟⏱️,Node.js就能搭建并运行自定义MCP服务器
概述 ·功能 ·安装 ·使用 MCP Inspector 进行测试 ·设置测试环境变量 ·与光标 AI 集成 ·在光标(代理模式下)使用 MCP 工具 ·代码概述 ·参考文献与资源 ·许可
概述
MCP(模型上下文协议) 是一个框架,允许您将定制工具集成到人工智能辅助开发环境中——如 Cursor AI。MCP 服务器会暴露功能(如数据检索或代码分析),以便基于大型语言模型的集成开发环境(IDE)按需调用这些工具。在模型上下文协议介绍中了解更多关于 MCP 的信息。
该项目演示了使用 JavaScript 实现的 MCP 服务器,使用Node.js。它定义了两个工具:add,接收两个数字输入并返回其和,以及 getApiKey,从 API_KEY 环境变量中获取 API 密钥。它还提供了一个预定义的提示词 add_numbers,使 AI 模型能够推断加法工具的使用情况。
要求
- Node.js: 需要版本20及以上。
特色
- MCP 集成: 向基于 LLM 的 IDE 展示工具功能。
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
🟢 MCP Server in Node.js
Build and run a custom MCP Server in Node.js in just 2 minutes ⏱️
Overview · Features · Installation · Testing with MCP Inspector · Setting Environment Variables for Testing · Integrating with Cursor AI · Using the MCP Tool in Cursor (Agent Mode) · Code Overview · References & Resources · License
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 implemented in JavaScript using Node.js. It defines two tools: add, which takes two numeric inputs and returns their sum, and getApiKey, which retrieves the API key from the API_KEY environment variable. It also provides a predefined prompt add_numbers that allows AI models to infer the usage of the addition tool.
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.
- MCP Prompt: Provides a predefined prompt (“add_numbers”) that allow AI models to infer tool usage.
- 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 cd -
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 zodThen, update the newly generated
package.jsonfile to include the following lines, which enables ES Modules and adds the mcp inspector command:"type": "module", "scripts": { "inspector": "npx @modelcontextprotocol/inspector node ./mcp-server.js" }
Testing with MCP Inspector
安装
npx @modelcontextprotocol/inspector node ./mcp-server.js配置
{
"mcpServers": {
"existing-server": {
"command": "python",
"args": ["/path/to/existing/server.py"]
},
"MCP Server Boilerplate": {
"command": "node",
"args": ["/home/john/mcp-server-node/mcp-server.js"],
"env": {
"API_KEY": "abc-1234567890"
}
}
}
}