feat(app): throw helpful error when callServerTool is called with a string (#449)

Users frequently call callServerTool("tool_name", args) instead of the
correct callServerTool({ name: "tool_name", arguments: args }), resulting
in a silent/confusing failure. Detect this and throw immediately with
a message that shows the correct call shape.

Also fixes the incorrect example in examples/pdf-server/README.md that
demonstrated this same wrong usage pattern.

Fixes #386

https://claude.ai/code/session_01GqAyN4Ux7svWoU2HqsSLZF

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Olivier Chafik 2026-02-13 21:05:21 +00:00 • committed by GitHub
commit 666952980f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -678,6 +678,19 @@ describe("App <-> AppBridge integration", () => {
expect(result.content).toEqual(resultContent);
});
it("callServerTool throws a helpful error when called with a string instead of params object", async () => {
await bridge.connect(bridgeTransport);
await app.connect(appTransport);
await expect(
// @ts-expect-error intentionally testing wrong usage
app.callServerTool("my_tool"),
).rejects.toThrow(
'callServerTool() expects an object as its first argument, but received a string ("my_tool"). ' +
'Did you mean: callServerTool({ name: "my_tool", arguments: { ... } })?',
);
});
it("onlistresources setter registers handler for resources/list requests", async () => {
const requestParams = {};
const resources = [{ uri: "test://resource", name: "Test" }];