-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuse_resource.go
More file actions
60 lines (50 loc) · 1.29 KB
/
use_resource.go
File metadata and controls
60 lines (50 loc) · 1.29 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
59
60
package cmd
import (
"context"
"fmt"
"os"
mcpclient "github.com/advanced-security/codeql-development-mcp-server/client/internal/mcp"
"github.com/spf13/cobra"
)
var useResourceCmd = &cobra.Command{
Use: "resource <uri>",
Short: "Read an MCP server resource by URI",
Long: `Read a specific MCP server resource and print its content.
Example:
gh-ql-mcp-client use resource codeql://server/tools
gh-ql-mcp-client use resource codeql://server/overview --format markdown`,
Args: cobra.ExactArgs(1),
RunE: runUseResource,
}
func init() {
useCmd.AddCommand(useResourceCmd)
}
func runUseResource(_ *cobra.Command, args []string) error {
uri := args[0]
ctx := context.Background()
client, err := connectMCPClient(ctx)
if err != nil {
return err
}
defer client.Close()
result, err := mcpclient.ReadResource(ctx, client, uri)
if err != nil {
return err
}
return outputResourceContent(result)
}
func outputResourceContent(result *mcpclient.ResourceContent) error {
switch OutputFormat() {
case "json":
s, err := mcpclient.FormatJSON(result)
if err != nil {
return err
}
fmt.Fprintln(os.Stdout, s)
case "markdown":
fmt.Fprint(os.Stdout, mcpclient.FormatResourceContentMarkdown(result))
default:
fmt.Fprint(os.Stdout, mcpclient.FormatResourceContentText(result))
}
return nil
}