Skip to main content

OpenAI MCP Agents

Python 3.11+ License Code style: black

This project is an SDK that integrates Model Context Protocol (MCP) into OpenAI Agents. It allows you to easily provide MCP server functionality as tools for OpenAI Agents to use.

Features

  • Supports two connection types:
    • Stdio connection: Communicate with local processes via standard input/output
    • SSE connection: Communicate with remote servers via Server-Sent Events
  • Supports two usage patterns:
    • Using async context manager (async with) for automatic connection management
    • Manual connection management via connect() and disconnect() methods
  • Support for connecting to multiple MCP servers
  • Full type hint support
  • Detailed example code provided

Installation

Using uv (Recommended)

uv install git+https://github.com/madroidmaq/openai-mcp-agents.git

Using pip

pip install git+https://github.com/madroidmaq/openai-mcp-agents.git

Development Environment Setup

If you want to contribute to the project, you can set up your development environment as follows:

# Clone the repository
git clone https://github.com/madroidmaq/openai-mcp-agents.git
cd openai-mcp-agents

# Create a virtual environment and install dependencies using uv
uv venv
source .venv/bin/activate  # On Windows use .venv\Scripts\activate
uv pip install -e .

Usage Examples

Single Server Connection

from openai_mcp_agents.mcp_agent import McpAgent
from mcp import StdioServerParameters

# Configure MCP server
server_params = StdioServerParameters(
    command="npx",
    args=["-y", "@modelcontextprotocol/server-filesystem", "/path/to/dir"],
)

# Using async context manager
async with McpAgent(
    name="Filesystem Assistant",
    instructions="You are a filesystem assistant",
    mcp_server=server_params,
    model="gpt-4"
) as agent:
    result = await Runner.run(
        agent,
        input="Please list all files in the directory.",
        context={}
    )
    print(result.final_output)

Multiple Server Connection

from openai_mcp_agents.mcp_agent import MultiServerMCPClient

async with MultiServerMCPClient({
    "math": {
        "command": "python",
        "args": ["/path/to/math_server.py"],
        "transport": "stdio",
    },
    "weather": {
        "url": "http://localhost:8000/sse",
        "transport": "sse",
    }
}) as client:
    all_tools = client.get_tools()
    # Use the tools...

API Documentation

McpAgent

McpAgent class inherits from Agent class and is used to connect to a single MCP server.

class McpAgent(Agent):
    def __init__(self,
        mcp_server: Optional[Union[StdioServerParameters, StdioConnection, SSEConnection]] = None,
        **kwargs):
        ...

MultiServerMCPClient

MultiServerMCPClient class is used to connect to multiple MCP servers simultaneously.

class MultiServerMCPClient(Agent):
    def __init__(self,
        connections: Optional[Dict[str, Union[StdioConnection, SSEConnection]]] = None,
        name: str = "MultiServerMCPClient",
        **kwargs):
        ...

Contributing

Issues and Pull Requests are welcome!

Contribution Process

  1. Fork this repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Code Style

This project uses Black for code formatting and mypy for type checking. Please ensure you run these tools before submitting your code.

black src tests examples
mypy src

License

Apache License 2.0

Support

If you encounter any issues while using this project, please get support through the following channels:

  1. Check the documentation
  2. Submit an Issue
  3. Send an email to madroidmaq@gmail.com

Metadata

Release files for openai-mcp-agents 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 openai-mcp-agents 0.1.0
File Size Uploaded Provenance
openai_mcp_agents-0.1.0.tar.gz 18.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for openai-mcp-agents 0.1.0
File Interpreter ABI Platform
openai_mcp_agents-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 31.7 kB

Release files / openai_mcp_agents-0.1.0.tar.gz

Download URL openai_mcp_agents-0.1.0.tar.gz
Size 18.0 kB
Tags Source
SHA-256 checksum
How to use checksums
fa5aa679a454ce4230e76515680387fc09626b90230a9770295145fc1647963a
BLAKE2b-256 checksum
How to use checksums
e870dde7e920e2ee1f90e406558d43d8aa89e593c1d16b34df6ea26dc1013096
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.5

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

Download URL openai_mcp_agents-0.1.0-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ba452d21e9950c6b66d45dc670c9044ac27ca5f5ad2f22ac3a4d1728348b551b
BLAKE2b-256 checksum
How to use checksums
55391dceb98d06e9056443b3c9850196d0b4d1ad624daa78cdf13129ac79b9f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.5

Security for openai-mcp-agents 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