Skip to content

Commit 36e2c84

Browse files
authored
Fix tool call return type to parse as JSON before returning (#66)
1 parent 7d7aa96 commit 36e2c84

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

internal/api/servers.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package api
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"net/http"
78
"slices"
@@ -162,8 +163,16 @@ func handleServerToolCall(accessor contracts.MCPClientAccessor, server string, t
162163
return nil, fmt.Errorf("%w: %s/%s: %v", errors.ErrToolCallFailedUnknown, server, tool, extractMessage(result.Content))
163164
}
164165

166+
// Parse the response content of the tool, ensure we can translate the message as JSON.
167+
msg := extractMessage(result.Content)
168+
var respData map[string]any
169+
err = json.Unmarshal([]byte(msg), &respData)
170+
if err != nil {
171+
return nil, fmt.Errorf("%w: %s/%s: error parsing response: %s: %w", errors.ErrToolCallFailedUnknown, server, tool, msg, err)
172+
}
173+
165174
resp := &ToolCallResponse{}
166-
resp.Body = extractMessage(result.Content)
175+
resp.Body = respData
167176

168177
return resp, nil
169178
}

internal/api/tools.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type ToolsResponse struct {
1616

1717
// ToolCallResponse represents the wrapped API response for calling a tool.
1818
type ToolCallResponse struct {
19-
Body string
19+
Body map[string]any
2020
}
2121

2222
// Tool represents a callable tool, following the MCP spec.

internal/runtime/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func AggregateConfigs(
5454
}
5555

5656
func (s *Server) Environ() []string {
57-
baseEnvs := os.Environ()
57+
baseEnvs := os.Environ() // TODO: Only 'add' required/configured env vars for this server's binary.
5858
overrideEnvs := make([]string, 0, len(s.Env))
5959
for k, v := range s.Env {
6060
overrideEnvs = append(overrideEnvs, fmt.Sprintf("%s=%s", k, v))

0 commit comments

Comments
 (0)