Skip to content

feat!: Structured output#316

Draft
gregnr wants to merge 9 commits into
mainfrom
feat/mcp-structured-output
Draft

feat!: Structured output#316
gregnr wants to merge 9 commits into
mainfrom
feat/mcp-structured-output

Conversation

@gregnr

@gregnr gregnr commented Jun 30, 2026

Copy link
Copy Markdown
Member

Implements outputSchema / structuredContent for MCP tools (AI-847) which implicitely fixes execute_sql doubling backslashes in results (#311).

  • Tool outputSchema is now returned as part of tools/list
  • mcp-utils validates every tool's structuredContent against its outputSchema
  • Return values from each tool's execute function feed directly into structuredContent
  • Tools now have an optional formatResult hook that renders the returned structuredContent as text content (defaults to JSON.stringify)
  • execute_sql returns rows as structuredContent and the prompt-injection fence now lives only in text content via formatResult. This removes the second JSON encode that was doubling backslashes in execute_sql corrupts backslash escaping in PL/pgSQL function bodies (round-trip failure) #311 (which confused LLMs)

The main downside to doing this is we lose the prompt-injection fence if the MCP client decides to pass the structured content directly to the LLM instead of the text-formatted version. I think this is a fair trade-off though - it matches the spirit behind structuredContent (actual structured content, not wrapped) and doesn't double JSON encode data. Client side prompt injection mitigations are a lot better than they used to be, so clients who want to use structuredContent should be willing to own this side of the security equation. Otherwise they can use the text version and continue to receive the wrapped version.

Closes AI-847
Closes #311

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 28470473556

Warning

No base build found for commit 84f1c60 on main.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 96.248%

Details

  • Patch coverage: 14 of 14 lines across 2 files are fully covered (100%).

Uncovered Changes

No uncovered changes found.

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 2824
Covered Lines: 2739
Line Coverage: 96.99%
Relevant Branches: 348
Covered Branches: 314
Branch Coverage: 90.23%
Branches in Coverage %: Yes
Coverage Strength: 43.13 hits per line

💛 - Coveralls

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.

execute_sql corrupts backslash escaping in PL/pgSQL function bodies (round-trip failure)

2 participants