> For the complete documentation index, see [llms.txt](https://docs.allmcp.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.allmcp.co/documentation/agent-frameworks/autogen.md).

# AutoGen

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

***

## Install

{% code title="install" %}

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

{% endcode %}

***

## Minimal example

{% code title="agent.py" overflow="wrap" %}

```python
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())
```

{% endcode %}

{% hint style="info" %}
**AutoGen is async.** `mcp_server_tools` and the agent's `run_stream` are awaited inside an `async def main()`, launched with `asyncio.run(main())`.
{% endhint %}

***

## Multi-agent setup

{% code title="multi\_agent.py" overflow="wrap" %}

```python
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())
```

{% endcode %}

***

## Multi-user setup

{% code title="multi\_user.py" overflow="wrap" %}

```python
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))
```

{% endcode %}

{% hint style="info" %}
**Scope tools to a user.** Append `?user_id={user_id}` to the endpoint URL to route each agent run to that user's connected providers and credentials.
{% endhint %}

***

## See also

{% content-ref url="/pages/uBaUeZYQpupBMd5c1BY0" %}
[Overview](/documentation/agent-frameworks/frameworks.md)
{% endcontent-ref %}

{% content-ref url="/pages/QJVxDLqxIz5KMCH5afbE" %}
[All Providers](/documentation/providers/providers.md)
{% endcontent-ref %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.allmcp.co/documentation/agent-frameworks/autogen.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
