Add MCP Server • AI Agent SDK
add_mcp_server: Attach an MCP server to a live agent at runtime.
add_mcp_server
Method
</div>
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
def add_mcp_server(name: str, mcp: Any) -> AnyParameters
ParamField
strUnique name for this MCP server (used by `remove_mcp_server`).
ParamField
AnyAn `MCP instance (e.g. MCP("npx -y @notionhq/notion-mcp-server")`).
Returns
ResponseField
AnyThe attached `MCP` instance.
Usage
from praisonaiagents.mcp import MCP
agent.add_mcp_server("notion", MCP("npx -y @notionhq/notion-mcp-server"))
# tools live on the next turnUses
ValueErrorrefresh_toolslogging.debug
Source
View on GitHubpraisonaiagents/agent/agent.py at line 6061