MCP 服务器样板
使用 TypeScript 和 Express 构建的模型上下文协议 (MCP) 样板服务器实现。
目录
概述
该项目实现了一个遵循模型上下文协议 (MCP) 的服务器,允许应用程序以标准化的方式为 LLM 提供上下文。它包括:
- 一个完全配置的 MCP 服务器,具有 HTTP 和 stdio 传输选项
- 用于演示关键功能的示例资源、工具和提示
- TypeScript 支持类型安全并改善开发人员体验
- HTTP 传输层的快速集成
项目结构
入门
先决条件
- Node.js(v18 或更高版本)
- npm 或 yarn
安装
克隆存储库并安装依赖项:
环境变量
复制示例环境文件并根据需要修改:
可用的环境变量:
PORT
:HTTP 服务器的端口(默认值:3000)NODE_ENV
:环境模式(开发、生产)- OAuth 设置(如果需要)
运行服务器
HTTP 服务器
构建并启动 HTTP 服务器:
对于自动重启的开发:
该服务器将在http://localhost:3000/mcp
(或 .env 文件中指定的端口)上可用。
标准输入输出模式
要在 stdio 模式下运行服务器(对于命令行工具):
对于自动重启的开发:
资源
样板包括以下示例资源:
- 静态信息资源:
info://server
- 提供有关服务器的基本信息
- 动态问候资源:
greeting://{name}
- 使用提供的名称参数生成个性化问候语
要访问资源:
- 通过MCP协议
- 使用 MCP 客户端库
工具
样板包括以下示例工具:
- 计算器:执行基本的算术运算
- 参数:
operation
:要执行的操作(加、减、乘、除)a
:第一个数字b
:第二个数字
- 参数:
- 时间戳:以各种格式提供当前时间
- 参数:
format
:输出格式(iso,unix,可读)
- 参数:
提示
样板包括以下示例提示:
- 问候语:创建个性化的问候提示
- 参数:
name
:问候的名字formal
:是否使用正式的问候风格(可选)
- 参数:
- 分析数据:创建数据分析提示
- 参数:
data
:要分析的数据format
:数据格式(json、csv、text)instructions
:附加分析说明(可选)
- 参数:
扩展服务器
添加资源
要添加新资源:
- 在
src/resources/
中创建一个新文件(例如myResource.ts
) - 实现资源处理程序
- 在
src/resources/index.ts
中注册
例子:
添加工具
要添加新工具:
- 在
src/tools/
中创建一个新文件(例如,myTool.ts
) - 实现工具处理程序
- 在
src/tools/index.ts
中注册
例子:
添加提示
要添加新提示:
- 在
src/prompts/
中创建一个新文件(例如myPrompt.ts
) - 实现提示处理程序
- 在
src/prompts/index.ts
中注册
例子:
测试和调试
要测试您的 MCP 服务器,您可以使用:
- MCP 检查器工具
- MCP 客户端库
- 直接 HTTP 请求(用于调试)
执照
该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅 LICENSE 文件。
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
模型上下文协议 (MCP) 服务器的即用型入门实现,使应用程序能够通过示例资源、工具和提示为 LLM 提供标准化上下文。
Related MCP Servers
- AsecurityAlicenseAqualityA beginner-friendly Model Context Protocol (MCP) server that helps users understand MCP concepts, provides interactive examples, and lists available MCP servers. This server is designed to be a helpful companion for developers working with MCP. Also comes with a huge list of servers you can install.Last updated -367661JavaScriptApache 2.0
- AsecurityAlicenseAqualityAn educational implementation of a Model Context Protocol server that demonstrates how to build a functional MCP server for integrating with various LLM clients like Claude Desktop.Last updated -1120PythonMIT License
- AsecurityAlicenseAqualityA Model Context Protocol (MCP) server designed to easily dump your codebase context into Large Language Models (LLMs).Last updated -191JavaScriptApache 2.0
- -securityAlicense-qualityA Model Context Protocol (MCP) server that implements AI-First Development framework principles, allowing LLMs to interact with context-first documentation tools and workflows for preserving knowledge and intent alongside code.Last updated -333PythonAGPL 3.0