feat(backend): implement MCP client infrastructure (#55)

Core MCP client implementation with comprehensive tooling:

**Services:**
- MCPClientManager: Main facade for all MCP operations
- MCPServerRegistry: Thread-safe singleton for server configs
- ConnectionPool: Connection pooling with auto-reconnection
- ToolRouter: Automatic tool routing with circuit breaker
- AsyncCircuitBreaker: Custom async-compatible circuit breaker

**Configuration:**
- YAML-based config with Pydantic models
- Environment variable expansion support
- Transport types: HTTP, SSE, STDIO

**API Endpoints:**
- GET /mcp/servers - List all MCP servers
- GET /mcp/servers/{name}/tools - List server tools
- GET /mcp/tools - List all tools from all servers
- GET /mcp/health - Health check all servers
- POST /mcp/call - Execute tool (admin only)
- GET /mcp/circuit-breakers - Circuit breaker status
- POST /mcp/circuit-breakers/{name}/reset - Reset circuit breaker
- POST /mcp/servers/{name}/reconnect - Force reconnection

**Testing:**
- 156 unit tests with comprehensive coverage
- Tests for all services, routes, and error handling
- Proper mocking and async test support

**Documentation:**
- MCP_CLIENT.md with usage examples
- Phase 2+ workflow documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-03 11:12:41 +01:00
parent 731a188a76
commit e5975fa5d0
22 changed files with 5763 additions and 0 deletions

View File

@@ -214,6 +214,71 @@ test(frontend): add unit tests for ProjectDashboard
---
## Phase 2+ Implementation Workflow
**For complex infrastructure issues (Phase 2 MCP, core systems), follow this rigorous process:**
### 1. Branch Setup
```bash
# Create feature branch from dev
git checkout dev && git pull
git checkout -b feature/<issue-number>-<description>
```
### 2. Planning Phase
- Read the issue thoroughly, understand ALL sub-tasks
- Identify components and their dependencies
- Determine if multi-agent parallel execution is appropriate
- Create a detailed execution plan before writing any code
### 3. Implementation with Continuous Testing
**After EACH sub-task:**
- [ ] Run unit tests for the component
- [ ] Run integration tests if applicable
- [ ] Verify type checking passes
- [ ] Verify linting passes
- [ ] Keep coverage high (aim for >90%)
**Both modules must be tested:**
- Backend: `IS_TEST=True uv run pytest` + E2E tests
- Frontend: `npm test` + E2E tests (if applicable)
### 4. Multi-Agent Review (MANDATORY before considering done)
Before closing an issue, perform deep review from multiple angles:
| Review Type | Focus Areas |
|-------------|-------------|
| **Code Quality** | Logic errors, edge cases, race conditions, error handling |
| **Security** | OWASP Top 10, input validation, authentication, authorization |
| **Performance** | N+1 queries, memory leaks, inefficient algorithms |
| **Architecture** | Pattern adherence, separation of concerns, extensibility |
| **Testing** | Coverage completeness, test quality, edge case coverage |
| **Documentation** | Code comments, README, API docs, usage examples |
**No stone unturned. No sloppy results. No unreviewed work.**
### 5. Final Validation
- [ ] All tests pass (unit, integration, E2E)
- [ ] Type checking passes
- [ ] Linting passes
- [ ] Documentation updated
- [ ] Coverage meets threshold
- [ ] Issue checklist 100% complete
- [ ] Multi-agent review passed
### When to Use Parallel Agents
Use multiple agents working in parallel when:
- Sub-tasks are independent (no shared state/dependencies)
- Different expertise areas (backend vs frontend)
- Time-critical deliveries with clear boundaries
Do NOT use parallel agents when:
- Tasks share state or have dependencies
- Sequential testing is required
- Integration points need careful coordination
---
## Quick Reference
| Action | Command/Location |