Skip to content

feat: support structured tool outputs and cancellation - #6

Open
jo-adithya wants to merge 2 commits into
feat/manifest-v3from
feat/tool-output-schemas
Open

jo-adithya wants to merge 2 commits into
feat/manifest-v3from
feat/tool-output-schemas

Conversation

@jo-adithya

Copy link
Copy Markdown
Collaborator

Summary

  • Advertise supported object output schemas and return normalized structuredContent alongside JSON text.
  • Validate final handler results; keep unsupported schemas and undeclared outputs text-only.
  • Provide handlers a per-call AbortSignal for cooperative cancellation.
  • Add output/cancellation tests and documentation, including removal of a stale catalog reference in test setup.

Stack

Part 2 of 2; depends on #5. This PR targets feat/manifest-v3 so its diff contains only the tool-output changes. Merge #5 first, then retarget this PR to main if necessary.

Verification

  • Single-agent source review of the full stack.
  • Isolated TypeScript check using existing external dependencies confirms the catalog errors are fixed; only an unrelated error in unchanged derive-public.ts remains.
  • Standard app tests remain blocked locally by the missing @modelcontextprotocol/sdk dependency.
  • Runtime behavior has not been verified by a passing local test run.

@jo-adithya
jo-adithya added this pull request to stack #7 October 20, 2026 05:25

@alexng353 alexng353 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alexng353 alexng353 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[agent] Review at a207f33 (stacked on #5). Same eight-read pass. bun test and type-check pass. Integration was not run.

Must-fix: one tool's output schema can hide every tool in the plugin. The SDK advertises the Zod-derived JSON Schema as outputSchema (app.ts:158). If that schema doesn't compile in the client's validator (for example a regex containing \-, which is valid in JS but not under unicode-mode AJV), listTools() throws, and Futurity drops the whole server. Both Claude reads reproduced this with a real MCP client. Fix: in declaresOutput (app.ts:80), compile the schema with the MCP SDK's own validator, and fall back to text-only output if it fails.

Related: some outputs pass Zod on the server but fail the client's schema check (regex flags are dropped, local datetimes). The same compile-and-validate step catches these.

Should-fix

  • Aborts on close need SDK >= 1.26. "Aborts on close" isn't true below that version, but the peer range is ^1.24.3. Raise the floor or document the limit. Three reads confirmed this.
  • .overwrite() schemas run twice. A Zod schema using .overwrite() is applied twice per call, and the second pass then fails validation (app.ts:89). Reproduced.

Nit: tools without an input schema receive the SDK's entire request context as input. That predates this PR, but this PR rewrote the line and documented the quirk instead of fixing it. Pass {} instead.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

@jo-adithya
jo-adithya force-pushed the feat/tool-output-schemas branch from a207f33 to 20a0a2a Compare October 20, 2026 17:11
@jo-adithya
jo-adithya force-pushed the feat/tool-output-schemas branch from 20a0a2a to 07eac1f Compare October 20, 2026 19:06
@jo-adithya
jo-adithya requested a review from alexng353 October 21, 2026 04:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants