Skip to content

Commit 63c791d

Browse files
authored
Add more mcp workbench examples to MCP API doc (#6403)
1 parent 4eb256d commit 63c791d

1 file changed

Lines changed: 82 additions & 1 deletion

File tree

  • python/packages/autogen-ext/src/autogen_ext/tools/mcp

python/packages/autogen-ext/src/autogen_ext/tools/mcp/_workbench.py

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class McpWorkbench(Workbench, Component[McpWorkbenchConfig]):
3636
server_params (McpServerParams): The parameters to connect to the MCP server.
3737
This can be either a :class:`StdioServerParams` or :class:`SseServerParams`.
3838
39-
Example:
39+
Examples:
40+
41+
Here is a simple example of how to use the workbench with a `mcp-server-fetch` server:
4042
4143
.. code-block:: python
4244
@@ -62,6 +64,85 @@ async def main() -> None:
6264
6365
asyncio.run(main())
6466
67+
Example of using the workbench with the `GitHub MCP Server <https://github.com/github/github-mcp-server>`_:
68+
69+
.. code-block:: python
70+
71+
import asyncio
72+
from autogen_agentchat.agents import AssistantAgent
73+
from autogen_agentchat.ui import Console
74+
from autogen_ext.models.openai import OpenAIChatCompletionClient
75+
from autogen_ext.tools.mcp import McpWorkbench, StdioServerParams
76+
77+
78+
async def main() -> None:
79+
model_client = OpenAIChatCompletionClient(model="gpt-4.1-nano")
80+
server_params = StdioServerParams(
81+
command="docker",
82+
args=[
83+
"run",
84+
"-i",
85+
"--rm",
86+
"-e",
87+
"GITHUB_PERSONAL_ACCESS_TOKEN",
88+
"ghcr.io/github/github-mcp-server",
89+
],
90+
env={
91+
"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
92+
},
93+
)
94+
async with McpWorkbench(server_params) as mcp:
95+
agent = AssistantAgent(
96+
"github_assistant",
97+
model_client=model_client,
98+
workbench=mcp,
99+
reflect_on_tool_use=True,
100+
model_client_stream=True,
101+
)
102+
await Console(agent.run_stream(task="Is there a repository named Autogen"))
103+
104+
105+
asyncio.run(main())
106+
107+
Example of using the workbench with the `Playwright MCP Server <https://github.com/microsoft/playwright-mcp>`_:
108+
109+
.. code-block:: python
110+
111+
# First run `npm install -g @playwright/mcp@latest` to install the MCP server.
112+
import asyncio
113+
from autogen_agentchat.agents import AssistantAgent
114+
from autogen_agentchat.teams import RoundRobinGroupChat
115+
from autogen_agentchat.conditions import TextMessageTermination
116+
from autogen_agentchat.ui import Console
117+
from autogen_ext.models.openai import OpenAIChatCompletionClient
118+
from autogen_ext.tools.mcp import McpWorkbench, StdioServerParams
119+
120+
121+
async def main() -> None:
122+
model_client = OpenAIChatCompletionClient(model="gpt-4.1-nano")
123+
server_params = StdioServerParams(
124+
command="npx",
125+
args=[
126+
"@playwright/mcp@latest",
127+
"--headless",
128+
],
129+
)
130+
async with McpWorkbench(server_params) as mcp:
131+
agent = AssistantAgent(
132+
"web_browsing_assistant",
133+
model_client=model_client,
134+
workbench=mcp,
135+
model_client_stream=True,
136+
)
137+
team = RoundRobinGroupChat(
138+
[agent],
139+
termination_condition=TextMessageTermination(source="web_browsing_assistant"),
140+
)
141+
await Console(team.run_stream(task="Find out how many contributors for the microsoft/autogen repository"))
142+
143+
144+
asyncio.run(main())
145+
65146
"""
66147

67148
component_provider_override = "autogen_ext.tools.mcp.McpWorkbench"

0 commit comments

Comments
 (0)