Feature Request: Add MCP Client Sampling Support to Codex

Resolved 💬 8 comments Opened Oct 8, 2025 by yaonyan Closed Oct 17, 2025
💡 Likely answer: A maintainer (gpeal, contributor) responded on this thread — see the highlighted reply below.

What feature would you like to see?

Add MCP Client Sampling support to Codex, following the MCP Specification.

What this enables:
This allows MCP servers to call AI models through the CLI client, transforming simple MCP tools into intelligent agents that can reason and make decisions.

Practical Example - Background Code Style Checker:

While coding, you start an MCP style checker tool that returns immediately, then works silently in the background.

It monitors file saves and uses AI (via sampling) to analyze violations in context - understanding your project's conventions and complexity patterns.

The analysis runs asynchronously without blocking your workflow, using your existing OpenAI subscription and requiring no separate API keys.

Technical Requirements:

  • Declare sampling: {} capability when connecting to MCP servers
  • Handle sampling/createMessage requests from MCP servers
  • Support model preferences (hints, cost/speed/intelligence priorities)
  • Forward requests to appropriate OpenAI models

Benefits:

  • Users don't need separate API keys for each MCP server
  • Users control which model is used (balancing cost vs intelligence)
  • Enables context-aware MCP tools that can perform complex reasoning
  • Provides feature parity with VS Code (which already supports this)

Additional information

This feature is part of the MCP specification and would unlock a new ecosystem of intelligent MCP tools for codex users.

For reference, VS Code already supports this feature with GitHub Copilot, allowing MCP servers to leverage the user's existing AI subscription through sampling requests:

!Image

View original on GitHub ↗

8 Comments

CaliLuke · 9 months ago

super useful, I have a very important use case for this capability that is required for an mcp server I'm developing. Would simplify my life considerably.

yaonyan · 9 months ago

@CaliLuke
The sampling support is now implemented in PR #5116. You can try it out
Would love to hear your feedback on whether this works for your use case! Let me know if you run into any issues. 🙏

CaliLuke · 9 months ago

I'm testing right now, so far it's been going pretty well and haven't seen any issues. I will update you when my testing is finalized in a few days.

gpeal contributor · 9 months ago

Unfortunately, this isn't something we can accept at this time. Although there are many valid use cases for this, we don't yet have an appropriate way to prevent people from abusing this to turn their ChatGPT Codex credits into generic completions API credits. We will continue to think through alternatives here and may revisit this in the future.

yaonyan · 9 months ago

@gpeal, thanks for the explanation. I understand the concern about credit abuse.

Would it be possible to reconsider if the feature is enabled only when a user provides a custom model_provider? This would mean they are using their own API credits, which should prevent the abuse scenario you described.

CaliLuke · 9 months ago

@gpeal why is this a problem? Since usage is metered the extra calls are going to come out of the same allotment as the rest of the current user's usage. Why would that be treated differently?

yaonyan · 9 months ago

My suggestion comes from the hope that Codex, as an open-source coding agent, can really help push the MCP(client side) ecosystem forward. I believe features like this are a key part of that journey.

keyvez · 5 months ago
Unfortunately, this isn't something we can accept at this time. Although there are many valid use cases for this, we don't yet have an appropriate way to prevent people from abusing this to turn their ChatGPT Codex credits into generic completions API credits. We will continue to think through alternatives here and may revisit this in the future.

Can you do it for when a user is using an oss model and when not using openai credits as in going through the API, and the same on the desktop GUI?