langgraph_agent_toolkit.core.mcp module
Configure MCP tools without importing the optional client at module load.
- class langgraph_agent_toolkit.core.mcp.MCPServerConfig(*, transport='http', url=None, command=None, args=<factory>, headers=<factory>, headers_env=<factory>, env=<factory>, env_env=<factory>, mode='auto', timeout=30.0, tool_allowlist=None)[source][source]
Bases:
BaseModelDescribe one operator-configured MCP server and its credentials.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
transport (Literal['http', 'stdio'])
url (str | None)
command (str | None)
args (list[str])
headers (dict[str, SecretStr])
headers_env (dict[str, str])
env (dict[str, SecretStr])
env_env (dict[str, str])
mode (Literal['auto', 'legacy'])
timeout (Annotated[float, Gt(gt=0), _PydanticGeneralMetadata(allow_inf_nan=False)])
tool_allowlist (list[str] | None)
- model_config = {'extra': 'forbid', 'hide_input_in_errors': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- transport: Literal['http', 'stdio']
- url: str | None
- command: str | None
- args: list[str]
- headers: dict[str, SecretStr]
- headers_env: dict[str, str]
- env: dict[str, SecretStr]
- env_env: dict[str, str]
- mode: Literal['auto', 'legacy']
- timeout: float
- tool_allowlist: list[str] | None
- langgraph_agent_toolkit.core.mcp.merge_tools(local_tools, extra_tools)[source][source]
Reject duplicate names before a graph can replace a tool silently.
- Parameters:
local_tools (Sequence[BaseTool])
extra_tools (Sequence[BaseTool])
- Return type:
list[BaseTool]
- async langgraph_agent_toolkit.core.mcp.load_mcp_tools(servers, *, discovery_timeout=30.0)[source][source]
Discover namespaced tools. Each tool opens and closes its own connection context.
The SDK can share a connection between overlapping calls. No connection stays open after the last call exits. Restart the worker to refresh tool schemas.
- Parameters:
servers (dict[str, MCPServerConfig])
discovery_timeout (float)
- Return type:
dict[str, list[BaseTool]]
- async langgraph_agent_toolkit.core.mcp.configure_mcp_agents(executor, settings, *, rebuild_all=False)[source][source]
Build MCP graphs and optionally refresh all graphs for a new service lifespan.
- Parameters:
executor (AgentExecutor)
settings (Settings)
rebuild_all (bool)
- Return type:
None