Add MCP Server • AI Agent SDK

add_mcp_server: Attach an MCP server to a live agent at runtime.

add_mcp_server

Method

</div>

This is a method of the Agent class in the agent module.

Attach an MCP server to a live agent at runtime.

Connects the MCP server (discovering its tools), tracks it by name, and appends it to `self.tools` so its tools become available on the next turn of the same run — no agent rebuild required. New MCP tools flow through the existing tool-execution and approval paths automatically.

Signature

python
def add_mcp_server(name: str, mcp: Any) -> Any

Parameters

ParamField str

Unique name for this MCP server (used by `remove_mcp_server`).

ParamField Any

An `MCP instance (e.g. MCP("npx -y @notionhq/notion-mcp-server")`).

Returns

ResponseField Any

The attached `MCP` instance.

Usage

python
from praisonaiagents.mcp import MCP
    agent.add_mcp_server("notion", MCP("npx -y @notionhq/notion-mcp-server"))
    # tools live on the next turn

Uses

  • ValueError
  • refresh_tools
  • logging.debug

Source

View on GitHub

praisonaiagents/agent/agent.py at line 6061


Related Documentation