Skip to content

Latest commit

 

History

History
212 lines (149 loc) · 5.47 KB

File metadata and controls

212 lines (149 loc) · 5.47 KB

MCP Integration Status and Migration Guide

Current State

The BotForge RAG project has been successfully refactored to support professional-grade MCP (Model Context Protocol) integration. The project now includes:

✅ Completed Features

  1. Professional Project Structure

    • Reorganized into enterprise-grade folder structure
    • Proper separation of tests, scripts, configs, and documentation
    • Added Makefile for developer workflows
  2. 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)
  3. HTTP Client Improvements

    • Fixed Accept headers for proper content negotiation
    • Added streaming (SSE) and regular JSON response support
    • Enhanced error handling and logging
  4. Developer Experience

    • Installation scripts for MCP dependencies
    • Test scripts for MCP integration
    • Comprehensive documentation and examples

File Structure

Core MCP Services

  • src/botforge/services/mcp_agent_service.py - Original service (refactored)
  • src/botforge/services/mcp_agent_service_new.py - New Claude-style implementation
  • src/botforge/services/external_mcp_manager.py - HTTP client with streaming support

Developer Scripts

  • scripts/dev/install_mcp_client.sh - Install MCP dependencies
  • scripts/dev/test_mcp_tools.py - Test MCP integration
  • scripts/dev/setup_dev_env.sh - Complete development setup

Dependencies

  • pyproject.toml - Updated with MCP client dependency
  • uv.lock - Dependency lock file

Migration Status

Current Implementation Options

  1. 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
  2. New Service (mcp_agent_service_new.py)

    • ✅ Official MCP Python client integration
    • ✅ Claude/GitHub Copilot style implementation
    • ✅ Proper MCP protocol support
    • ✅ Async session management

Next Steps for Developers

1. Install MCP Dependencies

# Install MCP client libraries
./scripts/dev/install_mcp_client.sh

# Or manually with uv
uv add mcp

# Or with pip
pip install mcp

2. Test MCP Integration

# Make script executable
chmod +x scripts/dev/test_mcp_tools.py

# Run tests (requires MCP server running)
./scripts/dev/test_mcp_tools.py

3. Choose Implementation

Option 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")

4. Migration Recommendations

  1. For existing applications: Use the refactored original service for minimal changes
  2. For new features: Use the new Claude-style service for better protocol compliance
  3. For production: Gradually migrate to the new service after thorough testing

Testing

Prerequisites

  1. MCP server running (e.g., on localhost:3001)
  2. MCP client libraries installed
  3. Bot configurations in database with MCP tool registrations

Test Commands

# Basic MCP client test
python scripts/dev/test_mcp_tools.py

# Integration tests (once implemented)
make test-mcp

# Full test suite
make test

Key Features

Dynamic Tool Discovery

The 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 automatically

Proper MCP Protocol

The new implementation follows MCP protocol specifications:

  • Correct message formatting
  • Proper session management
  • Standard tool invocation patterns
  • Error handling per MCP spec

Claude-Style Usage

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"
    )

Troubleshooting

Common Issues

  1. Import Errors for MCP Client

    • Solution: Run ./scripts/dev/install_mcp_client.sh
  2. MCP Server Connection Failed

    • Check server URL in database
    • Verify MCP server is running
    • Check network connectivity
  3. Tool Not Found

    • Verify tool is registered for the bot
    • Check MCP server has the tool available
    • Review bot configuration in database

Debug Mode

Enable detailed logging:

import logging
logging.getLogger('botforge.services.mcp_agent_service').setLevel(logging.DEBUG)

Future Enhancements

  • 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

Support

For questions or issues:

  1. Check this documentation
  2. Review test scripts in scripts/dev/
  3. Check logs with DEBUG level enabled
  4. Refer to MCP protocol documentation