from upsonic import Agent, Task
from upsonic.tools.mcp import MultiMCPHandler
from pydantic import BaseModel
class MultiDatabaseReport(BaseModel):
"""Structured output for multi-database operations."""
databases_used: int
total_tables: int
total_records: int
operations_summary: str
# Create multi-handler
multi_handler = MultiMCPHandler(
commands=[
"uvx mcp-server-sqlite --db-path /tmp/companies.db",
"uvx mcp-server-sqlite --db-path /tmp/employees.db",
],
timeout_seconds=60
)
# Create agent
agent = Agent(
name="Multi-MCP Structured Agent",
role="Multi-database operations with structured reporting",
goal="Demonstrate structured output with MultiMCPHandler",
tool_call_limit=10
)
# Create task with structured output
task = Task(
description="""
IMPORTANT: You have access to TWO separate SQLite databases.
- Database 1: Use tools from the first MCP server connection
- Database 2: Use tools from the second MCP server connection
Step 1: Using Database 1, create a 'companies' table with:
- id (integer primary key)
- name (text)
- industry (text)
- revenue (real)
Insert 3 tech companies into Database 1.
Step 2: Using Database 2, create an 'employees' table with:
- id (integer primary key)
- name (text)
- position (text)
- salary (real)
- company_id (integer)
Insert 5 sample employees into Database 2.
Step 3: Provide a structured report with:
- Number of databases used (should be 2)
- Total tables created (should be 2)
- Total records inserted (should be 8: 3 companies + 5 employees)
- Operations summary describing what was done
""",
tools=[multi_handler],
response_format=MultiDatabaseReport
)
# Execute
result = agent.do(task)
print(f"Databases Used: {result.databases_used}")
print(f"Total Tables: {result.total_tables}")
print(f"Total Records: {result.total_records}")
print(f"Operations Summary: {result.operations_summary}")