Skip to content

AutoGen

Use AllMCP tools in Microsoft AutoGen agents via autogen-ext[mcp].


install
pip install 'autogen-ext[mcp]' 'autogen-ext[anthropic]' autogen-agentchat

agent.py
import asyncio
from autogen_ext.tools.mcp import StreamableHttpServerParams, mcp_server_tools
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.ui import Console
from autogen_ext.models.anthropic import AnthropicChatCompletionClient
async def main():
params = StreamableHttpServerParams(
url="https://go.allmcp.co/mcp/",
headers={"X-API-Key": "YOUR_API_KEY"},
)
tools = await mcp_server_tools(params)
agent = AssistantAgent(
name="crm_agent",
model_client=AnthropicChatCompletionClient(model="claude-sonnet-4-6"),
tools=tools,
system_message="You are a CRM assistant. Use AllMCP tools to manage the user's data.",
)
await Console(agent.run_stream(task="List the top 5 contacts in my CRM"))
asyncio.run(main())

multi_agent.py
import asyncio
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_agentchat.ui import Console
from autogen_ext.tools.mcp import StreamableHttpServerParams, mcp_server_tools
from autogen_ext.models.anthropic import AnthropicChatCompletionClient
async def main():
params = StreamableHttpServerParams(
url="https://go.allmcp.co/mcp/",
headers={"X-API-Key": "YOUR_API_KEY"},
)
tools = await mcp_server_tools(params)
model = AnthropicChatCompletionClient(model="claude-sonnet-4-6")
data_agent = AssistantAgent(
name="DataFetcher",
model_client=model,
tools=tools,
system_message="Fetch raw data from the CRM. Do not analyze — just retrieve.",
)
analyst_agent = AssistantAgent(
name="Analyst",
model_client=model,
system_message="Analyze data provided by DataFetcher and produce insights.",
)
team = RoundRobinGroupChat([data_agent, analyst_agent], max_turns=4)
await Console(team.run_stream(task="Summarize this week's new leads by source"))
asyncio.run(main())

multi_user.py
def make_params(user_id: str) -> StreamableHttpServerParams:
return StreamableHttpServerParams(
url=f"https://go.allmcp.co/mcp/?user_id={user_id}",
headers={"X-API-Key": "YOUR_API_KEY"},
)
async def run_for_user(user_id: str, task: str):
params = make_params(user_id)
tools = await mcp_server_tools(params)
agent = AssistantAgent(
name="agent",
model_client=AnthropicChatCompletionClient(model="claude-sonnet-4-6"),
tools=tools,
)
await Console(agent.run_stream(task=task))