refactor: 迁移到官方 MCP SDK (#167)

- 添加官方 SDK 依赖 github.com/modelcontextprotocol/go-sdk v0.7.0
- 新增 mcp_server.go 使用官方 SDK 注册 8 个 MCP 工具
- 删除自实现的 streamable_http.go(约 400 行)
- 更新 routes.go 使用 mcp.NewStreamableHTTPHandler
- 优化服务器优雅关闭逻辑(5秒超时 + 警告日志)
- 清理 types.go 中的 JSON-RPC 相关类型

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
zy
2025-09-27 01:44:02 +08:00
committed by GitHub
parent 529ee71144
commit 53ea832773
8 changed files with 270 additions and 459 deletions

View File

@@ -16,46 +16,15 @@ type SuccessResponse struct {
Message string `json:"message,omitempty"`
}
// JSON-RPC 相关类型
// MCP 相关类型(用于内部转换)
// JSONRPCRequest JSON-RPC 请求
type JSONRPCRequest struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
Params any `json:"params,omitempty"`
ID any `json:"id"`
}
// JSONRPCResponse JSON-RPC 响应
type JSONRPCResponse struct {
JSONRPC string `json:"jsonrpc"`
Result any `json:"result,omitempty"`
Error *JSONRPCError `json:"error,omitempty"`
ID any `json:"id"`
}
// JSONRPCError JSON-RPC 错误
type JSONRPCError struct {
Code int `json:"code"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}
// MCP 相关类型
// MCPToolCall MCP 工具调用
type MCPToolCall struct {
Name string `json:"name"`
Arguments map[string]interface{} `json:"arguments"`
}
// MCPToolResult MCP 工具结果
// MCPToolResult MCP 工具结果(内部使用)
type MCPToolResult struct {
Content []MCPContent `json:"content"`
IsError bool `json:"isError,omitempty"`
}
// MCPContent MCP 内容
// MCPContent MCP 内容(内部使用)
type MCPContent struct {
Type string `json:"type"`
Text string `json:"text"`