# Sprint 21: MCP Server Configuration

> **Size**: L | **Owner**: Backend + Client | **Prerequisites**: Sprint 18
> **Phase**: 5 - Platform Evolution

---

## Validation Status (2025-12-31)

### ✅ Unblocked — Prerequisite Implemented

| Prerequisite | Status | Impact |
|--------------|--------|--------|
| Project scoping (Sprint 18) | ✅ Implemented | MCP servers can now be scoped to projects |

| Component | Status | Notes |
|-----------|--------|-------|
| MCP registry schema | ❌ Not implemented | No `domain/entities/mcp_config.py` |
| MCP registry infrastructure | ❌ Not implemented | No `infrastructure/mcp/registry.py` |
| MCP RPCs | ❌ Not implemented | No proto messages for MCP config |
| MCP UI | ❌ Not implemented | No Settings integration |

**Action required**: Sprint 18 prerequisite satisfied; proceed with MCP implementation.

**Downstream impact**: Sprint 22 (Rules) and Sprint 25 (LangGraph) depend on MCP configuration.

---

## Objective

Centralize "where context and tools come from" with scoped MCP server configuration and **explicit scope precedence** (workspace defaults → project overrides → resource overrides).

---

## Decision: Backend DB

> **Decided**: MCP server configuration stored in backend DB, synced by workspace. Enables team sharing and consistent behavior across devices.

---

## What Already Exists

| Asset | Location | Implication |
|-------|----------|-------------|
| Settings infrastructure | `config/settings.py` | Feature toggle patterns |
| Workspace scoping (Sprint 16) | `persistence/models/identity/identity.py` | ✅ Scope levels available |
| Project scoping (Sprint 18) | ✅ Implemented | **Prerequisite satisfied** |

---

## Scope

| Task | Effort |
|------|--------|
| MCP registry schema | M |
| Scope rules (workspace → project → resource) | M |
| Credential boundary per scope | M |
| MCP server CRUD endpoints | M |
| Runtime server selection | M |
| MCP configuration UI | M |

---

## Deliverables

- `src/noteflow/domain/entities/mcp_config.py`
- `src/noteflow/infrastructure/mcp/registry.py`
- `src/noteflow/infrastructure/mcp/credentials.py` (per-scope secrets)
- MCP RPCs in proto
- MCP management in Settings

## Quality Gates

- [ ] `pytest tests/grpc/test_mcp_config.py` passes
- [ ] `npm run test` passes for frontend
- [ ] Meets `docs/sprints/QUALITY_STANDARDS.md` (lint + test quality thresholds)

---

## Post-Sprint

- MCP server health checks
- Server capability discovery
- Per-user server preferences
