Repository navigation
Commit a23779e
authored
fix(mcp): default inputSchema to {type:"object"} for registered tools in tools/list (#529)
`MCPMock` lists a registered tool exactly as it was registered. A tool
added without `inputSchema` is therefore listed without one, but the MCP
schema requires `inputSchema` on every `Tool`. The official clients
reject the whole `tools/list` result, not just that tool.
Two documented paths produce such a tool:
- The docs Quick Start: `mcp.addTool({ name: "search", description:
"Search the web" })`
- `mcp.onToolCall("name", handler)` for a name that was never added.
That stores `{ name }`.
**Repro** (`@copilotkit/aimock` 1.45.0; current `main` has the same
handler):
```js
const mcp = new MCPMock({ port: 38733 });
mcp.addTool({ name: "search", description: "Search", inputSchema: { type: "object", properties: { query: { type: "string" } } } });
mcp.addTool({ name: "rich", description: "rich" });
await mcp.start();
```
- Python SDK 2.3.0 `list_tools()`: `ValidationError: ... ListToolsResult
tools.1.inputSchema Field required`
- TypeScript SDK 1.30.0 `client.listTools()`: `Invalid input: expected
object, received undefined` at `tools[1].inputSchema`
So a test that points a real MCP client at the mock fails at
`listTools`, before it reaches the tool it's testing.
**Fix:** in `tools/list`, a registered tool with no `inputSchema` is
listed with `{ type: "object" }`. This is the default
`McpFakes.listTools()` already uses ("A tool with no `inputSchema` lists
`{ type: "object" }`"), so registered tools and fake tools now behave
the same. A tool that has a schema is listed unchanged. The
recorded-list path also gets the default, because it reuses the same
`tools` array.
**Tests:** `mcp-mock.test.ts`.
- The existing "tools/list returns registered tools" case asserted that
`calc` is listed without `inputSchema`. I updated it to expect `{ type:
"object" }`.
- I added a case covering both the `addTool` and `onToolCall` paths.
Both fail on `main` and pass here.
- `prettier --check`, `eslint` and `pnpm typecheck` pass.
- The full `pnpm test` run on macOS shows the same 36 failures with and
without this change, all in `validate-cli*`, `mcp-fakes-report-route`,
`mcp-fakes-doc-samples` and `mcp-fakes-redgreen`. They look like they
need a built CLI or other local setup.
I left out one related gap: `resources/read` for a resource registered
without content returns no `text` or `blob`. That would be a separate PR
if you want it.4 files changed
Lines changed: 63 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
9 | 14 | | |
10 | 15 | | |
11 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
538 | 538 | | |
539 | 539 | | |
540 | 540 | | |
541 | | - | |
542 | | - | |
543 | | - | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
544 | 549 | | |
545 | 550 | | |
546 | 551 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
372 | 372 | | |
373 | 373 | | |
374 | 374 | | |
| 375 | + | |
375 | 376 | | |
376 | 377 | | |
377 | 378 | | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
378 | 419 | | |
379 | 420 | | |
380 | 421 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
450 | 450 | | |
451 | 451 | | |
452 | 452 | | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
453 | 457 | | |
454 | | - | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
455 | 463 | | |
456 | 464 | | |
457 | 465 | | |
| |||
0 commit comments