MCP (Model Context Protocol) servers are external tools that agents integrate through a lifecycle contract: servers must be connected before agent initialization and cleaned up after use, with optional name-scoping to prevent tool collisions across multiple servers. Error handling for MCP tools can be tuned per-agent: explicitly setting MCPConfig.failure_error_function to None raises errors as exceptions, while omitting it uses the framework's default to surface errors as model-visible messages.
The AgentBase.mcp_servers lifecycle must be managed by the caller: server.connect() must be called before passing the server to the agent, and server.cleanup() must be called when the server is no longer needed — see MCPServerManager for a helper that keeps connect/cleanup in the same task.[1]
When MCPConfig.include_server_in_tool_names is True, AgentBase.get_mcp_tools computes a set of reserved tool names — from FunctionTool names and enabled handoff tool names — and passes it to MCPUtil.get_all_function_tools to avoid name collisions across MCP servers.[1]
When MCPConfig.failure_error_function is explicitly set to None, MCP tool errors are raised as exceptions rather than being converted to model-visible error messages; if the key is absent, default_tool_error_function is used instead.[1]
Sources