-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuse.go
More file actions
49 lines (42 loc) · 1.24 KB
/
use.go
File metadata and controls
49 lines (42 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package cmd
import (
"fmt"
"strings"
"github.com/spf13/cobra"
)
var useCmd = &cobra.Command{
Use: "use",
Short: "Call an individual MCP server primitive (tool, resource, or prompt)",
Long: `Connect to the MCP server and call a single primitive.
Subcommands:
tool Call a tool by name with key-value arguments
resource Read a resource by URI
prompt Get a prompt by name with key-value arguments`,
}
// parseArgs converts a list of "key=value" strings into a map.
func parseArgs(args []string) (map[string]string, error) {
result := make(map[string]string, len(args))
for _, a := range args {
key, value, found := strings.Cut(a, "=")
if !found || key == "" {
return nil, fmt.Errorf("invalid argument %q: expected key=value format", a)
}
result[key] = value
}
return result, nil
}
// parseArgsAny converts a list of "key=value" strings into a map[string]any.
func parseArgsAny(args []string) (map[string]any, error) {
result := make(map[string]any, len(args))
for _, a := range args {
key, value, found := strings.Cut(a, "=")
if !found || key == "" {
return nil, fmt.Errorf("invalid argument %q: expected key=value format", a)
}
result[key] = value
}
return result, nil
}
func init() {
rootCmd.AddCommand(useCmd)
}