MCP客户端和服务器
全栈TypeScript工作区,包括:
client:React+MVVM+干净的架构。server:NestJS+Prisma+清洁架构。
P0范围已完成
- 登录/注册流程端到端有线连接。
- 聊天API+聊天UI流端到端连接。
- 聊天端点的JWT防护。
- API合同标准化为
{ code, message, data }. - MCP核心端点(
/api/v1/mcp)使用JSON-RPC方法:
- initialize - tools/list - tools/call
快速开始
1) 安装deps
npm install2) 环境
客户(client/.env):
REACT_APP_BASE_URL=http://localhost:3000服务器(server/.env):
DATABASE_URL=postgresql://:
@localhost:5432/
JWT_SECRET=super-secret-key
PORT=30003) 棱柱迁移流
# Generate Prisma client
npm --workspace server exec prisma generate
# Create/apply migration in local dev
npm --workspace server exec prisma migrate dev --name init
# (CI/Prod) apply migrations
npm --workspace server exec prisma migrate deploy4) 运行服务器/客户端
npm --workspace server run start:dev
npm --workspace client run startAPI合同
- 基础前缀:
/api/v1 - 认证:
- POST /api/v1/auth/login - POST /api/v1/auth/sign-up
- 聊天(需要JWT):
- GET /api/v1/chat/messages - POST /api/v1/chat/messages
- MCP:
- POST /api/v1/mcp
最小MCP请求示例
initialize
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {}
}tools/list
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list",
"params": {}
}tools/call (chat.send_message)
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "chat.send_message",
"arguments": {
"conversationId": "global",
"senderId": "assistant",
"senderName": "Assistant",
"content": "Hello from MCP"
}
}
}