-
Notifications
You must be signed in to change notification settings - Fork 424
fix: include schema guidance in empty-arguments error to prevent missing-tool reports #40542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+44
−2
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -354,6 +354,9 @@ describe("mcp_server_core.cjs", () => { | |
| expect(results[0].error.message).toContain("write-once, not a discovery probe"); | ||
| expect(results[0].error.message).toContain("tools/list"); | ||
| expect(results[0].error.message).toContain("noop"); | ||
| // Schema guidance should be included so the model can retry without calling tools/list | ||
| expect(results[0].error.message).toContain("Example:"); | ||
| expect(results[0].error.message).toContain("Required parameter"); | ||
|
Comment on lines
+357
to
+359
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/tdd] These new assertions cover only the 💡 Suggested addition in the handleRequest describe blockit("should return probe-detection error with schema guidance for empty arguments", async () => {
const { createServer, registerTool, handleRequest } = await import("./mcp_server_core.cjs");
const server = createServer({ name: "safe-outputs", version: "1.0.0" });
registerTool(server, {
name: "create_issue",
description: "Create an issue",
inputSchema: {
type: "object",
properties: {
title: { type: "string", description: "Issue title" },
body: { type: "string", description: "Issue body" },
},
required: ["title", "body"],
},
handler: () => ({ content: [] }),
});
const response = await handleRequest(server, {
jsonrpc: "2.0", id: 10, method: "tools/call",
params: { name: "create_issue", arguments: {} },
});
expect(response.error.code).toBe(-32602);
expect(response.error.message).toContain("write-once, not a discovery probe");
expect(response.error.message).toContain("Required parameter");
expect(response.error.message).toContain("Example:");
}); |
||
| }); | ||
|
|
||
| it("should return enhanced error for partially-supplied but invalid required fields", async () => { | ||
|
|
@@ -568,6 +571,43 @@ describe("mcp_server_core.cjs", () => { | |
| expect(response.error.message).toContain("too short"); | ||
| expect(response.error.message).toContain("20"); | ||
| }); | ||
|
|
||
| it("should return error for empty arguments object (probe detection) via handleRequest", async () => { | ||
| const { createServer, registerTool, handleRequest } = await import("./mcp_server_core.cjs"); | ||
| const server = createServer({ name: "test-server", version: "1.0.0" }); | ||
|
|
||
| registerTool(server, { | ||
| name: "probe_tool", | ||
| description: "A tool to test probe detection", | ||
| inputSchema: { | ||
| type: "object", | ||
| properties: { input: { type: "string", description: "Some input" } }, | ||
| required: ["input"], | ||
| }, | ||
| handler: args => ({ | ||
| content: [{ type: "text", text: `received: ${args.input}` }], | ||
| }), | ||
| }); | ||
|
|
||
| const response = await handleRequest(server, { | ||
| jsonrpc: "2.0", | ||
| id: 10, | ||
| method: "tools/call", | ||
| params: { | ||
| name: "probe_tool", | ||
| arguments: {}, // completely empty — probe attempt | ||
| }, | ||
| }); | ||
|
|
||
| expect(response.error).toBeDefined(); | ||
| expect(response.error.code).toBe(-32602); | ||
| expect(response.error.message).toContain("write-once, not a discovery probe"); | ||
| expect(response.error.message).toContain("tools/list"); | ||
| expect(response.error.message).toContain("noop"); | ||
| // Schema guidance should be included so the model can retry without calling tools/list | ||
| expect(response.error.message).toContain("Example:"); | ||
| expect(response.error.message).toContain("Required parameter"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("loadToolHandlers", () => { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/diagnose] Minor consistency nit: in the empty-args branch
missingalready equalstool.inputSchema.required(all fields are missing), so passingtool.inputSchema.requiredtogenerateEnhancedErrorMessageis equivalent but slightly diverges from the partial-args path just below (line 783) which usesmissing.💡 Suggested change
Same change applies to line 945 in the
handleMessagepath. This makes both branches read consistently and avoids the impression that a different field list is intentional.