Skip to content

Commit f6d5ce5

Browse files
authored
Merge pull request #49 from ayakut16/migration/client
Migration to mark3labs/mcp-go/client
2 parents 07e62e4 + 7daca9b commit f6d5ce5

File tree

21 files changed

+497
-973
lines changed

21 files changed

+497
-973
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ mcp tools npx -y @modelcontextprotocol/server-filesystem ~
147147
Uses HTTP and Server-Sent Events (SSE) to communicate with an MCP server via JSON-RPC 2.0. This is useful for connecting to remote servers that implement the MCP protocol.
148148

149149
```bash
150-
mcp tools http://127.0.0.1:3001
150+
mcp tools http://localhost:3001/sse
151151

152152
# Example: Use the everything sample server
153153
# docker run -p 3001:3001 --rm -it tzolov/mcp-everything-server:v1
@@ -340,7 +340,7 @@ mcp web https://ne.tools
340340
The web interface includes:
341341

342342
- A sidebar listing all available tools, resources, and prompts
343-
- Form-based and JSON-based parameter editing
343+
- Form-based and JSON-based parameter editing
344344
- Formatted and raw JSON response views
345345
- Interactive parameter forms automatically generated from tool schemas
346346
- Support for complex parameter types (arrays, objects, nested structures)
@@ -626,7 +626,7 @@ mcp proxy tool count_lines "Counts lines in a file" "file:string" -e "wc -l < \"
626626
The guard mode allows you to restrict access to specific tools, prompts, and resources based on pattern matching. This is useful for security purposes when:
627627

628628
- Restricting potentially dangerous operations (file writes, deletions, etc.)
629-
- Limiting the capabilities of AI assistants or applications
629+
- Limiting the capabilities of AI assistants or applications
630630
- Providing read-only access to sensitive systems
631631
- Creating sandboxed environments for testing or demonstrations
632632

cmd/mcptools/commands/call.go

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package commands
22

33
import (
4+
"context"
45
"encoding/json"
56
"fmt"
67
"os"
78
"strings"
89

10+
"github.com/mark3labs/mcp-go/mcp"
911
"github.com/spf13/cobra"
1012
)
1113

@@ -104,11 +106,36 @@ func CallCmd() *cobra.Command {
104106

105107
switch entityType {
106108
case EntityTypeTool:
107-
resp, execErr = mcpClient.CallTool(entityName, params)
109+
var toolResponse *mcp.CallToolResult
110+
request := mcp.CallToolRequest{}
111+
request.Params.Name = entityName
112+
request.Params.Arguments = params
113+
toolResponse, execErr = mcpClient.CallTool(context.Background(), request)
114+
if execErr == nil && toolResponse != nil {
115+
resp = ConvertJSONToMap(toolResponse)
116+
} else {
117+
resp = map[string]any{}
118+
}
108119
case EntityTypeRes:
109-
resp, execErr = mcpClient.ReadResource(entityName)
120+
var resourceResponse *mcp.ReadResourceResult
121+
request := mcp.ReadResourceRequest{}
122+
request.Params.URI = entityName
123+
resourceResponse, execErr = mcpClient.ReadResource(context.Background(), request)
124+
if execErr == nil && resourceResponse != nil {
125+
resp = ConvertJSONToMap(resourceResponse)
126+
} else {
127+
resp = map[string]any{}
128+
}
110129
case EntityTypePrompt:
111-
resp, execErr = mcpClient.GetPrompt(entityName)
130+
var promptResponse *mcp.GetPromptResult
131+
request := mcp.GetPromptRequest{}
132+
request.Params.Name = entityName
133+
promptResponse, execErr = mcpClient.GetPrompt(context.Background(), request)
134+
if execErr == nil && promptResponse != nil {
135+
resp = ConvertJSONToMap(promptResponse)
136+
} else {
137+
resp = map[string]any{}
138+
}
112139
default:
113140
fmt.Fprintf(os.Stderr, "Error: unsupported entity type: %s\n", entityType)
114141
os.Exit(1)

cmd/mcptools/commands/get_prompt.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package commands
22

33
import (
4+
"context"
45
"encoding/json"
56
"fmt"
67
"os"
78

9+
"github.com/mark3labs/mcp-go/mcp"
810
"github.com/spf13/cobra"
911
)
1012

@@ -81,8 +83,18 @@ func GetPromptCmd() *cobra.Command {
8183
os.Exit(1)
8284
}
8385

84-
resp, execErr := mcpClient.GetPrompt(promptName)
85-
if formatErr := FormatAndPrintResponse(thisCmd, resp, execErr); formatErr != nil {
86+
request := mcp.GetPromptRequest{}
87+
request.Params.Name = promptName
88+
resp, execErr := mcpClient.GetPrompt(context.Background(), request)
89+
90+
var responseMap map[string]any
91+
if execErr == nil && resp != nil {
92+
responseMap = ConvertJSONToMap(resp)
93+
} else {
94+
responseMap = map[string]any{}
95+
}
96+
97+
if formatErr := FormatAndPrintResponse(thisCmd, responseMap, execErr); formatErr != nil {
8698
fmt.Fprintf(os.Stderr, "%v\n", formatErr)
8799
os.Exit(1)
88100
}

cmd/mcptools/commands/guard.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"strings"
77

88
"github.com/f/mcptools/pkg/alias"
9-
"github.com/f/mcptools/pkg/client"
109
"github.com/f/mcptools/pkg/guard"
1110
"github.com/spf13/cobra"
1211
)
@@ -36,10 +35,10 @@ Examples:
3635
mcp guard --allow tools:read_* --deny edit_*,write_*,create_* npx run @modelcontextprotocol/server-filesystem ~
3736
mcp guard --allow prompts:system_* --deny tools:execute_* npx run @modelcontextprotocol/server-filesystem ~
3837
mcp guard --allow tools:read_* fs # Using an alias
39-
38+
4039
Patterns can include wildcards:
4140
* matches any sequence of characters
42-
41+
4342
Entity types:
4443
tools: filter available tools
4544
prompts: filter available prompts
@@ -76,7 +75,7 @@ Entity types:
7675
if found {
7776
fmt.Fprintf(os.Stderr, "Expanding alias '%s' to '%s'\n", aliasName, serverCmd)
7877
// Replace the alias with the actual command
79-
parsedArgs = client.ParseCommandString(serverCmd)
78+
parsedArgs = ParseCommandString(serverCmd)
8079
}
8180
}
8281

cmd/mcptools/commands/prompts.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package commands
22

33
import (
4+
"context"
45
"fmt"
56
"os"
67

8+
"github.com/mark3labs/mcp-go/mcp"
79
"github.com/spf13/cobra"
810
)
911

@@ -29,8 +31,15 @@ func PromptsCmd() *cobra.Command {
2931
os.Exit(1)
3032
}
3133

32-
resp, listErr := mcpClient.ListPrompts()
33-
if formatErr := FormatAndPrintResponse(thisCmd, resp, listErr); formatErr != nil {
34+
resp, listErr := mcpClient.ListPrompts(context.Background(), mcp.ListPromptsRequest{})
35+
36+
var prompts []any
37+
if listErr == nil && resp != nil {
38+
prompts = ConvertJSONToSlice(resp.Prompts)
39+
}
40+
41+
promptsMap := map[string]any{"prompts": prompts}
42+
if formatErr := FormatAndPrintResponse(thisCmd, promptsMap, listErr); formatErr != nil {
3443
fmt.Fprintf(os.Stderr, "%v\n", formatErr)
3544
os.Exit(1)
3645
}

cmd/mcptools/commands/read_resource.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package commands
22

33
import (
4+
"context"
45
"fmt"
56
"os"
67

8+
"github.com/mark3labs/mcp-go/mcp"
79
"github.com/spf13/cobra"
810
)
911

@@ -69,8 +71,18 @@ func ReadResourceCmd() *cobra.Command {
6971
os.Exit(1)
7072
}
7173

72-
resp, execErr := mcpClient.ReadResource(resourceName)
73-
if formatErr := FormatAndPrintResponse(thisCmd, resp, execErr); formatErr != nil {
74+
request := mcp.ReadResourceRequest{}
75+
request.Params.URI = resourceName
76+
resp, execErr := mcpClient.ReadResource(context.Background(), request)
77+
78+
var responseMap map[string]any
79+
if execErr == nil && resp != nil {
80+
responseMap = ConvertJSONToMap(resp)
81+
} else {
82+
responseMap = map[string]any{}
83+
}
84+
85+
if formatErr := FormatAndPrintResponse(thisCmd, responseMap, execErr); formatErr != nil {
7486
fmt.Fprintf(os.Stderr, "%v\n", formatErr)
7587
os.Exit(1)
7688
}

cmd/mcptools/commands/read_resource_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,11 @@ func TestReadResourceCmdRun_Success(t *testing.T) {
3737

3838
// Given: a mock client that returns a successful read resource response
3939
mockResponse := map[string]any{
40-
"result": map[string]any{
41-
"contents": []any{
42-
map[string]any{
43-
"uri": "test://foo",
44-
"mimeType": "text/plain",
45-
"text": "bar",
46-
},
40+
"contents": []any{
41+
map[string]any{
42+
"uri": "test://foo",
43+
"mimeType": "text/plain",
44+
"text": "bar",
4745
},
4846
},
4947
}

cmd/mcptools/commands/resources.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package commands
22

33
import (
4+
"context"
45
"fmt"
56
"os"
67

8+
"github.com/mark3labs/mcp-go/mcp"
79
"github.com/spf13/cobra"
810
)
911

@@ -29,8 +31,15 @@ func ResourcesCmd() *cobra.Command {
2931
os.Exit(1)
3032
}
3133

32-
resp, listErr := mcpClient.ListResources()
33-
if formatErr := FormatAndPrintResponse(thisCmd, resp, listErr); formatErr != nil {
34+
resp, listErr := mcpClient.ListResources(context.Background(), mcp.ListResourcesRequest{})
35+
36+
var resources []any
37+
if listErr == nil && resp != nil {
38+
resources = ConvertJSONToSlice(resp.Resources)
39+
}
40+
41+
resourcesMap := map[string]any{"resources": resources}
42+
if formatErr := FormatAndPrintResponse(thisCmd, resourcesMap, listErr); formatErr != nil {
3443
fmt.Fprintf(os.Stderr, "%v\n", formatErr)
3544
os.Exit(1)
3645
}

cmd/mcptools/commands/shell.go

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package commands
22

33
import (
4+
"context"
45
"encoding/json"
56
"errors"
67
"fmt"
78
"os"
89
"path/filepath"
910
"strings"
1011

11-
"github.com/f/mcptools/pkg/client"
12+
"github.com/mark3labs/mcp-go/client"
13+
"github.com/mark3labs/mcp-go/mcp"
1214
"github.com/peterh/liner"
1315
"github.com/spf13/cobra"
1416
)
@@ -48,18 +50,12 @@ func ShellCmd() *cobra.Command { //nolint:gocyclo
4850
os.Exit(1)
4951
}
5052

51-
mcpClient, clientErr := CreateClientFunc(parsedArgs, client.CloseTransportAfterExecute(false))
53+
mcpClient, clientErr := CreateClientFunc(parsedArgs)
5254
if clientErr != nil {
5355
fmt.Fprintf(os.Stderr, "Error: %v\n", clientErr)
5456
os.Exit(1)
5557
}
5658

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-
6359
fmt.Fprintf(thisCmd.OutOrStdout(), "mcp > MCP Tools Shell (%s)\n", Version)
6460
fmt.Fprintf(thisCmd.OutOrStdout(), "mcp > Connected to Server: %s\n", strings.Join(parsedArgs, " "))
6561
fmt.Fprintf(thisCmd.OutOrStdout(), "\nmcp > Type '/h' for help or '/q' to quit\n")
@@ -111,19 +107,43 @@ func ShellCmd() *cobra.Command { //nolint:gocyclo
111107

112108
switch command {
113109
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}
115119
if formatErr := FormatAndPrintResponse(thisCmd, resp, listErr); formatErr != nil {
116120
fmt.Fprintf(os.Stderr, "%v\n", formatErr)
117121
continue
118122
}
119123
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}
121133
if formatErr := FormatAndPrintResponse(thisCmd, resp, listErr); formatErr != nil {
122134
fmt.Fprintf(os.Stderr, "%v\n", formatErr)
123135
continue
124136
}
125137
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}
127147
if formatErr := FormatAndPrintResponse(thisCmd, resp, listErr); formatErr != nil {
128148
fmt.Fprintf(os.Stderr, "%v\n", formatErr)
129149
continue
@@ -208,11 +228,36 @@ func callCommand(thisCmd *cobra.Command, mcpClient *client.Client, commandArgs [
208228

209229
switch entityType {
210230
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+
}
212241
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+
}
214251
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+
}
216261
default:
217262
fmt.Fprintf(os.Stderr, "Error: unsupported entity type: %s\n", entityType)
218263
}

0 commit comments

Comments
 (0)