feat: add MCP (Model Context Protocol) support

Add comprehensive MCP integration using langchain-mcp-adapters to enable
pluggable external tools from MCP servers.

Features:
- MCP server configuration via mcp_config.json
- Automatic lazy initialization for seamless use in both FastAPI and LangGraph Studio
- Support for multiple MCP servers (filesystem, postgres, github, brave-search, etc.)
- Environment variable resolution in configuration
- Tool caching mechanism for optimal performance
- Complete documentation and setup guide

Implementation:
- Add src/mcp module with client, tools, and cache components
- Integrate MCP config loading in AppConfig
- Update tool system to include MCP tools automatically
- Add eager initialization in FastAPI lifespan handler
- Add lazy initialization fallback for LangGraph Studio

Dependencies:
- Add langchain-mcp-adapters>=0.1.0

Documentation:
- Add MCP_SETUP.md with comprehensive setup guide
- Update CLAUDE.md with MCP system architecture
- Update config.example.yaml with MCP configuration notes
- Update README.md with MCP setup instructions

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
hetaoBackend
2026-01-19 18:57:16 +08:00
parent 21f35b1d3c
commit 74d4a16492
19 changed files with 1044 additions and 5 deletions

View File

@@ -222,3 +222,25 @@ summarization:
# Custom summary prompt template (null = use default LangChain prompt)
# The prompt should guide the model to extract important context
summary_prompt: null
# ============================================================================
# MCP (Model Context Protocol) Configuration
# ============================================================================
# Configure MCP servers to provide additional tools and capabilities
# MCP configuration is loaded from a separate `mcp_config.json` file
#
# Setup:
# 1. Copy `mcp_config.example.json` to `mcp_config.json` in the project root
# 2. Enable desired MCP servers by setting `enabled: true`
# 3. Configure server commands, arguments, and environment variables
# 4. Restart the application to load MCP tools
#
# MCP servers provide tools that are automatically discovered and integrated
# with DeerFlow's agent system. Examples include:
# - File system access
# - Database connections (PostgreSQL, etc.)
# - External APIs (GitHub, Brave Search, etc.)
# - Browser automation (Puppeteer)
# - Custom MCP server implementations
#
# For more information, see: https://modelcontextprotocol.io