refactor: enhance MCP tool management with risk policies and confirmation handling

This commit is contained in:
mlogclub
2026-07-28 11:33:15 +08:00
parent ed109047d3
commit 07370fe9a2
17 changed files with 448 additions and 117 deletions
+2
View File
@@ -56,12 +56,14 @@ func (c *Client) ListTools(ctx context.Context, cfg ServerConfig) ([]ToolInfo, e
}
ret := make([]ToolInfo, 0, len(result.Tools))
for _, tool := range result.Tools {
readOnlyHint := tool.Annotations != nil && tool.Annotations.ReadOnlyHint
ret = append(ret, ToolInfo{
Name: tool.Name,
Title: tool.Title,
Description: tool.Description,
InputSchema: tool.InputSchema,
OutputSchema: tool.OutputSchema,
ReadOnlyHint: readOnlyHint,
})
}
return ret, nil
@@ -23,7 +23,11 @@ func (p *systemToolProvider) Register(server *mcp.Server) error {
server,
&mcp.Tool{
Name: "server_time",
Title: "获取当前时间",
Description: "获取当前服务端时间,可选传入时区。",
Annotations: &mcp.ToolAnnotations{
ReadOnlyHint: true,
},
},
func(_ context.Context, _ *mcp.CallToolRequest, args serverTimeArgs) (*mcp.CallToolResult, map[string]any, error) {
loc := time.Local
@@ -46,7 +50,11 @@ func (p *systemToolProvider) Register(server *mcp.Server) error {
server,
&mcp.Tool{
Name: "service_info",
Title: "查看服务信息",
Description: "查看当前 agent-desk 服务的基础运行信息。",
Annotations: &mcp.ToolAnnotations{
ReadOnlyHint: true,
},
},
func(ctx context.Context, req *mcp.CallToolRequest, _ struct{}) (*mcp.CallToolResult, map[string]any, error) {
cfg := config.Current()
+1
View File
@@ -28,6 +28,7 @@ type ToolInfo struct {
Description string `json:"description"`
InputSchema any `json:"inputSchema"`
OutputSchema any `json:"outputSchema,omitempty"`
ReadOnlyHint bool `json:"readOnlyHint"`
}
type ToolResultContent struct {