MCPAdapt: Multi-Agent Framework Adapter

0.1.20 · active · verified Thu Apr 16

MCPAdapt is a Python library designed to bridge the gap between different multi-agent cooperative (MCP) servers and various agentic frameworks. It allows developers to integrate agent servers (e.g., those following the MCP specification) with popular AI agent frameworks like CrewAI and SmolAgents, abstracting away framework-specific communication details. The current version is 0.1.20, with frequent minor releases focusing on new adapter features and bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up an MCPAdapt server using the SmolAgentsAdapter. It wraps a simple Python function (`add`) into an agent service, making it accessible via the MCP specification. The server can be run standalone using `mcp_server.run()` or integrated into an existing FastAPI application.

import uvicorn
from fastapi import FastAPI
from mcpadapt import MCPAdapt
from mcpadapt.adapters.smolagents import SmolAgentsAdapter

# Define a simple function for the agent
def add(a: int, b: int) -> int:
    """Adds two numbers."""
    return a + b

# Initialize the SmolAgentsAdapter with the function
smolagents_adapter = SmolAgentsAdapter(
    name="adder",
    description="An agent that adds two numbers.",
    func=add
)

# Create the MCPAdapt server
mcp_server = MCPAdapt(
    agent_id="adder_agent",
    adapter=smolagents_adapter,
    server_params={
        "host": os.environ.get('MCP_HOST', '127.0.0.1'), 
        "port": int(os.environ.get('MCP_PORT', '8000'))
    }
)

# To run the server (this will block):
# mcp_server.run()

# Alternatively, integrate with an existing FastAPI app (recommended for production):
app = FastAPI()
app.include_router(mcp_server.router)

# You can then run this FastAPI app using uvicorn:
# uvicorn your_module_name:app --host 127.0.0.1 --port 8000
# For testing, you could run:
# if __name__ == "__main__":
#     import os
#     os.environ['MCP_HOST'] = '127.0.0.1'
#     os.environ['MCP_PORT'] = '8000'
#     mcp_server.run()

view raw JSON →