Skip to content

Show how to limit function and MCP tool output and retrieve the original - #6120

Open
markstuart-oai wants to merge 2 commits into
feat/simple-codexfrom
feat/bounded-tool-output-example
Open

markstuart-oai wants to merge 2 commits into
feat/simple-codexfrom
feat/bounded-tool-output-example

Conversation

@markstuart-oai

@markstuart-oai markstuart-oai commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

This example shows how to keep large tool results out of a conversation while letting the owner read the originals privately. It uses a local function tool and a tool discovered through MCP. Run it offline with uv run python examples/mcp/bounded_tool_output/main.py.

When a selected report exceeds 128 UTF-8 bytes of text, the tool returns a warning count and a random reference. The application can fetch the original in pages of up to 64 characters. Only the authenticated requester goes in the run context. The owner and originals stay in a private, per-run store. Closing the store revokes all references.

The local function checks access before reading, limits the text at the source and checks access again before returning. This keeps the limit in place even if the application replaces its output editor. The MCP wrapper checks access before the request and checks that the store is still open before resolving a local ticket and before returning a selected success.

Small reports, images, MCP errors and unselected results can still contain sensitive data. The example excludes native tools and provider-hosted MCP. No SDK defaults change.

Local verification

  • All 13 example tests passed with MCP 1.30.0 and 2.3.0. They cover denial before a read, closure during a pending call, replacement editors, model requests, history, events, traces and cleanup.
  • Repository formatting, lint, type checks and documentation build passed. The full test suite passed with 13,232 tests passing and 37 skipped.

@markstuart-oai
markstuart-oai requested review from a team, rm-openai and seratch as code owners November 21, 2026 05:32
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T15:34:11.770631Z 334676d New commits
🔒 Security Review ✅ Completed 2026-11-21T15:35:22.648519Z 334676d New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@jbeckwith-oai jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved after static review and an independent second review. Checked local preparation and MCP interception before conversion, custom-data extraction and span output; structured-content replacement and metadata removal; text-byte accounting, image preservation, per-run reference ownership/revocation, private retrieval, cancellation, and regression coverage. The documented exclusions for errors, small reports, images, and storage quotas match the implementation. No actionable findings. This example approval does not clear outstanding findings in the stacked base.

Hosted checks: {"SUCCESS": 16, "IN_PROGRESS": 3}. Pending checks retained for follow-up. Static review only; no candidate code or local tests were executed.

Hosted CI completion: 19 checks passed, 2 skipped; no pending or failed checks.

@jbeckwith-oai jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved after static re-review and an independent second review. The local example tool now checks access before reading and after awaited bounding, and applies its output limit before an independent output editor can observe it. MCP report handling rechecks that storage is open before resolving tickets and after awaits, including the small-result path. Reviewed trusted owner/requester separation and the new unauthorized-read, revocation, independent-editor, cancellation, and short-report regressions. No actionable findings in this increment.

Hosted CI completed: 19 passed, 2 skipped. Static review only; no candidate code or local tests executed.

This branch has not been deployed

No deployments
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