- 添加官方 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>
66 lines
1.7 KiB
Go
66 lines
1.7 KiB
Go
package main
|
|
|
|
// HTTP API 响应类型
|
|
|
|
// ErrorResponse 错误响应
|
|
type ErrorResponse struct {
|
|
Error string `json:"error"`
|
|
Code string `json:"code"`
|
|
Details any `json:"details,omitempty"`
|
|
}
|
|
|
|
// SuccessResponse 成功响应
|
|
type SuccessResponse struct {
|
|
Success bool `json:"success"`
|
|
Data any `json:"data"`
|
|
Message string `json:"message,omitempty"`
|
|
}
|
|
|
|
// MCP 相关类型(用于内部转换)
|
|
|
|
// MCPToolResult MCP 工具结果(内部使用)
|
|
type MCPToolResult struct {
|
|
Content []MCPContent `json:"content"`
|
|
IsError bool `json:"isError,omitempty"`
|
|
}
|
|
|
|
// MCPContent MCP 内容(内部使用)
|
|
type MCPContent struct {
|
|
Type string `json:"type"`
|
|
Text string `json:"text"`
|
|
MimeType string `json:"mimeType"`
|
|
Data string `json:"data"`
|
|
}
|
|
|
|
// FeedDetailRequest Feed详情请求
|
|
type FeedDetailRequest struct {
|
|
FeedID string `json:"feed_id" binding:"required"`
|
|
XsecToken string `json:"xsec_token" binding:"required"`
|
|
}
|
|
|
|
// FeedDetailResponse Feed详情响应
|
|
type FeedDetailResponse struct {
|
|
FeedID string `json:"feed_id"`
|
|
Data any `json:"data"`
|
|
}
|
|
|
|
// PostCommentRequest 发表评论请求
|
|
type PostCommentRequest struct {
|
|
FeedID string `json:"feed_id" binding:"required"`
|
|
XsecToken string `json:"xsec_token" binding:"required"`
|
|
Content string `json:"content" binding:"required"`
|
|
}
|
|
|
|
// PostCommentResponse 发表评论响应
|
|
type PostCommentResponse struct {
|
|
FeedID string `json:"feed_id"`
|
|
Success bool `json:"success"`
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
// UserProfileRequest 用户主页请求
|
|
type UserProfileRequest struct {
|
|
UserID string `json:"user_id" binding:"required"`
|
|
XsecToken string `json:"xsec_token" binding:"required"`
|
|
}
|