The BotForge RAG project has been successfully refactored to support professional-grade MCP (Model Context Protocol) integration. The project now includes:
-
Professional Project Structure
- Reorganized into enterprise-grade folder structure
- Proper separation of tests, scripts, configs, and documentation
- Added Makefile for developer workflows
-
MCP Protocol Integration
- Implemented proper MCP client using official Python SDK
- Created Claude/GitHub Copilot-style MCP agent service
- Dynamic server URL fetching from database
- LLM-driven tool parameter handling (no hardcoded schemas)
-
HTTP Client Improvements
- Fixed Accept headers for proper content negotiation
- Added streaming (SSE) and regular JSON response support
- Enhanced error handling and logging
-
Developer Experience
- Installation scripts for MCP dependencies
- Test scripts for MCP integration
- Comprehensive documentation and examples
src/botforge/services/mcp_agent_service.py- Original service (refactored)src/botforge/services/mcp_agent_service_new.py- New Claude-style implementationsrc/botforge/services/external_mcp_manager.py- HTTP client with streaming support
scripts/dev/install_mcp_client.sh- Install MCP dependenciesscripts/dev/test_mcp_tools.py- Test MCP integrationscripts/dev/setup_dev_env.sh- Complete development setup
pyproject.toml- Updated with MCP client dependencyuv.lock- Dependency lock file
-
Original Service (
mcp_agent_service.py)- ✅ Refactored for dynamic server URLs
- ✅ Removed hardcoded tool parameters
- ✅ LLM-driven tool discovery and execution
- ✅ HTTP-based MCP communication
-
New Service (
mcp_agent_service_new.py)- ✅ Official MCP Python client integration
- ✅ Claude/GitHub Copilot style implementation
- ✅ Proper MCP protocol support
- ✅ Async session management
# Install MCP client libraries
./scripts/dev/install_mcp_client.sh
# Or manually with uv
uv add mcp
# Or with pip
pip install mcp# Make script executable
chmod +x scripts/dev/test_mcp_tools.py
# Run tests (requires MCP server running)
./scripts/dev/test_mcp_tools.pyOption A: Use Refactored Original Service
from botforge.services.mcp_agent_service import MCPAgentService
service = MCPAgentService()
response = await service.query_with_mcp_agent("bot-id", "your query")Option B: Use New Claude-Style Service
from botforge.services.mcp_agent_service_new import MCPAgentService
async with MCPAgentService() as service:
response = await service.query_with_mcp_agent("bot-id", "your query")- For existing applications: Use the refactored original service for minimal changes
- For new features: Use the new Claude-style service for better protocol compliance
- For production: Gradually migrate to the new service after thorough testing
- MCP server running (e.g., on localhost:3001)
- MCP client libraries installed
- Bot configurations in database with MCP tool registrations
# Basic MCP client test
python scripts/dev/test_mcp_tools.py
# Integration tests (once implemented)
make test-mcp
# Full test suite
make testThe system now automatically discovers tools from MCP servers without hardcoded schemas:
# Tools are discovered at runtime
tools = await session.list_tools()
for tool in tools:
# Tool schemas are fetched from MCP server
# LLM handles parameter formatting automaticallyThe new implementation follows MCP protocol specifications:
- Correct message formatting
- Proper session management
- Standard tool invocation patterns
- Error handling per MCP spec
The API follows the same patterns as Anthropic Claude:
async with MCPAgentService() as mcp_service:
# Context manager handles session lifecycle
result = await mcp_service.query_with_mcp_agent(
bot_id="my-bot",
query="Use the weather tool to check temperature in Paris"
)-
Import Errors for MCP Client
- Solution: Run
./scripts/dev/install_mcp_client.sh
- Solution: Run
-
MCP Server Connection Failed
- Check server URL in database
- Verify MCP server is running
- Check network connectivity
-
Tool Not Found
- Verify tool is registered for the bot
- Check MCP server has the tool available
- Review bot configuration in database
Enable detailed logging:
import logging
logging.getLogger('botforge.services.mcp_agent_service').setLevel(logging.DEBUG)- Add MCP tool caching for better performance
- Implement tool usage analytics
- Add MCP server health monitoring
- Create MCP tool discovery UI
- Add CI/CD integration for MCP testing
For questions or issues:
- Check this documentation
- Review test scripts in
scripts/dev/ - Check logs with DEBUG level enabled
- Refer to MCP protocol documentation