-
Notifications
You must be signed in to change notification settings - Fork 4
feat(mcp): Implement MCP Gateway integration for extensibility #684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(mcp): Implement MCP Gateway integration for extensibility #684
Conversation
🚀 Development Environment OptionsThis repository supports Dev Containers for a consistent development environment. Option 1: GitHub Codespaces (Recommended)Create a cloud-based development environment:
Option 2: VS Code Dev Containers (Local)Use Dev Containers on your local machine:
Option 3: Traditional Local SetupSet up the development environment manually: # Clone the repository
git clone https://github.com/manavgup/rag_modulo.git
cd rag_modulo
git checkout claude/implement-issue-653-01XnmYg4iGRZHquUbm9Fifgd
# Initialize development environment
make dev-init
make dev-build
make dev-up
make dev-validateAvailable CommandsOnce in your development environment: make help # Show all available commands
make dev-validate # Validate environment setup
make test-atomic # Run atomic tests
make test-unit # Run unit tests
make lint # Run lintingServices AvailableWhen running
This automated message helps reviewers quickly set up the development environment. |
Code Review: MCP Gateway Integration (PR #684)SummaryThis PR implements a well-architected MCP (Model Context Protocol) integration with strong patterns following expert recommendations. The implementation adds 2,826 lines across 10 files with comprehensive test coverage (1,126 test lines) representing 40% of the codebase changes. ✅ Strengths1. Excellent Architecture & Design Patterns
2. Comprehensive Error Handling
3. Production-Ready Features
4. Excellent Test Coverage
5. Code Quality
|
Add comprehensive architecture document for integrating SPIRE (SPIFFE Runtime Environment) into RAG Modulo to provide cryptographic workload identity for AI agents, MCP tools, and services. Key sections: - Problem statement: gaps in current user-only identity model - SPIRE/SPIFFE concepts: SVIDs, attestation, trust domains - Proposed architecture: identity hierarchy for all workloads - Integration points: backend, MCP Gateway, agents, infrastructure - Trust domain design: single vs federated architectures - Workload registration: selectors and attestation strategies - Implementation phases: 5-phase rollout plan - Security considerations: threat model and best practices - Deployment strategies: Docker Compose and Kubernetes - MCP Context Forge integration: aligns with PR #684 This enables machine/agent IDs (AgentIDs) for the upcoming AI agent capabilities being added via MCP Context Forge integration.
Add environment variables to support SPIFFE workload identity integration for AI agents and services. This enables cryptographic machine identity with configurable migration phases: - SPIFFE_ENABLED: Toggle SPIFFE integration - SPIFFE_AUTH_MODE: Migration phases (disabled→optional→preferred→required) - SPIFFE_ENDPOINT_SOCKET: SPIRE Agent Workload API socket - SPIFFE_TRUST_DOMAIN: Trust domain for identity hierarchy - SPIFFE_LEGACY_JWT_WARNING: Track legacy auth usage during migration - SPIFFE_SVID_TTL_SECONDS: Certificate lifetime configuration - SPIFFE_JWT_AUDIENCES: Allowed JWT-SVID audiences Related to: MCP Context Forge integration (PR #684)
This architecture document outlines how to integrate SPIRE (SPIFFE Runtime Environment) into RAG Modulo to provide cryptographic workload identities for AI agents. This enables zero-trust agent authentication and secure agent-to-agent (A2A) communication. Key architectural decisions: - JWT-SVIDs for stateless verification (vs X.509 for mTLS) - Trust domain: spiffe://rag-modulo.example.com - Integration with IBM MCP Context Forge (PR #684) - Capability-based access control for agents - 5-phase implementation plan Agent types defined: - search-enricher: MCP tool invocation - cot-reasoning: Chain of Thought orchestration - question-decomposer: Query decomposition - source-attribution: Document source tracking - entity-extraction: Named entity recognition - answer-synthesis: Answer generation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Add comprehensive architecture documentation for the Agentic RAG Platform: - agentic-ui-architecture.md: React component hierarchy, state management, and API integration for agent features - backend-architecture-diagram.md: Overall backend architecture with Mermaid diagrams showing service layers and data flow - mcp-integration-architecture.md: MCP client/server integration strategy, PR comparison (#671 vs #684), and Context Forge integration - rag-modulo-mcp-server-architecture.md: Exposing RAG capabilities as MCP server with tools (rag_search, rag_ingest, etc.) and resources - search-agent-hooks-architecture.md: 3-stage agent pipeline (pre-search, post-search, response) with database schema and execution flow - system-architecture.md: Complete system architecture overview with technology stack and data flows These documents guide implementation of: - PR #695 (SPIFFE/SPIRE agent identity) - PR #671 (MCP Gateway client) - Issue #697 (Agent execution hooks) - Issue #698 (MCP Server) - Issue #699 (Agentic UI) Closes #696 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Add comprehensive architecture documentation for the Agentic RAG Platform: - agentic-ui-architecture.md: React component hierarchy, state management, and API integration for agent features - backend-architecture-diagram.md: Overall backend architecture with Mermaid diagrams showing service layers and data flow - mcp-integration-architecture.md: MCP client/server integration strategy, PR comparison (#671 vs #684), and Context Forge integration - rag-modulo-mcp-server-architecture.md: Exposing RAG capabilities as MCP server with tools (rag_search, rag_ingest, etc.) and resources - search-agent-hooks-architecture.md: 3-stage agent pipeline (pre-search, post-search, response) with database schema and execution flow - system-architecture.md: Complete system architecture overview with technology stack and data flows These documents guide implementation of: - PR #695 (SPIFFE/SPIRE agent identity) - PR #671 (MCP Gateway client) - Issue #697 (Agent execution hooks) - Issue #698 (MCP Server) - Issue #699 (Agentic UI) Closes #696 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Add comprehensive architecture documentation for the Agentic RAG Platform: - agentic-ui-architecture.md: React component hierarchy, state management, and API integration for agent features - backend-architecture-diagram.md: Overall backend architecture with Mermaid diagrams showing service layers and data flow - mcp-integration-architecture.md: MCP client/server integration strategy, PR comparison (#671 vs #684), and Context Forge integration - rag-modulo-mcp-server-architecture.md: Exposing RAG capabilities as MCP server with tools (rag_search, rag_ingest, etc.) and resources - search-agent-hooks-architecture.md: 3-stage agent pipeline (pre-search, post-search, response) with database schema and execution flow - system-architecture.md: Complete system architecture overview with technology stack and data flows These documents guide implementation of: - PR #695 (SPIFFE/SPIRE agent identity) - PR #671 (MCP Gateway client) - Issue #697 (Agent execution hooks) - Issue #698 (MCP Server) - Issue #699 (Agentic UI) Closes #696 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
* feat: add SPIFFE/SPIRE configuration for agent identity Add environment variables to support SPIFFE workload identity integration for AI agents and services. This enables cryptographic machine identity with configurable migration phases: - SPIFFE_ENABLED: Toggle SPIFFE integration - SPIFFE_AUTH_MODE: Migration phases (disabled→optional→preferred→required) - SPIFFE_ENDPOINT_SOCKET: SPIRE Agent Workload API socket - SPIFFE_TRUST_DOMAIN: Trust domain for identity hierarchy - SPIFFE_LEGACY_JWT_WARNING: Track legacy auth usage during migration - SPIFFE_SVID_TTL_SECONDS: Certificate lifetime configuration - SPIFFE_JWT_AUDIENCES: Allowed JWT-SVID audiences Related to: MCP Context Forge integration (PR #684) * docs: add SPIFFE/SPIRE integration architecture for agent identity This architecture document outlines how to integrate SPIRE (SPIFFE Runtime Environment) into RAG Modulo to provide cryptographic workload identities for AI agents. This enables zero-trust agent authentication and secure agent-to-agent (A2A) communication. Key architectural decisions: - JWT-SVIDs for stateless verification (vs X.509 for mTLS) - Trust domain: spiffe://rag-modulo.example.com - Integration with IBM MCP Context Forge (PR #684) - Capability-based access control for agents - 5-phase implementation plan Agent types defined: - search-enricher: MCP tool invocation - cot-reasoning: Chain of Thought orchestration - question-decomposer: Query decomposition - source-attribution: Document source tracking - entity-extraction: Named entity recognition - answer-synthesis: Answer generation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * feat(spiffe): implement SPIFFE/SPIRE agent authentication This commit implements the SPIFFE/SPIRE integration for AI agent authentication as designed in docs/architecture/spire-integration-architecture.md. Key changes: - Add py-spiffe dependency for SPIFFE JWT-SVID support - Create core SPIFFE authentication module (spiffe_auth.py) with: - SPIFFEConfig for environment-based configuration - AgentPrincipal dataclass for authenticated agent identity - SPIFFEAuthenticator for JWT-SVID validation - AgentType and AgentCapability enums - Helper functions for SPIFFE ID parsing and building - Create Agent data model with SQLAlchemy: - Agent model with SPIFFE ID, type, capabilities, status - Relationships to User (owner) and Team - Status management (active, suspended, revoked) - Add Agent repository, service, and router layers: - Full CRUD operations for agents - Agent registration with SPIFFE ID generation - Status and capability management - JWT-SVID validation endpoint - Extend AuthenticationMiddleware to detect and validate SPIFFE JWT-SVIDs - Add SPIRE deployment configuration templates: - server.conf, agent.conf for SPIRE configuration - docker-compose.spire.yml for local development - README.md with deployment instructions - Add comprehensive unit tests for all SPIFFE components Reference: PR #695 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix(spiffe): address PR review feedback for SPIFFE/SPIRE integration Critical fixes: - Add database migration for agents table (migrations/add_agents_table.sql) - Fix signature verification security: failed validation now always rejects (prevents fallback bypass attack) - Fix timezone handling: use UTC consistently for JWT timestamps Improvements: - Align env vars with .env.example (SPIFFE_JWT_AUDIENCES, SPIFFE_SVID_TTL_SECONDS) - Add capability enforcement decorator (require_capabilities) - Add OpenAPI tags metadata for agents endpoint - Update and expand unit tests (47 tests passing) Addresses review comments from PR #695. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix(spiffe): rename metadata to agent_metadata to avoid SQLAlchemy reserved word SQLAlchemy's Declarative API reserves the 'metadata' attribute name. Renamed the field to 'agent_metadata' in the model while keeping the database column name as 'metadata' via explicit column name mapping. This also updates the schema to use validation_alias for proper model_validate() from ORM objects. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix(test): add missing trust_domain to AgentPrincipal in test The test_validate_jwt_svid_valid test was failing because AgentPrincipal requires a trust_domain field which was not being provided. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix(spiffe): Address comprehensive PR review feedback Critical fixes: - Fix timezone-naive datetime to use UTC throughout (agent.py, agent_repository.py) - Change default agent status from ACTIVE to PENDING for approval workflow - Add RuntimeError when SPIFFE enabled but py-spiffe library missing - Restrict trust domain to configured value only (security fix) High priority security fixes: - Add capability validation per agent type (ALLOWED_CAPABILITIES_BY_TYPE) - Add authentication requirement to SPIFFE validation endpoint - Reject user-specified trust domains that don't match server config Code quality improvements: - Add OpenAPI tags metadata for agent router documentation - Fix require_capabilities decorator type hints (ParamSpec, TypeVar) - Add composite database indexes (owner+status, type+status, team+status) - Update migration script with new composite indexes Test updates: - Update test_register_agent_with_custom_trust_domain to verify rejection - Fix test_authenticator_creates_principal_with_fallback to mock spiffe module 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
Implements a simplified MCP (Model Context Protocol) integration approach as recommended by expert panel (Martin Fowler, Sam Newman, Michael Nygard, Gregor Hohpe). This provides foundational capability for tool-based search result enrichment. Key components: - ResilientMCPGatewayClient: Thin wrapper (~200 lines) with circuit breaker pattern, health checks (5s timeout), retry logic, and graceful degradation - SearchResultEnricher: Content Enricher pattern implementation (~200 lines) with parallel execution and error isolation - MCP Router: API endpoints for tool discovery and invocation Features: - Circuit breaker: 5 failure threshold, 60s recovery timeout - Health monitoring with 5-second timeout - API versioning (v1 format) - Prometheus-ready metrics - Graceful degradation (core RAG works if tools fail) Docker infrastructure: - Redis service for MCP gateway caching - MCP Context Forge gateway container Configuration settings added: - MCP_ENABLED, MCP_GATEWAY_URL, MCP_TIMEOUT - MCP_CIRCUIT_BREAKER_THRESHOLD, MCP_CIRCUIT_BREAKER_TIMEOUT - MCP_ENRICHMENT_ENABLED, MCP_MAX_CONCURRENT Closes #653
Production fixes in search_result_enricher.py: - Fix QueryResult access: qr.text → qr.chunk.text with null safety - Fix DocumentMetadata attributes: doc_id → document_name, file_type → content_type - Remove non-existent file_name attribute access Test fixes in test_search_result_enricher.py: - Fix property mocking: use _mcp_client direct assignment instead of patch.object - Use MagicMock instead of Mock for proper async method support - Fix mock_search_output fixture to use proper QueryResult structure - Add DocumentChunkWithScore import for proper chunk construction All 50 MCP-related tests now pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
d4b0b2f to
4b21226
Compare
Code Review - MCP Gateway Integration (PR #684)OverviewThis PR implements a well-architected MCP (Model Context Protocol) integration following expert panel recommendations. The implementation adds ~2,800 lines with foundational capabilities for tool-based search result enrichment. ✅ Strengths1. Excellent Architecture & Design Patterns
2. Robust Error Handling
3. High-Quality Tests
4. Observability & Monitoring
5. Security Considerations
6. Configuration Management
🔍 Issues & RecommendationsPriority 1: Critical Issues1. Missing httpx Dependency
|
- Remove unused imports: patch, uuid4 - Remove unused variable assignment in test_enrich_with_specific_tools 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
PR Review: MCP Gateway Integration for ExtensibilitySummaryThis PR implements a well-architected MCP (Model Context Protocol) integration following expert recommendations. The implementation is clean, follows enterprise patterns, and includes comprehensive testing with 1,136+ lines of test code. ✅ Strengths1. Excellent Architecture & Design Patterns
2. Robust Error Handling
3. Strong Test Coverage
4. Security Considerations
5. Production-Ready Features
6. Code Quality
|
| Component | Lines | Test Lines | Coverage Estimate |
|---|---|---|---|
| mcp_gateway_client.py | 639 | 400 | ~85%+ (circuit breaker, retries, health) |
| search_result_enricher.py | 509 | 428 | ~85%+ (parallel/sequential, errors) |
| mcp_router.py | 275 | 308 | ~90%+ (all endpoints, auth, validation) |
| mcp_schema.py | 194 | N/A | 100% (Pydantic schemas) |
Overall: Strong test coverage with comprehensive unit tests. Integration tests would boost confidence to 95%+.
🎯 Recommendations Summary
Must Address Before Merge:
- ✅ Add MCP_JWT_TOKEN to secrets baseline - prevents accidental commits
- ✅ Pin Docker image version - prevents unexpected breaking changes
Should Address Soon (Follow-up PR):
- 🔄 Add integration tests - validate real MCP gateway interaction
- 🔄 Document API with examples - improve developer experience
- 🔄 Add container vulnerability scanning - security hardening
Nice to Have:
- 💡 Performance testing - validate concurrent enrichment at scale
- 💡 Adaptive concurrency - optimize based on gateway latency
🎉 Conclusion
This is high-quality, production-ready code that follows enterprise patterns and best practices. The architecture is sound, error handling is robust, and test coverage is comprehensive.
Recommendation: ✅ APPROVE with minor fixes
The security concern (JWT token storage) is easily addressable via secrets baseline update. The Docker image pinning is a best practice that should be addressed before merge.
Once the two "Must Address" items are completed, this PR is ready to merge.
Additional Notes
- Aligns with CLAUDE.md: Follows service architecture, type hints, async/await patterns, 120-char lines
- CI/CD: Will pass linting (Ruff), type checking (MyPy), unit tests
- Breaking Changes: None - this is purely additive functionality
- Documentation: Comprehensive docstrings, but external docs could be enhanced
Great work on this implementation! 🚀
Fixes from code review: - Replace deprecated datetime.utcnow() with datetime.now(UTC) (Python 3.12+) - Use datetime.UTC alias per Ruff UP017 rule - Fix Docker health check to use wget instead of curl (Alpine image) Files changed: - backend/rag_solution/schemas/mcp_schema.py: datetime.now(UTC) for Field defaults - backend/rag_solution/services/mcp_gateway_client.py: datetime.now(UTC) in circuit breaker - tests/unit/services/test_mcp_gateway_client.py: datetime.now(UTC) in tests - docker-compose-infra.yml: wget health check for MCP Context Forge All 50 MCP tests pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Code Review: MCP Gateway Integration (PR #684)This PR implements a well-designed MCP (Model Context Protocol) integration following expert recommendations. Overall, this is high-quality code with excellent architecture patterns. Below is my detailed review: ✅ Strengths1. Architecture & Design Patterns
2. Code Quality
3. Resilience Features
4. Security
|
Changed MCP Context Forge from port 3000 to 3001 to avoid conflict with the frontend which runs on port 3000. Files updated: - docker-compose-infra.yml: Port 3001 for MCP container - backend/core/config.py: Default MCP_GATEWAY_URL to port 3001 - tests/unit/*: Updated all mock settings and assertions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Comprehensive Code Review - PR #684: MCP Gateway IntegrationExecutive SummaryThis PR implements a well-architected MCP Gateway integration following enterprise patterns. Production-ready with 1,136 test lines covering core functionality. Overall code quality is excellent. Recommendation: ✅ APPROVE with minor suggestions ✅ StrengthsArchitecture & Design Excellence
Code Quality
Resilience & Observability
Security
Testing
🔍 Code Quality Scores
🚨 RecommendationsHigh Priority - Configuration ValidationIssue: No URL validation on gateway URL (config.py:291) Medium Priority - Resource ManagementIssue: New client per request loses circuit breaker state (mcp_router.py:44) Medium Priority - Error ContextIssue: Missing exc_info in exception logging (mcp_gateway_client.py:304) Low Priority - Docker VolumeIssue: Unused mcp_tools volume (docker-compose-infra.yml:220-224) Low Priority - Test CoverageMissing: Retry partial failures, concurrent circuit breaker, JWT expiration, large payloads 🔒 Security: Strong 🛡️✅ Input Validation: Pydantic strict schemas 📊 PerformancePositive: Parallel execution, semaphore control, lazy init, efficient retries Impact: +30-100ms latency, minimal throughput impact, ~5MB memory Future: Connection pooling, response caching, batch operations 🏗️ Architectural Alignment: Excellent✅ Service Architecture with DI Pattern Compliance: Circuit Breaker, Content Enricher, DI, Graceful Degradation 🎉 Final Verdict: 9.2/10Production-ready code demonstrating:
Recommendation: ✅ APPROVE Minor suggestions are optimizations, not blockers. Safe to merge. 🔧 Testing Checklist
Excellent work! This MCP integration provides a solid foundation for tool-based search enrichment. 🚀 |
MCP Context Forge uses PORT env var, not MCP_SERVER_PORT.
Changed from 4444 (default) to 3001 to avoid frontend conflict.
Verified: curl http://localhost:3001/health returns {"status":"healthy"}
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Pull Request Review: MCP Gateway IntegrationI've completed a comprehensive review of PR #684. This is a well-architected implementation that follows enterprise integration patterns and the repository's standards. Below is my detailed feedback. ✅ Overall Assessment: APPROVED with Minor SuggestionsThis PR implements a simplified MCP (Model Context Protocol) integration with strong architectural foundations, comprehensive testing, and proper error handling. The code follows expert panel recommendations and maintains backward compatibility. 🎯 Strengths1. Excellent Architecture ⭐⭐⭐⭐⭐
2. Production-Ready Resilience ⭐⭐⭐⭐⭐
3. Comprehensive Test Coverage ⭐⭐⭐⭐⭐
4. Security Considerations ⭐⭐⭐⭐
5. Structured Logging ⭐⭐⭐⭐⭐
🔍 Code Quality AnalysisSchemas (
|
Implements a simplified MCP (Model Context Protocol) integration approach as recommended by expert panel (Martin Fowler, Sam Newman, Michael Nygard, Gregor Hohpe). This provides foundational capability for tool-based search result enrichment.
Key components:
Features:
Docker infrastructure:
Configuration settings added:
Closes #653