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:
14
routes.go
14
routes.go
@@ -1,7 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/modelcontextprotocol/go-sdk/mcp"
|
||||
)
|
||||
|
||||
// setupRoutes 设置路由配置
|
||||
@@ -20,8 +23,15 @@ func setupRoutes(appServer *AppServer) *gin.Engine {
|
||||
// 健康检查
|
||||
router.GET("/health", healthHandler)
|
||||
|
||||
// MCP 端点 - 使用 Streamable HTTP 协议
|
||||
mcpHandler := appServer.StreamableHTTPHandler()
|
||||
// MCP 端点 - 使用官方 SDK 的 Streamable HTTP Handler
|
||||
mcpHandler := mcp.NewStreamableHTTPHandler(
|
||||
func(r *http.Request) *mcp.Server {
|
||||
return appServer.mcpServer
|
||||
},
|
||||
&mcp.StreamableHTTPOptions{
|
||||
JSONResponse: true, // 支持 JSON 响应
|
||||
},
|
||||
)
|
||||
router.Any("/mcp", gin.WrapH(mcpHandler))
|
||||
router.Any("/mcp/*path", gin.WrapH(mcpHandler))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user