Even though I can talk on the playground, the MCP server doesn’t connect.
from agno.agent import Agent
from agno.models.openrouter import OpenRouter
from agno.playground import Playground, serve_playground_app
from agno.storage.sqlite import SqliteStorage
from agno.tools.mcp import MCPTools
from mcp import StdioServerParameters
from textwrap import dedent
Storage path for agent sessions
agent_storage: str = “tmp/agents.db”
Create the MCP tool using the command
parameter directly
server_params = StdioServerParameters(
command=“npx”,
args=[
“-y”,
“@bytebase/dbhub”,
“–transport”, “stdio”,
“–dsn”, “”
],
)
Instantiate the MCP tool
mcp_tools = MCPTools(server_params=server_params)
Create the agent
postgres_agent = Agent(
name=“PostgreSQL Assistant”,
model=OpenRouter(
id=“google/gemini-2.0-flash-exp:free”,
api_key=“”
),
tools=[mcp_tools],
instructions=dedent(“”"
You are an expert PostgreSQL database assistant. Help users explore and query the database.
- Respond clearly and in detail in Spanish.
- Use available tools to access the database.
- Provide relevant context about the queries you have made.
- Organize your answers with headings when appropriate.
- Be concise and focus on relevant information.
“”),
storage=SqliteStorage(table_name=“postgres_agent”, db_file=agent_storage),
add_datetime_to_instructions=True,
add_history_to_messages=True,
num_history_responses=5,
markdown=True,
show_tool_calls=True,
)
Create the app to interact with the agent
app = Playground(agents=[postgres_agent]).get_app()
Start the server
if name == “main”:
serve_playground_app(“agent_postgre:app”, reload=True)