Skip to main content

flatresult

MCP tools can return more than text: structuredContent, resource_link blocks, embedded resources and audio. Many clients only handle text and image blocks, so the result shows up empty, gets dropped, prints as a raw struct, or fails the whole call with Unsupported response item type: resource_link.

flatresult rewrites tool results into text and image blocks every client reads. It puts the JSON of structuredContent in a text block when the server sent none, reads linked resources from the server and puts their contents inline, and turns embedded resources into text (or an image). Use it as a stdio proxy around any MCP server (no code changes, any language) or as one function. No dependencies.

pip install flatresult

Quick start: any stdio server

Put flatresult proxy -- in front of the server command in your client's config:

{
  "mcpServers": {
    "my-server": {
      "command": "flatresult",
      "args": ["proxy", "--", "npx", "-y", "@acme/mcp-server"]
    }
  }
}

Or with uvx, nothing to install first: "command": "uvx", "args": ["flatresult", "proxy", "--", ...].

For a remote (HTTP) server, wrap a stdio bridge such as mcp-remote:

{
  "mcpServers": {
    "figma": {
      "command": "uvx",
      "args": ["flatresult", "proxy", "--", "npx", "-y", "mcp-remote", "https://mcp.figma.com/mcp"]
    }
  }
}

Each rewrite is reported on stderr (most clients show it in their MCP log):

flatresult: content[0]: resource_link -> inline contents: text block
flatresult: structuredContent: structuredContent -> text block (412 chars)

Proxy options

Option What it does
--keep Keep the original blocks and add the text after them, for clients that skip unknown blocks instead of failing on them.
--no-inline Don't read linked resources; turn each link into a text line naming it.
--max-links N Read at most N linked resources per result (default 5). The rest become text lines.
--max-text CHARS Cut resource text put inline after CHARS characters (default 100,000), with a note saying how much was left out.
--timeout SECONDS If the server has not answered resources/read by then, send the result with the links as text (default 10).
--quiet / --log FILE Don't report rewrites, or append them to a file instead of stderr.

Only the results of the client's own tools/call requests are touched. Everything else passes through byte for byte. Linked resources are read with the server's own resources/read, so the proxy needs no credentials of its own; the client never sees those requests. If the server says it has no resources capability, links become text lines.

What gets rewritten

The server sends The client gets
structuredContent with no text block a text block with its JSON (structuredContent is kept), as the spec asks servers to do
resource_link Resource: <name> <uri> (mime type, size) and its description, plus the resource's contents when the server can read it
embedded text resource (type: "resource", text) a text block: <uri> (<mime type>): and the text
embedded image blob an image block
other embedded blobs, audio a short note: [binary resource file:///r.pdf: application/pdf, 52,113 bytes, not shown]
text, image, unknown block types unchanged

In your own client or server: one function

from flatresult import flatten

result = {"content": [], "structuredContent": {"temp": 21.5, "unit": "C"}}
flat = flatten(result)
flat.result["content"]   # [{"type": "text", "text": '{"temp": 21.5, "unit": "C"}'}]
[str(c) for c in flat.changes]
# ['structuredContent: structuredContent -> text block (27 chars)']

flatten(result, keep=False, read=None, max_text=100_000) takes a tools/call result (a dict) and returns Flattened(result, changes). It never changes its input, and returns the same object when nothing needs rewriting. Pass read, a function from a uri to the contents list of a resources/read result (or None), to put linked resources inline. links(result) lists the uris to read.

To see what a result would look like, there's a command too (exit code 2 when it rewrote something):

echo '{"content": [{"type": "resource_link", "uri": "file:///r.txt", "name": "report"}]}' \
  | flatresult check

Limits

  • It fixes what the client is given, not how the client shows it. A client that already reads structuredContent or resource links gets the same data twice with --keep, and as text instead of its own UI without it. Use it for clients that show nothing.
  • Links are read only from the server behind the proxy. An https:// link the server can't read stays a text line; the proxy never fetches URLs itself.
  • Binary resources other than images are not decoded (a PDF stays a note with its size).
  • The proxy speaks stdio. For a remote server, put a stdio bridge such as mcp-remote behind it.

Why this exists

The spec says a tool that returns structuredContent SHOULD also return the JSON as text, and that clients should handle every content type. In practice both sides skip it, and users of one client lose the data another client shows:

Some clients have closed their reports one by one (LibreChat#15198, goose#13182, Cherry Studio#23290), each on its own schedule. flatresult works in front of any client today, with servers you don't control.

License

MIT

Metadata

Release files for flatresult 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flatresult 0.1.0
File Size Uploaded Provenance Actions
flatresult-0.1.0.tar.gz 19.5 kB Without provenance Details for flatresult-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for flatresult 0.1.0
File Interpreter ABI Platform Actions
flatresult-0.1.0-py3-none-any.whl Python 3 none any Details for flatresult-0.1.0-py3-none-any.whl

Total release size: 35.5 kB

Release files / flatresult-0.1.0.tar.gz

Download URL flatresult-0.1.0.tar.gz
Size 19.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7fdc50dd263e2aa52fc8aaac6cc389644904e4b3afcbd05bf37b122edcb91f30
BLAKE2b-256 checksum
How to use checksums
7f975450b7b6d965e00f4aa0895d30c4a6ce6002069891f0dd96dbaf0dd85a94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / flatresult-0.1.0-py3-none-any.whl

Download URL flatresult-0.1.0-py3-none-any.whl
Size 16.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
43feb65c7996e89a930b1b1e64b59decce77a1f75a97beae78e2dc448c27ba50
BLAKE2b-256 checksum
How to use checksums
aceed8a834abeb4423457c1190f46774ddd2b1adaf6b541c33e7567fefd8d8e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for flatresult 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page