Skip to main content

What is Model Context Protocol (MCP)?

The Model Context Protocol (MCP) is an open protocol that enables seamless integration between LLM applications and external data sources and tools. It provides a standardized way for AI agents to communicate with external servers and access their capabilities.

How MCP Works

MCP creates a bridge between your AI agents and external tool servers:
  1. Server Registration: You configure an MCP server by specifying its connection details
  2. Tool Discovery: The framework automatically discovers available tools from the server
  3. Tool Execution: When your agent needs a tool, the framework handles communication with the MCP server
  4. Result Handling: Results are returned to your agent in a standardized format

Key Benefits

  • Extensive Ecosystem: Access thousands of community-developed and official tools
  • No Custom Development: Use pre-built tools without writing integration code
  • Standardized Protocol: Consistent interface across different tool providers
  • Live Updates: Servers can update tools without changing your code

Three Ways to Use MCP

1. Class-Based

from upsonic import Agent, Task

class DatabaseMCP:
    command = "uvx"
    args = ["mcp-server-sqlite", "--db-path", "/tmp/test_mcp_v7.db"]

agent = Agent(
    name="Legacy MCP Agent",
    role="Database operations specialist using legacy MCP class",
    goal="Demonstrate backward compatibility with class-based MCP",
    tool_call_limit=10
)

task = Task(
    description="""
    Create a 'products' table with columns: 
    - id (integer primary key)
    - name (text)
    - price (real)
    - category (text)
    - stock (integer)
    
    Insert 5 sample products with different categories (electronics, books, clothing).
    Then query and show all products sorted by price.
    """,
    tools=[DatabaseMCP]
)

result = agent.do(task)
print(result)

2. MCPHandler Class

from upsonic import Agent, Task
from upsonic.tools.mcp import MCPHandler

mcp_handler = MCPHandler(
    command="uvx mcp-server-sqlite --db-path /tmp/db.db",
    timeout_seconds=60
)

agent = Agent(model="openai/gpt-4o")
task = Task(
    description="Query the database to list all tables and their schema information to understand the database structure.",
    tools=[mcp_handler]
)
result = agent.do(task)
print(result)

3. MultiMCPHandler Class (Multiple Servers)

from upsonic import Agent, Task
from upsonic.tools.mcp import MultiMCPHandler

multi_handler = MultiMCPHandler(
    commands=[
        "uvx mcp-server-sqlite --db-path /tmp/db1.db",
        "uvx mcp-server-sqlite --db-path /tmp/db2.db",
    ],
    tool_name_prefixes=["users_db", "products_db"],  # Prevent tool name collisions
    timeout_seconds=60
)

agent = Agent(model="openai/gpt-4o")
task = Task(
    description="""
    Connect to both databases using prefixed tools:
    - Use 'users_db_*' tools to query the users database
    - Use 'products_db_*' tools to query the products database
    Cross-reference the data between both databases.
    """,
    tools=[multi_handler]
)
result = agent.do(task)
print(result)
Use tool_name_prefix or tool_name_prefixes when connecting to multiple servers that expose tools with the same names. This prevents collisions and makes it clear which server’s tools to use.

MCP Server Resources

Discover available MCP servers: