Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,28 @@ RERANKER_TOP_K=5
# Larger batches = fewer LLM calls but higher memory usage
RERANKER_BATCH_SIZE=10

# ================================
# MCP GATEWAY INTEGRATION
# ================================
# MCP Context Forge Gateway URL (set to enable MCP tool features)
MCP_GATEWAY_URL=http://localhost:8080
# API key for MCP Gateway (optional, depends on gateway configuration)
MCP_GATEWAY_API_KEY=
# Enable MCP Gateway integration (set to true to enable)
MCP_ENABLED=false
# Default timeout for tool invocations (seconds)
MCP_GATEWAY_TIMEOUT=30.0
# Health check timeout (seconds)
MCP_GATEWAY_HEALTH_TIMEOUT=5.0
# Maximum concurrent tool invocations
MCP_MAX_CONCURRENT_TOOLS=3
# Overall enrichment timeout (seconds)
MCP_ENRICHMENT_TIMEOUT=60.0
# Circuit breaker: failures before opening
MCP_CIRCUIT_BREAKER_THRESHOLD=5
# Circuit breaker: recovery timeout (seconds)
MCP_CIRCUIT_BREAKER_RECOVERY=60.0

# ================================
# CONTAINER IMAGES (Optional)
# ================================
Expand Down
20 changes: 20 additions & 0 deletions backend/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,26 @@ class Settings(BaseSettings):
cot_reasoning_strategy: Annotated[str, Field(default="decomposition", alias="COT_REASONING_STRATEGY")]
cot_token_budget_multiplier: Annotated[float, Field(default=2.0, alias="COT_TOKEN_BUDGET_MULTIPLIER")]

# MCP Gateway Integration settings
# URL of the MCP Context Forge Gateway (set to empty to disable MCP features)
mcp_gateway_url: Annotated[str, Field(default="http://localhost:8080", alias="MCP_GATEWAY_URL")]
# API key for MCP Gateway authentication (optional, depends on gateway configuration)
mcp_gateway_api_key: Annotated[str | None, Field(default=None, alias="MCP_GATEWAY_API_KEY")]
# Default timeout for MCP tool invocations (seconds)
mcp_gateway_timeout: Annotated[float, Field(default=30.0, alias="MCP_GATEWAY_TIMEOUT")]
# Timeout for MCP Gateway health checks (seconds)
mcp_gateway_health_timeout: Annotated[float, Field(default=5.0, alias="MCP_GATEWAY_HEALTH_TIMEOUT")]
# Enable/disable MCP Gateway integration
mcp_enabled: Annotated[bool, Field(default=False, alias="MCP_ENABLED")]
# Maximum concurrent tool invocations during enrichment
mcp_max_concurrent_tools: Annotated[int, Field(default=3, alias="MCP_MAX_CONCURRENT_TOOLS")]
# Overall timeout for enrichment process (seconds)
mcp_enrichment_timeout: Annotated[float, Field(default=60.0, alias="MCP_ENRICHMENT_TIMEOUT")]
# Circuit breaker failure threshold
mcp_circuit_breaker_threshold: Annotated[int, Field(default=5, alias="MCP_CIRCUIT_BREAKER_THRESHOLD")]
# Circuit breaker recovery timeout (seconds)
mcp_circuit_breaker_recovery: Annotated[float, Field(default=60.0, alias="MCP_CIRCUIT_BREAKER_RECOVERY")]

# Embedding settings
embedding_model: Annotated[
str,
Expand Down
2 changes: 2 additions & 0 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from rag_solution.router.user_router import router as user_router
from rag_solution.router.voice_router import router as voice_router
from rag_solution.router.websocket_router import router as websocket_router
from rag_solution.router.mcp_router import router as mcp_router

# Services
from rag_solution.services.system_initialization_service import SystemInitializationService
Expand Down Expand Up @@ -222,6 +223,7 @@ async def lifespan(_app: FastAPI) -> AsyncGenerator[None, None]:
app.include_router(token_warning_router)
app.include_router(voice_router)
app.include_router(websocket_router)
app.include_router(mcp_router)


# Root endpoint
Expand Down
28 changes: 28 additions & 0 deletions backend/rag_solution/mcp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""MCP Gateway Integration for RAG Modulo.

This module provides a thin wrapper for integrating with MCP Context Forge Gateway,
enabling tool invocation and search result enrichment with production-grade
resilience patterns including circuit breaker, health checks, and rate limiting.

Architecture Decision:
This implementation follows the "Simple Gateway Integration" approach recommended
by expert panel (Martin Fowler, Sam Newman, Michael Nygard, Gregor Hohpe):
- ~200 lines vs 2,000+ for complex agent framework
- Leverages MCP Context Forge's existing 400+ tests
- Includes production features: rate limiting, auth, circuit breaker

Modules:
- gateway_client: ResilientMCPGatewayClient with circuit breaker and health checks
- enricher: SearchResultEnricher for parallel result enhancement
- mcp_schema: Pydantic schemas for request/response validation
"""

from rag_solution.mcp.enricher import SearchResultEnricher
from rag_solution.mcp.gateway_client import CircuitBreaker, CircuitBreakerOpenError, MCPGatewayClient

__all__ = [
"CircuitBreaker",
"CircuitBreakerOpenError",
"MCPGatewayClient",
"SearchResultEnricher",
]
Loading
Loading