Skip to content

Commit ac0e2e3

Browse files
committed
fix(app): auto-register tools capability in registerTool
When registerTool is called before connect() on an App created without explicit tools capability, setRequestHandler's capability assertion would throw, breaking app initialization at module load. Auto-register { tools: { listChanged: true } } on first registerTool call (pre-connect only), mirroring McpServer.registerTool behavior. Fixes pdf-annotations e2e failures where the PDF canvas never rendered because registerTool threw at module scope.
1 parent 8aca27e commit ac0e2e3

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/app.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,15 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
352352

353353
this._registeredTools[name] = registeredTool;
354354

355+
// Auto-register tools capability so setRequestHandler's capability check
356+
// passes. Mirrors McpServer.registerTool behavior — callers shouldn't need
357+
// to declare { tools: {} } in the constructor just to use registerTool.
358+
// Only do this pre-connect; post-connect the capability was already
359+
// advertised (or wasn't) and can't change.
360+
if (!this._capabilities.tools && !this.transport) {
361+
this.registerCapabilities({ tools: { listChanged: true } });
362+
}
363+
355364
this.ensureToolHandlersInitialized();
356365
return registeredTool;
357366
}

0 commit comments

Comments
 (0)