支持MCP的HTTP服务器
一个使用Express和TypeScript构建的HTTP服务器,同时提供网页和模型上下文协议(MCP)端点。
特性
- 具有web和MCP功能的HTTP服务器
- 采用现代流式HTTP传输的无状态MCP服务器实现
- TypeScript用于类型安全
- 用于HTTP处理的Express.js
需求
- Node.js 18+
- npm或纱线
安装
# Clone the repository (or download)
git clone https://github.com/your-username/jakegaylor-com-mcp-server.git
cd jakegaylor-com-mcp-server
# Install dependencies
npm install发展
# 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
├── express.ts # HTTP server configuration
├── stdio.ts # STDIO server configuration
├── config.ts # Server configuration
└── types.ts # TypeScript type definitions可用端点
服务器支持多个端点:
- Web(GET
/):提供网页 - MCP(职位
/mcp):提供MCP协议功能
MCP功能
MCP端点实现了三个MCP组件:
- 资源:
echo://{message}-将消息作为资源返回 - 工具:
echo-将提供的消息作为工具响应返回 - 提示:
echo-使用提供的消息创建用户提示
MCP协议
此服务器实现 模型上下文协议 (MCP),LLM与外部数据和功能交互的标准化方式。它公开了一个响应JSON-RPC请求的无状态API端点。
API使用
向发送POST请求 /mcp 使用JSON-RPC有效载荷:
初始化
curl -X POST http://localhost:3000/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"
}
}
}'呼叫回声工具
curl -X POST http://localhost:3000/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
}'许可证
重新生成飞行部署密钥
令牌由以下材料制成:
fly tokens create deploy --name gh-jakegaylor-com-mcp-server --expiry 2160h
