Skip to main content

Overview

Any Upsonic Agent can be exposed as an MCP (Model Context Protocol) server using as_mcp(). This lets other agents, tools, or MCP-compatible clients consume your agent over stdio, SSE, or Streamable HTTP.

Creating an MCP Server from an Agent

Run this script and it starts an MCP server over stdio, exposing a do tool that accepts a task string and returns the agent’s response.

Using an Agent MCP Server from Another Agent

The MCPHandler spawns the server as a subprocess, discovers the do tool, and makes it available to the orchestrator agent.

Multiple Agent Servers as Tools

Use tool_name_prefix to avoid name collisions when combining multiple agent servers:

Customizing the Server

as_mcp() returns a standard FastMCP server object. You can add extra tools before running:

How It Works

  1. as_mcp() creates a FastMCP server named after the agent.
  2. It registers a do tool whose description includes the agent’s role, goal, and instructions.
  3. When a client calls do(task="..."), the agent runs its full workflow internally (reasoning, tool use, memory) and returns the result as text.
  4. .run() starts the server and blocks, waiting for client connections.
For more information on MCP tools, see MCPHandler.