快速MCP服务器
使用Express和TypeScript构建的无状态模型上下文协议(MCP)服务器。
特性
- 采用现代流式HTTP传输的无状态MCP服务器实现
- TypeScript用于类型安全
- 用于HTTP处理的Express.js
需求
- Node.js 18+
- npm或纱线
安装```bash
Clone the repository (or download)
git clone https://github.com/your-username/sample-express-mcp-server.git
cd sample-express-mcp-server
Install dependencies
npm install
## 发展```bash
# Build the TypeScript code
npm run build
# Run in development mode with auto-reloading
npm run dev
# Run tests (when added)
npm test
服务器结构```
src/
├── index.ts # Main application entry point
└── server.ts # MCP server definition with resource, tool, and prompt
## 可用功能
此服务器使用三个MCP组件实现了一个简单的回显端点:
- **资源**: `echo://{message}` -将消息作为资源返回
- **工具**: `echo` -将提供的消息作为工具响应返回
- **提示**: `echo` -使用提供的消息创建用户提示
## MCP协议
此服务器实现 模型上下文协议 (MCP),LLM与外部数据和功能交互的标准化方式。它公开了一个响应JSON-RPC请求的无状态API端点。
### API使用
向发送POST请求 `/mcp` 使用JSON-RPC有效载荷:
#### 初始化```bash
curl -X POST http://localhost:3001/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Accept: text/event-stream" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {
"roots": {
"listChanged": true
},
"sampling": {}
},
"clientInfo": {
"name": "ExampleClient",
"version": "1.0.0"
}
}
}'
呼叫回声工具```bash
curl -X POST http://localhost:3001/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Accept: text/event-stream" \
-d '{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "echo",
"arguments": {
"message": "Hello, World!"
}
},
"id": 1
}'
```
许可证
国际协调委员会
