Skip to content

Commit a23779e

Browse files
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.
2 parents 75e04da + 3b13230 commit a23779e

4 files changed

Lines changed: 63 additions & 4 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
- **OpenRouter Video: `openai/sora-2` now returns the real removal rejection, not a job.** OpenRouter removed the model, and a live submit returns `400 {"error":{"message":"Model openai/sora-2 does not exist","code":400}}`. `POST /api/v1/videos` with `model: "openai/sora-2"` now returns that 400 even when a fixture matches, and never reaches a record-mode upstream. The default `GET /api/v1/videos/models` listing no longer includes `openai/sora-2`, and a fixture for it no longer adds it to the listing. Move fixtures to a model OpenRouter still serves (for example `bytedance/seedance-2.0`). The daily drift check now confirms the model stays absent instead of requiring it.
88

9+
### Fixed
10+
11+
- **MCP: `tools/list` now gives every registered tool an `inputSchema`.** A tool registered with `addTool()` without an `inputSchema`, or only with `onToolCall()`, was listed with no `inputSchema`, and the official MCP SDK client rejected the whole `tools/list` response. These tools are now listed with `inputSchema: { "type": "object" }`, as fake-only tools already were, so the `tools/list` response for them now includes that field. Tools registered with an `inputSchema` are listed unchanged (#529).
12+
- **MCP: `tools/list` now adds `"type": "object"` to a registered `inputSchema` that has no `type`.** A schema such as `{}` or `{ "properties": { ... } }` was listed as is, and the official MCP SDK client rejected the whole `tools/list` response (`inputSchema.type: expected "object"`). Such a schema is now listed with `"type": "object"` added and its other keys kept. A schema with an explicit `type` is listed unchanged (#529).
13+
914
## [1.45.0] - 2026-10-10
1015

1116
Every fixture, config and request that 1.44.0 accepted behaves the same by default. New behavior that would change those inputs is opt-in.

‎docs/mcp-mock/index.html‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,14 @@ <h3>Precedence</h3>
538538
<p>
539539
<code>tools/list</code> returns the registered tools plus the tools named in the
540540
request&rsquo;s blocks. A fake-only tool is listed with its <code>description</code> and
541-
<code>inputSchema</code>, or with <code>{ "type": "object" }</code> as its schema. When a
542-
tool is both registered and faked, the registered definition is listed. Fakes never remove
543-
a registered tool from the list.
541+
<code>inputSchema</code>, or with <code>{ "type": "object" }</code> as its schema. A
542+
registered tool without an <code>inputSchema</code> (an <code>addTool()</code> call
543+
without one, or a tool that has only an <code>onToolCall</code> handler) is also listed
544+
with <code>{ "type": "object" }</code> as its schema. A registered
545+
<code>inputSchema</code> that has no <code>type</code> is listed with
546+
<code>"type": "object"</code> added and its other keys kept. When a tool is both
547+
registered and faked, the registered definition is listed. Fakes never remove a registered
548+
tool from the list.
544549
</p>
545550

546551
<h3>Errors</h3>

‎src/__tests__/mcp-mock.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,50 @@ describe("MCPMock", () => {
372372
expect(data.result.tools[1]).toEqual({
373373
name: "calc",
374374
description: "Calculator",
375+
inputSchema: { type: "object" },
375376
});
376377
});
377378

379+
it("tools/list gives every tool an inputSchema, as the MCP schema requires", async () => {
380+
// The official SDK clients reject the whole list when one tool lacks
381+
// inputSchema. Both of these register a tool without one.
382+
mcp = new MCPMock();
383+
mcp.addTool({ name: "search", description: "Search the web" });
384+
mcp.onToolCall("lookup", () => "x");
385+
const url = await mcp.start();
386+
const sessionId = await initSession(url);
387+
388+
const res = await jsonRpc(url, "/", "tools/list", {}, 1, { "mcp-session-id": sessionId });
389+
const data = JSON.parse(res.body);
390+
expect(data.result.tools).toEqual([
391+
{ name: "search", description: "Search the web", inputSchema: { type: "object" } },
392+
{ name: "lookup", inputSchema: { type: "object" } },
393+
]);
394+
});
395+
396+
it("tools/list adds type object to an inputSchema without a type", async () => {
397+
// The official SDK clients also reject the whole list when a tool's
398+
// inputSchema has no `type`. Other keys are kept; an explicit type is not
399+
// rewritten.
400+
mcp = new MCPMock();
401+
mcp.addTool({ name: "empty", inputSchema: {} });
402+
mcp.addTool({ name: "props", inputSchema: { properties: { q: { type: "string" } } } });
403+
mcp.addTool({ name: "typed", inputSchema: { type: "object", required: [] } });
404+
const url = await mcp.start();
405+
const sessionId = await initSession(url);
406+
407+
const res = await jsonRpc(url, "/", "tools/list", {}, 1, { "mcp-session-id": sessionId });
408+
const data = JSON.parse(res.body);
409+
expect(data.result.tools).toEqual([
410+
{ name: "empty", inputSchema: { type: "object" } },
411+
{
412+
name: "props",
413+
inputSchema: { type: "object", properties: { q: { type: "string" } } },
414+
},
415+
{ name: "typed", inputSchema: { type: "object", required: [] } },
416+
]);
417+
});
418+
378419
it("tools/call with function handler", async () => {
379420
mcp = new MCPMock();
380421
mcp.onToolCall("add", (args: unknown) => {

‎src/mcp-handler.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,16 @@ export function createMCPRequestHandler(state: MCPState) {
450450

451451
"tools/list": async (_params, id, req) => {
452452
const tools: MCPToolDefinition[] = [];
453+
// inputSchema is required on every listed Tool, with a root `type`; a
454+
// tool registered without one lists `{ type: "object" }`, as fake
455+
// tools already do, and a schema without a `type` gets
456+
// `type: "object"` added. An explicit `type` is left as is.
453457
for (const { def } of state.tools.values()) {
454-
tools.push(def);
458+
tools.push(
459+
def.inputSchema?.type !== undefined
460+
? def
461+
: { ...def, inputSchema: { type: "object", ...def.inputSchema } },
462+
);
455463
}
456464
const ctx = contexts.get(req);
457465
// AM7: a recorded list comes first, in recorded order (its definition

0 commit comments

Comments
 (0)