Skip to content

Preserve MCP output schemas in model requests#1986

Open
Genmin wants to merge 2 commits intoMCPJam:mainfrom
Genmin:codex/include-mcp-output-schema
Open

Preserve MCP output schemas in model requests#1986
Genmin wants to merge 2 commits intoMCPJam:mainfrom
Genmin:codex/include-mcp-output-schema

Conversation

@Genmin
Copy link
Copy Markdown

@Genmin Genmin commented May 1, 2026

Summary

  • include MCP tool outputSchema details in model-facing tool descriptions so providers can see structuredContent field meanings
  • preserve the raw MCP output schema on converted tools without misusing AI SDK tool.outputSchema for the whole CallToolResult
  • show output schemas in live raw request payloads for chat traces

Fixes #1956.

Validation

  • npm run test -w @mcpjam/sdk -- tool-converters.test.ts
  • npm run test -w @mcpjam/inspector -- model-request-payload.test.ts
  • npm run typecheck -w @mcpjam/sdk
  • npm run build -w @mcpjam/sdk
  • npm run build:server -w @mcpjam/inspector
  • git diff --check

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label May 1, 2026
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@chelojimenez
Copy link
Copy Markdown
Contributor

chelojimenez commented May 1, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@dosubot dosubot Bot added the enhancement New feature or request label May 1, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3513cdbd-8014-4fdd-88f0-d8dd6c91105e

📥 Commits

Reviewing files that changed from the base of the PR and between 69d463f and 1a73339.

📒 Files selected for processing (7)
  • .changeset/curly-tools-smile.md
  • mcpjam-inspector/server/utils/__tests__/model-request-payload.test.ts
  • mcpjam-inspector/server/utils/model-request-payload.ts
  • mcpjam-inspector/shared/model-request-payload.ts
  • sdk/src/TestAgent.ts
  • sdk/src/mcp-client-manager/tool-converters.ts
  • sdk/tests/tool-converters.test.ts
✅ Files skipped from review due to trivial changes (5)
  • mcpjam-inspector/shared/model-request-payload.ts
  • sdk/tests/tool-converters.test.ts
  • sdk/src/TestAgent.ts
  • mcpjam-inspector/server/utils/model-request-payload.ts
  • mcpjam-inspector/server/utils/tests/model-request-payload.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • .changeset/curly-tools-smile.md
  • sdk/src/mcp-client-manager/tool-converters.ts

Walkthrough

Adds support for MCP tool output schemas across the codebase: introduces an optional outputSchema on SerializedModelRequestTool; implements serializeOptionalJsonSchema and updates buildResolvedModelRequestPayload to include per-tool outputSchema when serializable; augments SDK tool conversion to embed schema hints in tool descriptions and store raw schema metadata on converted tools; and adds tests covering these behaviors.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@mcpjam-inspector/server/utils/model-request-payload.ts`:
- Around line 39-45: The current early-return for plain object schemas
incorrectly catches Zod schemas and prevents serialization; in the function
handling schema (variable name "schema") move the generic object fallback (the
branch that returns schema as Record<string, unknown>) to after the attempt to
call z.toJSONSchema(schema as z.ZodType), so first try z.toJSONSchema and return
that if it succeeds, and only if serialization fails fall back to returning the
raw object; update logic around the try/catch block referencing z.toJSONSchema
and the plain-object check to reflect this order and add a test for
outputSchema: z.object({...}).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 10128e16-4bed-4b4e-bd3e-73bede0435f2

📥 Commits

Reviewing files that changed from the base of the PR and between d6a4de4 and 559f0c9.

📒 Files selected for processing (7)
  • .changeset/curly-tools-smile.md
  • mcpjam-inspector/server/utils/__tests__/model-request-payload.test.ts
  • mcpjam-inspector/server/utils/model-request-payload.ts
  • mcpjam-inspector/shared/model-request-payload.ts
  • sdk/src/TestAgent.ts
  • sdk/src/mcp-client-manager/tool-converters.ts
  • sdk/tests/tool-converters.test.ts

Comment thread mcpjam-inspector/server/utils/model-request-payload.ts Outdated
@Genmin
Copy link
Copy Markdown
Author

Genmin commented May 1, 2026

Addressed the CodeRabbit output schema finding. serializeOptionalJsonSchema now tries z.toJSONSchema(...) before falling back to a raw object, so outputSchema: z.object(...) is serialized instead of being passed through as a non-JSON-schema Zod object.

Validation:

  • npm --prefix mcpjam-inspector test -- --run server/utils/__tests__/model-request-payload.test.ts -> 9 passed
  • npm exec prettier -- --check mcpjam-inspector/server/utils/model-request-payload.ts mcpjam-inspector/server/utils/__tests__/model-request-payload.test.ts
  • git diff --check

I also tried npm exec tsc -- --noEmit -p server/tsconfig.json; it is currently blocked by existing repo-wide type errors outside this PR (unknown JSON response bodies in many tests, unused locals, missing RequestInfo/JsonWebKey, and several route/service errors).

@Genmin Genmin force-pushed the codex/include-mcp-output-schema branch from 2d69663 to 69d463f Compare May 1, 2026 22:18
@Genmin Genmin force-pushed the codex/include-mcp-output-schema branch from 69d463f to 1a73339 Compare May 2, 2026 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Tool output schema is not passed to LLM

2 participants