@@ -20,9 +20,10 @@ import (
20 "github.com/mark3labs/mcp-go/mcp"
20 "github.com/mark3labs/mcp-go/mcp"
23−type mcpTool struct {
23+type McpTool struct {
24 mcpName string
24 mcpName string
25 tool mcp.Tool
25 tool mcp.Tool
26 mcpConfig config.MCPConfig
27 mcpConfig config.MCPConfig
27 permissions permission.Service
28 permissions permission.Service
28 workingDir string
29 workingDir string
@@ -38,11 +39,11 @@ type MCPClient interface {
38 Close() error
39 Close() error
41−func (b *mcpTool) Name() string {
42+func (b *McpTool) Name() string {
42 return fmt.Sprintf("mcp_%s_%s", b.mcpName, b.tool.Name)
43 return fmt.Sprintf("mcp_%s_%s", b.mcpName, b.tool.Name)
45−func (b *mcpTool) Info() tools.ToolInfo {
46+func (b *McpTool) Info() tools.ToolInfo {
46 required := b.tool.InputSchema.Required
47 required := b.tool.InputSchema.Required
47 if required == nil {
48 if required == nil {
48 required = make([]string, 0)
49 required = make([]string, 0)
@@ -56,7 +57,6 @@ func (b *mcpTool) Info() tools.ToolInfo {
58func runTool(ctx context.Context, c MCPClient, toolName string, input string) (tools.ToolResponse, error) {
59func runTool(ctx context.Context, c MCPClient, toolName string, input string) (tools.ToolResponse, error) {
60 initRequest := mcp.InitializeRequest{}
60 initRequest := mcp.InitializeRequest{}
61 initRequest.Params.ProtocolVersion = mcp.LATEST_PROTOCOL_VERSION
61 initRequest.Params.ProtocolVersion = mcp.LATEST_PROTOCOL_VERSION
62 initRequest.Params.ClientInfo = mcp.Implementation{
62 initRequest.Params.ClientInfo = mcp.Implementation{
@@ -93,7 +93,7 @@ func runTool(ctx context.Context, c MCPClient, toolName string, input string) (t
93 return tools.NewTextResponse(output), nil
93 return tools.NewTextResponse(output), nil
96−func (b *mcpTool) Run(ctx context.Context, params tools.ToolCall) (tools.ToolResponse, error) {
96+func (b *McpTool) Run(ctx context.Context, params tools.ToolCall) (tools.ToolResponse, error) {
97 sessionID, messageID := tools.GetContextValues(ctx)
97 sessionID, messageID := tools.GetContextValues(ctx)
98 if sessionID == "" || messageID == "" {
98 if sessionID == "" || messageID == "" {
99 return tools.ToolResponse{}, fmt.Errorf("session ID and message ID are required for creating a new file")
99 return tools.ToolResponse{}, fmt.Errorf("session ID and message ID are required for creating a new file")
@@ -114,43 +114,13 @@ func (b *mcpTool) Run(ctx context.Context, params tools.ToolCall) (tools.ToolRes
114 return tools.ToolResponse{}, permission.ErrorPermissionDenied
114 return tools.ToolResponse{}, permission.ErrorPermissionDenied
117− switch b.mcpConfig.Type {
118− case config.MCPStdio:
119− c, err := client.NewStdioMCPClient(
120− b.mcpConfig.Command,
121− b.mcpConfig.ResolvedEnv(),
122− b.mcpConfig.Args...,
125− return tools.NewTextErrorResponse(err.Error()), nil
127− return runTool(ctx, c, b.tool.Name, params.Input)
128− case config.MCPHttp:
129− c, err := client.NewStreamableHttpClient(
131− transport.WithHTTPHeaders(b.mcpConfig.ResolvedHeaders()),
134− return tools.NewTextErrorResponse(err.Error()), nil
136− return runTool(ctx, c, b.tool.Name, params.Input)
138− c, err := client.NewSSEMCPClient(
140− client.WithHeaders(b.mcpConfig.ResolvedHeaders()),
143− return tools.NewTextErrorResponse(err.Error()), nil
145− return runTool(ctx, c, b.tool.Name, params.Input)
117+ return runTool(ctx, b.client, b.tool.Name, params.Input)
148− return tools.NewTextErrorResponse("invalid mcp type"), nil
151−func NewMcpTool(name string, tool mcp.Tool, permissions permission.Service, mcpConfig config.MCPConfig, workingDir string) tools.BaseTool {
120+func NewMcpTool(name string, c MCPClient, tool mcp.Tool, permissions permission.Service, mcpConfig config.MCPConfig, workingDir string) tools.BaseTool {
152− return &mcpTool{
121+ return &McpTool{
153 mcpName: name,
122 mcpName: name,
154 tool: tool,
124 tool: tool,
155 mcpConfig: mcpConfig,
125 mcpConfig: mcpConfig,
156 permissions: permissions,
126 permissions: permissions,
@@ -179,9 +149,8 @@ func getTools(ctx context.Context, name string, m config.MCPConfig, permissions
179 return stdioTools
149 return stdioTools
181 for _, t := range tools.Tools {
151 for _, t := range tools.Tools {
182− stdioTools = append(stdioTools, NewMcpTool(name, t, permissions, m, workingDir))
152+ stdioTools = append(stdioTools, NewMcpTool(name, c, t, permissions, m, workingDir))
185 return stdioTools
154 return stdioTools