-
Notifications
You must be signed in to change notification settings - Fork 273
Closed
Milestone
Description
Given the recent breaking change which some examples haven't been updated along with some current examples largely relying on accessing map keys via untyped string literals (this is very pythonic for a Golang SDK), it would be great to add simple typed tool examples.
This is an example of how I've implemented it, using ToolFor. I'm unsure if this is the intended implementation for a typed tool. Without the ToolFor wrapper, I was responsible for unmarshaling the raw json message which seemed less than ideal. I'm dubious my usage of jsonschema (or lack thereof) is per design intent.
type GitToolArgs struct {
Repo string `json:"repo" jsonschema:"Repo URL,pattern=(git|https?).*\\.git"`
SourceBranch string `json:"sourceBranch" jsonschema:"Source GIT Branch"`
TargetBranch string `json:"targetBranch" jsonschema:"Target GIT Branch"`
}
func (a *AIWorkerMCP) addGitTool() error {
a.server.AddTool(mcp.ToolFor[*GitToolArgs, any](&mcp.Tool{
Annotations: &mcp.ToolAnnotations{
OpenWorldHint: ptr.To(true),
ReadOnlyHint: true,
},
Description: "Fetches GIT context",
Name: "aiworkermcp-git",
Title: "AI Worker GIT MCP",
}, a.gitToolHandlerFor))
return nil
}
func (a *AIWorkerMCP) gitToolHandlerFor(ctx context.Context, req *mcp.CallToolRequest, args *GitToolArgs) (
*mcp.CallToolResult, any, error,
) {
// some work here
return &mcp.CallToolResult{
IsError: false,
Content: []mcp.Content{
&mcp.TextContent{
Text: "some text content here",
},
},
}, nil, nil
}