|
1 | 1 | package commands |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
4 | 5 | "encoding/json" |
5 | 6 | "errors" |
6 | 7 | "fmt" |
7 | 8 | "os" |
8 | 9 | "path/filepath" |
9 | 10 | "strings" |
10 | 11 |
|
11 | | - "github.com/f/mcptools/pkg/client" |
| 12 | + "github.com/mark3labs/mcp-go/client" |
| 13 | + "github.com/mark3labs/mcp-go/mcp" |
12 | 14 | "github.com/peterh/liner" |
13 | 15 | "github.com/spf13/cobra" |
14 | 16 | ) |
@@ -48,18 +50,12 @@ func ShellCmd() *cobra.Command { //nolint:gocyclo |
48 | 50 | os.Exit(1) |
49 | 51 | } |
50 | 52 |
|
51 | | - mcpClient, clientErr := CreateClientFunc(parsedArgs, client.CloseTransportAfterExecute(false)) |
| 53 | + mcpClient, clientErr := CreateClientFunc(parsedArgs) |
52 | 54 | if clientErr != nil { |
53 | 55 | fmt.Fprintf(os.Stderr, "Error: %v\n", clientErr) |
54 | 56 | os.Exit(1) |
55 | 57 | } |
56 | 58 |
|
57 | | - _, listErr := mcpClient.ListTools() |
58 | | - if listErr != nil { |
59 | | - fmt.Fprintf(os.Stderr, "Error connecting to MCP server: %v\n", listErr) |
60 | | - os.Exit(1) |
61 | | - } |
62 | | - |
63 | 59 | fmt.Fprintf(thisCmd.OutOrStdout(), "mcp > MCP Tools Shell (%s)\n", Version) |
64 | 60 | fmt.Fprintf(thisCmd.OutOrStdout(), "mcp > Connected to Server: %s\n", strings.Join(parsedArgs, " ")) |
65 | 61 | fmt.Fprintf(thisCmd.OutOrStdout(), "\nmcp > Type '/h' for help or '/q' to quit\n") |
@@ -111,19 +107,43 @@ func ShellCmd() *cobra.Command { //nolint:gocyclo |
111 | 107 |
|
112 | 108 | switch command { |
113 | 109 | case "tools": |
114 | | - resp, listErr = mcpClient.ListTools() |
| 110 | + var listToolsResult *mcp.ListToolsResult |
| 111 | + listToolsResult, listErr = mcpClient.ListTools(context.Background(), mcp.ListToolsRequest{}) |
| 112 | + |
| 113 | + var tools []any |
| 114 | + if listErr == nil && listToolsResult != nil { |
| 115 | + tools = ConvertJSONToSlice(listToolsResult.Tools) |
| 116 | + } |
| 117 | + |
| 118 | + resp = map[string]any{"tools": tools} |
115 | 119 | if formatErr := FormatAndPrintResponse(thisCmd, resp, listErr); formatErr != nil { |
116 | 120 | fmt.Fprintf(os.Stderr, "%v\n", formatErr) |
117 | 121 | continue |
118 | 122 | } |
119 | 123 | case "resources": |
120 | | - resp, listErr = mcpClient.ListResources() |
| 124 | + var listResourcesResult *mcp.ListResourcesResult |
| 125 | + listResourcesResult, listErr = mcpClient.ListResources(context.Background(), mcp.ListResourcesRequest{}) |
| 126 | + |
| 127 | + var resources []any |
| 128 | + if listErr == nil && listResourcesResult != nil { |
| 129 | + resources = ConvertJSONToSlice(listResourcesResult.Resources) |
| 130 | + } |
| 131 | + |
| 132 | + resp = map[string]any{"resources": resources} |
121 | 133 | if formatErr := FormatAndPrintResponse(thisCmd, resp, listErr); formatErr != nil { |
122 | 134 | fmt.Fprintf(os.Stderr, "%v\n", formatErr) |
123 | 135 | continue |
124 | 136 | } |
125 | 137 | case "prompts": |
126 | | - resp, listErr = mcpClient.ListPrompts() |
| 138 | + var listPromptsResult *mcp.ListPromptsResult |
| 139 | + listPromptsResult, listErr = mcpClient.ListPrompts(context.Background(), mcp.ListPromptsRequest{}) |
| 140 | + |
| 141 | + var prompts []any |
| 142 | + if listErr == nil && listPromptsResult != nil { |
| 143 | + prompts = ConvertJSONToSlice(listPromptsResult.Prompts) |
| 144 | + } |
| 145 | + |
| 146 | + resp = map[string]any{"prompts": prompts} |
127 | 147 | if formatErr := FormatAndPrintResponse(thisCmd, resp, listErr); formatErr != nil { |
128 | 148 | fmt.Fprintf(os.Stderr, "%v\n", formatErr) |
129 | 149 | continue |
@@ -208,11 +228,36 @@ func callCommand(thisCmd *cobra.Command, mcpClient *client.Client, commandArgs [ |
208 | 228 |
|
209 | 229 | switch entityType { |
210 | 230 | case EntityTypeTool: |
211 | | - resp, execErr = mcpClient.CallTool(entityName, params) |
| 231 | + var toolResponse *mcp.CallToolResult |
| 232 | + request := mcp.CallToolRequest{} |
| 233 | + request.Params.Name = entityName |
| 234 | + request.Params.Arguments = params |
| 235 | + toolResponse, execErr = mcpClient.CallTool(context.Background(), request) |
| 236 | + if execErr == nil && toolResponse != nil { |
| 237 | + resp = ConvertJSONToMap(toolResponse) |
| 238 | + } else { |
| 239 | + resp = map[string]any{} |
| 240 | + } |
212 | 241 | case EntityTypeRes: |
213 | | - resp, execErr = mcpClient.ReadResource(entityName) |
| 242 | + var resourceResponse *mcp.ReadResourceResult |
| 243 | + request := mcp.ReadResourceRequest{} |
| 244 | + request.Params.URI = entityName |
| 245 | + resourceResponse, execErr = mcpClient.ReadResource(context.Background(), request) |
| 246 | + if execErr == nil && resourceResponse != nil { |
| 247 | + resp = ConvertJSONToMap(resourceResponse) |
| 248 | + } else { |
| 249 | + resp = map[string]any{} |
| 250 | + } |
214 | 251 | case EntityTypePrompt: |
215 | | - resp, execErr = mcpClient.GetPrompt(entityName) |
| 252 | + var promptResponse *mcp.GetPromptResult |
| 253 | + request := mcp.GetPromptRequest{} |
| 254 | + request.Params.Name = entityName |
| 255 | + promptResponse, execErr = mcpClient.GetPrompt(context.Background(), request) |
| 256 | + if execErr == nil && promptResponse != nil { |
| 257 | + resp = ConvertJSONToMap(promptResponse) |
| 258 | + } else { |
| 259 | + resp = map[string]any{} |
| 260 | + } |
216 | 261 | default: |
217 | 262 | fmt.Fprintf(os.Stderr, "Error: unsupported entity type: %s\n", entityType) |
218 | 263 | } |
|
0 commit comments