Skip to main content

SDK for integrating Model Context Protocol (MCP) into OpenAI Agents

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openai_mcp_agents-0.1.0.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

openai_mcp_agents-0.1.0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file openai_mcp_agents-0.1.0.tar.gz.

File metadata

  • Download URL: openai_mcp_agents-0.1.0.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.5

File hashes

Hashes for openai_mcp_agents-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fa5aa679a454ce4230e76515680387fc09626b90230a9770295145fc1647963a
MD5 e3e6194810a7cfe028d020c9c8bbd03e
BLAKE2b-256 e870dde7e920e2ee1f90e406558d43d8aa89e593c1d16b34df6ea26dc1013096

See more details on using hashes here.

File details

Details for the file openai_mcp_agents-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for openai_mcp_agents-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba452d21e9950c6b66d45dc670c9044ac27ca5f5ad2f22ac3a4d1728348b551b
MD5 9d5fba7e3d437f40166ee7da84974172
BLAKE2b-256 55391dceb98d06e9056443b3c9850196d0b4d1ad624daa78cdf13129ac79b9f0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page