-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuse.go
More file actions
58 lines (50 loc) · 1.48 KB
/
use.go
File metadata and controls
58 lines (50 loc) · 1.48 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
50
51
52
53
54
55
56
57
58
package cmd
import (
"fmt"
"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 := cutString(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 := cutString(a, "=")
if !found || key == "" {
return nil, fmt.Errorf("invalid argument %q: expected key=value format", a)
}
result[key] = value
}
return result, nil
}
// cutString splits s around the first instance of sep.
func cutString(s, sep string) (before, after string, found bool) {
for i := 0; i+len(sep) <= len(s); i++ {
if s[i:i+len(sep)] == sep {
return s[:i], s[i+len(sep):], true
}
}
return s, "", false
}
func init() {
rootCmd.AddCommand(useCmd)
}