Auto-unwrap FastMCP results

Resolved 💬 2 comments Opened Apr 14, 2026 by lunbun Closed May 16, 2026

What variant of Codex are you using?

App, CLI

What feature would you like to see?

FastMCP servers will auto-wrap all tool responses in a {"result": ...} JSON structure in order to comply with the MCP spec when returning primitive values (see: https://fastmcp.wiki/en/clients/tools#primitive-type-unwrapping). FastMCP assumes that the MCP client will auto-unwrap these.

Codex does not currently unwrap FastMCP results. I tested both Gemini CLI and the VSCode GitHub Copilot extension, and they both seem to unwrap them.

I think this would be a nice feature to have. With the current behavior, any FastMCP primitive strings are kept JSON-encoded, meaning newlines are escaped. For example:

{"result": "example1\nexample2"}

instead of

example1
example2

I've noticed that with strings with lots of newlines, model performance seems to be slightly worse when in this escaped form rather than as a raw string.

In order to avoid tampering with non-FastMCP servers that happen to return JSON of the form {"result": ...}, FastMCP seems to set "x-fastmcp-wrap-result": true in the schema which can be used to detect FastMCP servers.

The only potential downside I can think of this feature is that it increases risk of prompt injection, so (maybe) this could be an opt-in feature in the config.toml.

Additional information

_No response_

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗