Skip to content

Commit c9830fc

Browse files
linfangwclaude
andcommitted
fix(mcp): handle non-JSON success response, update params_to_tool docs
- client.ts: wrap success response.json() in try-catch to handle empty/non-JSON responses gracefully - README.md, docs/en-US/mcp-server.md, docs/zh-CN/mcp-server.md: update params_to_tool type from string to object, fix examples to use object literal instead of JSON.stringify Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent abbe640 commit c9830fc

4 files changed

Lines changed: 17 additions & 9 deletions

File tree

docs/en-US/mcp-server.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ This is the **Call** action and costs **1-100 credits** per invocation, priced b
178178
|-----------|------|----------|-------------|
179179
| `tool_id` | string | Yes | Tool ID from discovery results |
180180
| `search_id` | string | Yes | Search ID from the discovery that found this tool |
181-
| `params_to_tool` | string | Yes | JSON-stringified parameters to pass to the tool |
181+
| `params_to_tool` | object | Yes | Dictionary of parameters to pass to the tool |
182182
| `session_id` | string | No | Session identifier for tracking |
183183
| `max_response_size` | number | No | Max response size in bytes (default `20480`) |
184184

@@ -188,7 +188,7 @@ Example:
188188
{
189189
"tool_id": "openweathermap.weather.execute.v1",
190190
"search_id": "YOUR_SEARCH_ID",
191-
"params_to_tool": "{\"city\":\"London\",\"units\":\"metric\"}"
191+
"params_to_tool": {"city": "London", "units": "metric"}
192192
}
193193
```
194194

@@ -251,7 +251,7 @@ If `session_id` is omitted, the MCP server may generate one for the lifetime of
251251
- Verify the API key is valid
252252
- Verify the selected `tool_id` came from a prior discovery
253253
- Re-run `get_tools_by_ids` to inspect the tool before calling
254-
- Check that `params_to_tool` is valid JSON
254+
- Check that `params_to_tool` is a valid object
255255

256256
### Windows-specific issues
257257

docs/zh-CN/mcp-server.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ QVERIS_API_KEY=your-api-key
178178
|-----|------|------|------|
179179
| `tool_id` | string || 来自发现结果的工具 ID |
180180
| `search_id` | string || 发现该工具的搜索 ID |
181-
| `params_to_tool` | string || JSON 字符串化的工具参数 |
181+
| `params_to_tool` | object || 传递给工具的参数字典 |
182182
| `session_id` | string || 用于追踪的会话标识符 |
183183
| `max_response_size` | number || 最大响应字节数(默认 `20480`|
184184

@@ -188,7 +188,7 @@ QVERIS_API_KEY=your-api-key
188188
{
189189
"tool_id": "openweathermap.weather.execute.v1",
190190
"search_id": "YOUR_SEARCH_ID",
191-
"params_to_tool": "{\"city\":\"London\",\"units\":\"metric\"}"
191+
"params_to_tool": {"city": "London", "units": "metric"}
192192
}
193193
```
194194

@@ -251,7 +251,7 @@ QVERIS_API_KEY=your-api-key
251251
- 验证 API 密钥是否有效
252252
- 验证所选 `tool_id` 来自此前的发现结果
253253
- 重新运行 `get_tools_by_ids` 检查工具后再调用
254-
- 检查 `params_to_tool` 是否为有效 JSON
254+
- 检查 `params_to_tool` 是否为有效对象
255255

256256
### Windows 特定问题
257257

packages/mcp/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Execute a discovered tool with specific parameters.
9999
|-----------|------|----------|-------------|
100100
| `tool_id` | string || Tool ID from search results |
101101
| `search_id` | string || Search ID from the search that found this tool |
102-
| `params_to_tool` | string || JSON string of parameters to pass to the tool |
102+
| `params_to_tool` | object || A dictionary of parameters to pass to the tool |
103103
| `session_id` | string | | Session identifier (auto-generated if omitted) |
104104
| `max_response_size` | number | | Max response size in bytes (default: 20480) |
105105

@@ -109,7 +109,7 @@ Execute a discovered tool with specific parameters.
109109
{
110110
"tool_id": "openweathermap.weather.execute.v1",
111111
"search_id": "abcd1234-ab12-ab12-ab12-abcdef123456",
112-
"params_to_tool": "{\"city\": \"London\", \"units\": \"metric\"}"
112+
"params_to_tool": {"city": "London", "units": "metric"}
113113
}
114114
```
115115

packages/mcp/src/api/client.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,15 @@ export class QverisClient {
118118
throw error;
119119
}
120120

121-
return response.json() as Promise<T>;
121+
try {
122+
return await response.json() as T;
123+
} catch {
124+
const error: ApiError = {
125+
status: response.status,
126+
message: 'Invalid or empty JSON response from API',
127+
};
128+
throw error;
129+
}
122130
} catch (err: unknown) {
123131
if (err && typeof err === 'object' && 'status' in err) {
124132
// ApiError — rethrow as-is

0 commit comments

Comments
 (0)