Skip to content

Commit 1d3efa2

Browse files
committed
check args before use in mcp
if no subcommands given print usage
1 parent 718ec6d commit 1d3efa2

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

cmd/src/mcp.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,43 @@ import (
1616
func init() {
1717
flagSet := flag.NewFlagSet("mcp", flag.ExitOnError)
1818
commands = append(commands, &command{
19-
flagSet: flagSet,
20-
handler: mcpMain,
19+
flagSet: flagSet,
20+
handler: mcpMain,
21+
usageFunc: mcpUsage,
2122
})
2223
}
24+
25+
func mcpUsage() {
26+
fmt.Println("The 'mcp' command exposes MCP tools as subcommands for agents to use.")
27+
fmt.Println("\nUSAGE:")
28+
fmt.Println(" src mcp list-tools List available tools")
29+
fmt.Println(" src mcp <tool-name> schema View the input/output schema of a tool")
30+
fmt.Println(" src mcp <tool-name> <flags> Invoke a tool with the given flags")
31+
fmt.Println(" src mcp <tool-name> -h List the available flags of a tool")
32+
}
33+
2334
func mcpMain(args []string) error {
2435
fmt.Println("NOTE: This command is still experimental")
2536
tools, err := mcp.LoadDefaultToolDefinitions()
2637
if err != nil {
2738
return err
2839
}
2940

41+
if len(args) == 0 {
42+
mcpUsage()
43+
return nil
44+
}
45+
3046
subcmd := args[0]
3147
if subcmd == "list-tools" {
3248
fmt.Println("The following tools are available:")
3349
for name := range tools {
34-
fmt.Printf(" %s\n", name)
50+
fmt.Printf(" %s\n", name)
3551
}
3652
fmt.Println("\nUSAGE:")
37-
fmt.Printf(" • Invoke a tool\n")
38-
fmt.Printf(" src mcp <tool-name> <flags>\n")
39-
fmt.Printf("\n • View the Input / Output Schema of a tool\n")
40-
fmt.Printf(" src mcp <tool-name> schema\n")
41-
fmt.Printf("\n • List the available flags of a tool\n")
42-
fmt.Printf(" src mcp <tool-name> -h\n")
43-
fmt.Printf("\n • View the Input / Output Schema of a tool\n")
44-
fmt.Printf(" src mcp <tool-name> schema\n")
53+
fmt.Println(" src mcp <tool-name> schema View the input/output schema of a tool")
54+
fmt.Println(" src mcp <tool-name> <flags> Invoke a tool with the given flags")
55+
fmt.Println(" src mcp <tool-name> -h List the available flags of a tool")
4556
return nil
4657
}
4758

0 commit comments

Comments
 (0)