chore: 同步本地更改
- 新增 aio-mcp 项目框架 - 新增 .trae/skills/ OCR/SKU 设计工具 - 更新 auto-check 配置和 stress 包 - 删除 fnhelp 文档目录 - 更新 Docker 压力测试脚本
This commit is contained in:
22
aio-mcp/internal/server/server.go
Normal file
22
aio-mcp/internal/server/server.go
Normal file
@@ -0,0 +1,22 @@
|
||||
// Package server 负责 MCP 服务器的装配:创建 server 实例并注册全部工具。
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/modelcontextprotocol/go-sdk/mcp"
|
||||
|
||||
"aio-mcp/internal/tools"
|
||||
)
|
||||
|
||||
// New 创建并装配 aio-mcp 服务器。
|
||||
// version 为服务器实现版本号,随 MCP initialize 握手上报给客户端。
|
||||
func New(version string) *mcp.Server {
|
||||
s := mcp.NewServer(&mcp.Implementation{
|
||||
Name: "aio-mcp",
|
||||
Version: version,
|
||||
}, nil)
|
||||
|
||||
// 注册全部工具。新增工具后在 tools.RegisterAll 里追加即可。
|
||||
tools.RegisterAll(s)
|
||||
|
||||
return s
|
||||
}
|
||||
40
aio-mcp/internal/tools/echo.go
Normal file
40
aio-mcp/internal/tools/echo.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/modelcontextprotocol/go-sdk/mcp"
|
||||
)
|
||||
|
||||
// echoArgs 是 echo 工具的输入参数。
|
||||
// json tag 决定参数名;jsonschema tag 提供描述,供客户端(LLM)理解参数。
|
||||
type echoArgs struct {
|
||||
Message string `json:"message" jsonschema:"要回显的文本,必填"`
|
||||
Times int `json:"times,omitempty" jsonschema:"回显次数,默认 1"`
|
||||
}
|
||||
|
||||
// registerEcho 注册 echo 工具:演示带参数的工具写法。
|
||||
func registerEcho(s *mcp.Server) {
|
||||
mcp.AddTool(s, &mcp.Tool{
|
||||
Name: "echo",
|
||||
Description: "把传入的文本原样回显指定次数,用于演示参数传递与工具调用。",
|
||||
}, func(_ context.Context, _ *mcp.CallToolRequest, args echoArgs) (*mcp.CallToolResult, any, error) {
|
||||
times := args.Times
|
||||
if times <= 0 {
|
||||
times = 1
|
||||
}
|
||||
// 用换行分隔,避免重复文本粘连。
|
||||
line := strings.TrimRight(args.Message, "\n")
|
||||
lines := make([]string, times)
|
||||
for i := range lines {
|
||||
lines[i] = line
|
||||
}
|
||||
return &mcp.CallToolResult{
|
||||
Content: []mcp.Content{
|
||||
&mcp.TextContent{Text: fmt.Sprintf("%s\n(共 %d 次)", strings.Join(lines, "\n"), times)},
|
||||
},
|
||||
}, nil, nil
|
||||
})
|
||||
}
|
||||
22
aio-mcp/internal/tools/ping.go
Normal file
22
aio-mcp/internal/tools/ping.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/modelcontextprotocol/go-sdk/mcp"
|
||||
)
|
||||
|
||||
// registerPing 注册 ping 工具:无参数健康检查,返回 pong 与服务器时间。
|
||||
func registerPing(s *mcp.Server) {
|
||||
mcp.AddTool(s, &mcp.Tool{
|
||||
Name: "ping",
|
||||
Description: "健康检查。返回 pong 与服务器当前时间,用于确认 aio-mcp 连接正常。",
|
||||
}, func(_ context.Context, _ *mcp.CallToolRequest, _ struct{}) (*mcp.CallToolResult, any, error) {
|
||||
return &mcp.CallToolResult{
|
||||
Content: []mcp.Content{
|
||||
&mcp.TextContent{Text: "pong " + time.Now().Format(time.RFC3339)},
|
||||
},
|
||||
}, nil, nil
|
||||
})
|
||||
}
|
||||
26
aio-mcp/internal/tools/registry.go
Normal file
26
aio-mcp/internal/tools/registry.go
Normal file
@@ -0,0 +1,26 @@
|
||||
// Package tools 集中管理 aio-mcp 的全部 MCP 工具。
|
||||
//
|
||||
// # 新增工具的固定步骤
|
||||
//
|
||||
// 1. 在本目录新建一个文件(如 weather.go),实现
|
||||
// func registerXXX(s *mcp.Server)
|
||||
// 2. 在 RegisterAll 中追加一行 registerXXX(s)
|
||||
//
|
||||
// 工具通过泛型 mcp.AddTool[In, Out] 注册:输入参数用 struct 定义,
|
||||
// 加 json 与 jsonschema tag(描述、必填),SDK 会自动生成 inputSchema
|
||||
// 并做输入校验,无需手工写 JSON Schema。
|
||||
//
|
||||
// 后续工具需要共享状态(SQLite 连接、配置、http client 等)时,
|
||||
// 把 RegisterAll 演进为 RegisterAll(s *mcp.Server, deps *Deps),
|
||||
// 在 server.New 里构造 deps 传入即可,各工具文件只改签名。
|
||||
package tools
|
||||
|
||||
import (
|
||||
"github.com/modelcontextprotocol/go-sdk/mcp"
|
||||
)
|
||||
|
||||
// RegisterAll 注册所有工具。
|
||||
func RegisterAll(s *mcp.Server) {
|
||||
registerPing(s)
|
||||
registerEcho(s)
|
||||
}
|
||||
Reference in New Issue
Block a user