Skip to content

Commit 2f7bbde

Browse files
anuragtsdirkbrnd
andauthored
MCP playground (#224)
Co-authored-by: Dirk Brand <[email protected]>
1 parent 494b620 commit 2f7bbde

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

tools/mcp.mdx

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,68 @@ if __name__ == "__main__":
168168
asyncio.run(run_agent("What is the license for this project?"))
169169
```
170170

171+
## Running MCP in Playground
172+
173+
You can also run MCP servers in the Agno Playground, which provides a web interface for interacting with your agents. Here's an example of a GitHub agent running in the Playground:
174+
175+
```python github_playground.py
176+
import asyncio
177+
from os import getenv
178+
from textwrap import dedent
179+
180+
import nest_asyncio
181+
from agno.agent import Agent
182+
from agno.models.openai import OpenAIChat
183+
from agno.playground import Playground, serve_playground_app
184+
from agno.storage.agent.sqlite import SqliteAgentStorage
185+
from agno.tools.mcp import MCPTools
186+
187+
# Allow nested event loops
188+
nest_asyncio.apply()
189+
190+
agent_storage_file: str = "tmp/agents.db"
191+
192+
193+
async def run_server() -> None:
194+
"""Run the GitHub agent server."""
195+
github_token = getenv("GITHUB_TOKEN") or getenv("GITHUB_ACCESS_TOKEN")
196+
if not github_token:
197+
raise ValueError("GITHUB_TOKEN environment variable is required")
198+
199+
# Create a client session to connect to the MCP server
200+
async with MCPTools("npx -y @modelcontextprotocol/server-github") as mcp_tools:
201+
agent = Agent(
202+
name="MCP GitHub Agent",
203+
tools=[mcp_tools],
204+
instructions=dedent("""\
205+
You are a GitHub assistant. Help users explore repositories and their activity.
206+
207+
- Use headings to organize your responses
208+
- Be concise and focus on relevant information\
209+
"""),
210+
model=OpenAIChat(id="gpt-4o"),
211+
storage=SqliteAgentStorage(
212+
table_name="basic_agent",
213+
db_file=agent_storage_file,
214+
auto_upgrade_schema=True,
215+
),
216+
add_history_to_messages=True,
217+
num_history_responses=3,
218+
add_datetime_to_instructions=True,
219+
markdown=True,
220+
)
221+
222+
playground = Playground(agents=[agent])
223+
app = playground.get_app()
224+
225+
# Serve the app while keeping the MCPTools context manager alive
226+
serve_playground_app(app)
227+
228+
229+
if __name__ == "__main__":
230+
asyncio.run(run_server())
231+
```
232+
171233

172234
## Best Practices
173235

@@ -191,7 +253,7 @@ You are a filesystem assistant. Help users explore files and directories.
191253
"""
192254
```
193255

194-
## Understanding server Parameters
256+
## Understanding Server Parameters
195257

196258
The recommended way to configure `MCPTools` or `MultiMCPTools` is to use the `command` parameter.
197259

0 commit comments

Comments
 (0)