You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tools/mcp.mdx
+63-1Lines changed: 63 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -168,6 +168,68 @@ if __name__ == "__main__":
168
168
asyncio.run(run_agent("What is the license for this project?"))
169
169
```
170
170
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
+
asyncdefrun_server() -> None:
194
+
"""Run the GitHub agent server."""
195
+
github_token = getenv("GITHUB_TOKEN") or getenv("GITHUB_ACCESS_TOKEN")
196
+
ifnot github_token:
197
+
raiseValueError("GITHUB_TOKEN environment variable is required")
198
+
199
+
# Create a client session to connect to the MCP server
200
+
asyncwith 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
+
171
233
172
234
## Best Practices
173
235
@@ -191,7 +253,7 @@ You are a filesystem assistant. Help users explore files and directories.
191
253
"""
192
254
```
193
255
194
-
## Understanding server Parameters
256
+
## Understanding Server Parameters
195
257
196
258
The recommended way to configure `MCPTools` or `MultiMCPTools` is to use the `command` parameter.
0 commit comments