-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
Confirm this is a feature request for the Python library and not the underlying OpenAI API.
- This is a feature request for the Python library
Describe the feature or improvement you're requesting
Description
I propose adding native support to the OpenAI Python SDK for interacting with local or remote Model Context Protocol (MCP) servers. This integration would enable OpenAI SDK users to seamlessly leverage MCP-provided resources (prompts, tools, models, etc.) while retaining compatibility with OpenAI’s existing interfaces.
Proposed Functionality
- MCP Server Configuration: Allow users to configure an MCP server endpoint or local process (via parameters like
StdioServerParameters
in the example) directly within the OpenAI client initialization. - Protocol Bridging: Automatically translate OpenAI SDK requests (e.g.,
chat.completions.create
) into MCP protocol calls (e.g., prompt resolution, resource loading, tool execution) when an MCP server is configured. - Backend Agnosticism: Retain the default OpenAI API behavior unless an MCP server is explicitly specified, ensuring backward compatibility.
Use Case Example
A developer could initialize the OpenAI client with either:
# Default OpenAI behavior
client = openai.OpenAI(api_key="...")
# MCP-integrated behavior
client = openai.OpenAI(
mcp_server=StdioServerParameters(command="python", args=["mcp_server.py"])
)
Subsequent client calls would then utilize MCP-managed resources (prompts, tools), enabling dynamic model orchestration while maintaining familiar OpenAI SDK semantics.
Benefits
- Simplifies integration workflows for users operating in hybrid OpenAI/MCP environments.
- Enables use cases like runtime prompt templating, resource management, and tool execution via MCP.
- Strengthens interoperability between OpenAI’s ecosystem and the MCP protocol’s extensibility.
References
- MCP Python SDK: https://github.com/modelcontextprotocol/python-sdk
This feature would empower developers to flexibly combine OpenAI’s capabilities with MCP-managed infrastructure while maintaining a unified coding interface.
Additional context
No response