SDK for integrating Model Context Protocol (MCP) into OpenAI Agents
Project description
OpenAI MCP Agents
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
- Fork this repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - 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
Support
If you encounter any issues while using this project, please get support through the following channels:
- Check the documentation
- Submit an Issue
- Send an email to madroidmaq@gmail.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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
Algorithm | Hash digest | |
---|---|---|
SHA256 |
fa5aa679a454ce4230e76515680387fc09626b90230a9770295145fc1647963a
|
|
MD5 |
e3e6194810a7cfe028d020c9c8bbd03e
|
|
BLAKE2b-256 |
e870dde7e920e2ee1f90e406558d43d8aa89e593c1d16b34df6ea26dc1013096
|
File details
Details for the file openai_mcp_agents-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: openai_mcp_agents-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
ba452d21e9950c6b66d45dc670c9044ac27ca5f5ad2f22ac3a4d1728348b551b
|
|
MD5 |
9d5fba7e3d437f40166ee7da84974172
|
|
BLAKE2b-256 |
55391dceb98d06e9056443b3c9850196d0b4d1ad624daa78cdf13129ac79b9f0
|