MCP (Model Context Protocol) tools loader for deepagents CLI.
This module provides async functions to load and manage MCP servers using
langchain-mcp-adapters, supporting Claude Desktop style JSON configs.
It also supports automatic discovery of .mcp.json files from user-level
and project-level locations.
Load and validate MCP configuration from JSON file.
Supports multiple server types:
command, args, env fields (default)type: "sse", url, and optional headerstype: "http", url, and optional headersFind MCP config files from standard locations.
Checks three paths in precedence order (lowest to highest):
~/.deepagents/.mcp.json (user-level global)<project-root>/.deepagents/.mcp.json (project subdir)<project-root>/.mcp.json (project root, Claude Code compat)Project root is determined by find_project_root(), falling back to CWD.
Split discovered config paths into user-level and project-level.
User-level configs live under ~/.deepagents/. Everything else is
considered project-level.
Extract stdio server entries from a parsed MCP config.
Merge multiple MCP config dicts by server name.
Later entries override earlier ones for the same server name
(simple dict.update on mcpServers).
Load an MCP config file, returning None on any error.
Wraps load_mcp_config with lenient error handling suitable for
auto-discovery. Missing files are skipped silently; parse and validation
errors are logged as warnings.
Load MCP tools from configuration file with stateful sessions.
Supports multiple server types:
For stdio servers, this creates persistent sessions that remain active
across tool calls, avoiding server restarts. Sessions are managed by
MCPSessionManager and should be cleaned up with
session_manager.cleanup() when done.
Resolve MCP config and load tools.
Auto-discovers configs from standard locations and merges them.
When explicit_config_path is provided it is added as the
highest-precedence source (errors in that file are fatal).
Metadata for a single MCP tool.
Metadata for a connected MCP server and its tools.
Manages persistent MCP sessions for stateful stdio servers.
This manager creates and maintains persistent sessions for stdio MCP servers, preventing server restarts on every tool call. Sessions are kept alive until explicitly cleaned up.