AutoGen MCP in 2026: McpWorkbench With an Auth Header
Connect AutoGen MCP tools to a remote server: McpWorkbench with a bearer key, a tool filter, the mcp pin a fresh install needs, a real 401 and X output.
Tarun Khatri
Published · Updated · 6 min read
AutoGen MCP support lives in autogen-ext: wrap a server in McpWorkbench with StreamableHttpServerParams, then pass it to an AssistantAgent.
This guide connects AutoGen 0.7.5 to Weir's remote MCP server for public X (Twitter) data, with an API key. It covers AutoGen's archived status, the pin a fresh install now needs, and a real call. We run Weir.
import os
from autogen_ext.tools.mcp import McpWorkbench, StreamableHttpServerParams
weir = StreamableHttpServerParams(
url="https://api.weirapp.io/mcp",
headers={"Authorization": f"Bearer {os.environ['WEIR_API_KEY']}"},
timeout=60,
)
async def tool_names() -> list[str]:
async with McpWorkbench(weir) as workbench:
return [tool["name"] for tool in await workbench.list_tools()]
How to connect an AutoGen MCP client to a remote server
You need AutoGen's two packages, a Weir key and a model key.
- Installpip install autogen-agentchat "autogen-ext[mcp,openai]" "mcp<2" on Python 3.10 or later.
- Get a Weir keyCreate one under API keys in your Weir dashboard. Keep it in WEIR_API_KEY.
- Set a model keyOpenAIChatCompletionClient reads OPENAI_API_KEY.
- Run the agentOpen the workbench with async with and hand it to an AssistantAgent.
As of 24 October 2026, PyPI's newest AutoGen is 0.7.5, from 30 September 2025. Its README said "maintenance mode" from April 2026.
Since 16 October, it says "archived and no longer maintained", with no bug or security fixes.
Why the pin? autogen-ext[mcp] asks for mcp>=1.11.0 with no upper limit. The 2.x mcp SDK dropped names AutoGen imports, so a fresh install gave us this:
ImportError: cannot import name 'RequestContext' from 'mcp.shared.context'
With "mcp<2", pip picked mcp 1.30.0 and the import worked.
AutoGen MCP example: McpWorkbench and an AssistantAgent
A default Weir key lists more than 40 tools, Reddit included. McpWorkbench 0.7.5 can rename tools but not drop them, so this subclass keeps two:
class XOnly(McpWorkbench):
async def list_tools(self):
tools = await super().list_tools()
return [t for t in tools if t["name"] in ("search_x", "get_x_post")]
Then open it and give it to the agent. weir is the params object from the top of this page:
import asyncio
from autogen_agentchat.agents import AssistantAgent
from autogen_ext.models.openai import OpenAIChatCompletionClient
async def main(task: str) -> None:
async with XOnly(weir) as workbench:
agent = AssistantAgent(
"x_analyst", model_client=OpenAIChatCompletionClient(model="gpt-5-mini"),
workbench=workbench, reflect_on_tool_use=True,
system_message="Search X with limit 5 or less. Link every post you cite.")
result = await agent.run(task=task)
print(result.messages[-1].content)
asyncio.run(main("What has @msdev posted about MCP lately?"))
Here's what the 0.7.5 source does with it:
- One session for the whole block. The workbench holds one MCP connection and closes it when
async withends. - The tool list loads on each model call. Listing is free on Weir, so the filter costs nothing.
reflect_on_tool_use=Truematters. Without it, the agent's answer is the raw tool result.- A failed call doesn't end the run. The model gets an error result, a
402included.
Without async with, call await workbench.start() and await workbench.stop() yourself.
What does the agent get back?
To answer, the model calls search_x. We made that call through Weir's MCP server on 24 October 2026:
→ search_x {"fromUsers": ["pyautogen", "msdev"], "query": "MCP -filter:nativeretweets",
"onlyOriginal": true, "limit": 3}
← 3 posts · 4 credits · nextCursor set
2026-09-09 34 likes @msdev "Welcome to MCP Live!"
2026-08-20 62 likes @msdev "Join us September 9 for MCP Live!"
2026-08-17 99 likes @msdev "Claude in Microsoft Foundry now supports ... MCP connector"
None of @pyautogen's posts made the three newest matches. The workbench hands the model both text blocks Weir sends: the JSON, then a line like "Charged 4 credits; 588 credits left."
Each post carries its url, so the agent can link what it cites.
Weir bills 1 credit per call plus 1 per X post, and failed calls are free. Packs start at $5 for 25,000 credits, as of October 2026. See our pricing page.
AutoGen MCP workbench or mcp_server_tools?
autogen_ext.tools.mcp gives you two routes. Pick the workbench unless you need plain tool objects:
| McpWorkbench | mcp_server_tools | |
|---|---|---|
| Give it to the agent | workbench= |
tools= |
| Connection | One, held open | A new one per call |
| Drop tools | Subclass list_tools |
Filter the list |
| Clean up | async with |
Nothing to close |
With mcp_server_tools(weir), filter the returned list by t.name and pass it as tools=. Each call then opens its own session, which is fine for Weir's stateless server.
Moving to Microsoft Agent Framework
Agent Framework's MCP tool sends headers and filters tools itself. PyPI lists agent-framework 1.23.0, released on 22 October 2026:
import os
from agent_framework import Agent, MCPStreamableHTTPTool
from agent_framework.openai import OpenAIChatClient
weir_tool = MCPStreamableHTTPTool(
name="weir", url="https://api.weirapp.io/mcp",
static_headers={"Authorization": f"Bearer {os.environ['WEIR_API_KEY']}"},
allowed_tools=["search_x", "get_x_post"],
)
async def ask(question: str) -> None:
async with Agent(client=OpenAIChatClient(model="gpt-5-mini"), name="x_analyst",
instructions="Search X with limit 5 or less.", tools=weir_tool) as agent:
print((await agent.run(question)).text)
Install it with pip install agent-framework, in its own environment. It needs mcp 2.x, which AutoGen can't import. We ran the tool part against our stub: it sent the header and kept the two X tools.
If it doesn't work
This is what the workbench raised when we connected with no key:
ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
httpx.HTTPStatusError: Client error '401 Unauthorized' for url 'https://api.weirapp.io/mcp'
It shows up at the first list_tools() or agent run, not when async with opens. Check the key with Weir's free GET /v1/whoami. Other errors:
cannot import name 'RequestContext'. Install"mcp<2"next to AutoGen.- "Tools cannot be used with a workbench". Pass
tools=orworkbench=, not both. - The agent replies with raw JSON. Set
reflect_on_tool_use=True. - "Failed to create MCP session" in Agent Framework. It hides the status code. A missing or wrong key is the usual cause.
- A tool returns
402. Your Weir credits ran out, and retrying won't help.
When not to use Weir
- Your agent has to post or DM on X. Weir is read-only.
- You want private data. Weir reads public posts, not bookmarks, DMs or home timelines.
- Price per post matters most. TwitterAPI.io lists $0.15 per 1,000 tweets as of October 2026, less than our $5 pack.
- You need a guarantee. Weir isn't licensed by X or affiliated with it, so access can change.
FAQ
Is AutoGen still maintained?
No. Since 16 October 2026, its README says AutoGen is archived and gets no bug fixes, security fixes or new features. The last release, 0.7.5, shipped on 30 September 2025. Microsoft points users to Agent Framework and a migration guide.
Can AutoGen be an MCP server?
Not on its own. AutoGen 0.7.5's MCP module is a client only. Agent Framework can do it: Microsoft's docs show agent.as_mcp_server(), which wraps an agent as an MCP server.
Is AG2 the same as AutoGen?
No. AG2 calls itself "formerly AutoGen" on GitHub, but it's a separate project with its own MCP client. There, you pass MCPToolkit(MCPServerConfig(server_url=..., authorization_token=...)) in the agent's tools.
How do I pass headers to an MCP server in AutoGen?
Put them in headers on StreamableHttpServerParams, as above, and AutoGen sends them on every request. SseServerParams takes headers too, but Weir doesn't serve SSE.
Sources
All checked on 24 October 2026.
- AutoGen README, archived notice (commit 004749e, 16 October 2026): https://github.com/microsoft/autogen
- AutoGen python-v0.7.5 source, MCP module and
AssistantAgent: https://github.com/microsoft/autogen/tree/python-v0.7.5/python/packages - autogen-ext on PyPI, version 0.7.5: https://pypi.org/project/autogen-ext/
- MCP Python SDK v2.3.0 migration guide: https://github.com/modelcontextprotocol/python-sdk/blob/v2.3.0/docs/migration.md
- Microsoft Learn, Agent Framework MCP tools (updated 28 September 2026): https://learn.microsoft.com/en-us/agent-framework/agents/tools/local-mcp-tools
- agent-framework on PyPI, version 1.23.0: https://pypi.org/project/agent-framework/
- AG2 README and MCP toolkit (v1.2.1): https://github.com/ag2ai/ag2
- TwitterAPI.io pricing: https://twitterapi.io/pricing
- Weir docs, MCP: https://docs.weirapp.io/mcp
- Weir billing: https://docs.weirapp.io/billing
- Weir search_x call (request 594deb40-10ae-48af-82af-091ea97cb502) and no-key request (request 1cce84e3-15e7-42cb-8d2c-6de9fb3bd5f3)