Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion examples/pdf-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ On some host platforms, tool calls have size limits, so large PDFs cannot be sen
```typescript
// Load in chunks with progress
while (hasMore) {
const chunk = await app.callServerTool("read_pdf_bytes", { url, offset });
const chunk = await app.callServerTool({
name: "read_pdf_bytes",
arguments: { url, offset },
});
chunks.push(base64ToBytes(chunk.bytes));
offset += chunk.byteCount;
hasMore = chunk.hasMore;
Expand Down
13 changes: 13 additions & 0 deletions src/app-bridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" }];
Expand Down
6 changes: 6 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,12 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
params: CallToolRequest["params"],
options?: RequestOptions,
): Promise<CallToolResult> {
if (typeof params === "string") {
throw new Error(
`callServerTool() expects an object as its first argument, but received a string ("${params}"). ` +
`Did you mean: callServerTool({ name: "${params}", arguments: { ... } })?`,
);
}
return await this.request(
{ method: "tools/call", params },
CallToolResultSchema,
Expand Down
Loading