MCPcopy Create free account
hub / github.com/github/gh-aw / registerAddTool

Function registerAddTool

pkg/cli/mcp_tools_management.go:23–83  ·  view source on GitHub ↗

registerAddTool registers the add tool with the MCP server.

(server *mcp.Server, execCmd execCmdFunc)

Source from the content-addressed store, hash-verified

21
22// registerAddTool registers the add tool with the MCP server.
23func registerAddTool(server *mcp.Server, execCmd execCmdFunc) {
24 mcp.AddTool(server, &mcp.Tool{
25 Name: "add",
26 Annotations: &mcp.ToolAnnotations{
27 OpenWorldHint: new(true),
28 },
29 Description: "Add workflows from remote repositories to .github/workflows",
30 Icons: []mcp.Icon{
31 {Source: "➕"},
32 },
33 }, func(ctx context.Context, req *mcp.CallToolRequest, args addArgs) (*mcp.CallToolResult, any, error) {
34 // Check for cancellation before starting
35 select {
36 case <-ctx.Done():
37 return nil, nil, newMCPError(jsonrpc.CodeInternalError, "request cancelled", ctx.Err().Error())
38 default:
39 }
40
41 // Validate required arguments
42 if len(args.Workflows) == 0 {
43 return nil, nil, newMCPError(jsonrpc.CodeInvalidParams, "missing required parameter: at least one workflow specification is required", nil)
44 }
45 for _, workflowSpec := range args.Workflows {
46 if isRepositoryOnlyWorkflowSpec(workflowSpec) {
47 return nil, nil, newMCPError(jsonrpc.CodeInvalidParams, "failed to add workflows", map[string]any{
48 "error": "workflow specification must be in format 'owner/repo/workflow-name[@version]'",
49 "spec": workflowSpec,
50 })
51 }
52 }
53
54 mcpToolsManagementLog.Printf("add tool invoked: workflows=%d, number=%d, name=%q", len(args.Workflows), args.Number, args.Name)
55
56 // Build command arguments
57 cmdArgs := []string{"add"}
58
59 // Add workflows
60 cmdArgs = append(cmdArgs, args.Workflows...)
61
62 // Add optional flags
63 if args.Number > 0 {
64 cmdArgs = append(cmdArgs, "-c", strconv.Itoa(args.Number))
65 }
66 if args.Name != "" {
67 cmdArgs = append(cmdArgs, "-n", args.Name)
68 }
69
70 // Execute the CLI command
71 output, err := runMCPExecCombinedOutput(ctx, execCmd, cmdArgs...)
72
73 if err != nil {
74 return nil, nil, newMCPError(jsonrpc.CodeInternalError, "failed to add workflows", map[string]any{"error": err.Error(), "output": string(output)})
75 }
76
77 return &mcp.CallToolResult{
78 Content: []mcp.Content{
79 &mcp.TextContent{Text: string(output)},
80 },

Callers 1

createMCPServerFunction · 0.85

Calls 6

newMCPErrorFunction · 0.85
runMCPExecCombinedOutputFunction · 0.85
DoneMethod · 0.80
ErrorMethod · 0.45
PrintfMethod · 0.45

Tested by

no test coverage detected