You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
core: move MCP tool handler logic into shared operations that the CLI and doctor also call #1349
agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.area: corepackages/core: the brain CLI, indexer, hybrid search, config, taxonomy, skills.area: mcpThe stdio MCP server and its brain_* tools.priority: p2Wanted, not scheduled. Pulled in when a milestone has room.type: refactorStructure changes; behaviour does not. No changeset-visible effect.
startMcpServer is 600 lines (packages/core/src/mcp-server.ts:91-691). Tool handlers contain logic other surfaces need: the index-staleness check (indexStalenessWarning, packages/core/src/mcp-server.ts:134-174), reimplemented by doctor (packages/core/src/cli/commands/doctor.ts:312-330), and the brain_update read-modify-write-reindex flow (packages/core/src/mcp-server.ts:564-640).
Scope
Move each tool handler's body into a function under packages/core/src/lib/ops/ (one module per operation or per family) that takes resolved dependencies and returns the result object.
mcp-server.ts keeps schema registration and thin wrappers that map results to MCP content.
doctor's staleness check calls the shared staleness function.
Out of scope
Adding a CLI update command (see the separate brain_update issue).
Changing any MCP input schema, tool name or output text.
Provider resolution (separate issue).
Acceptance criteria
startMcpServer is under ~200 lines and contains no SQL.
One staleness function is called by both MCP and doctor; a test asserts both report the same stale count on one fixture.
packages/core/tests/mcp-contract.test.ts and mcp-input-schemas.json pass unchanged.
Each extracted operation has a direct unit test against the fixture corpus.
Verification
bun run test packages/core
bun run typecheck
bun run lint
Contract impact
None intended; contract snapshots must not change.
Delivered in #1468, squash-merged as 62cf4d6 on main. The tool handler bodies now live in packages/core/src/lib/ops/ (staleness.ts, read.ts, write.ts). startMcpServer went from 594 lines to 68 and contains no SQL. brain doctor's db check calls the shared indexStaleness. index-staleness.test.ts asserts that MCP and doctor both report 3 stale files on one fixture; it failed first against a divergent doctor copy, and fails again when the shared function is mutated. Every extracted op has a direct test against the fixture corpus in ops.test.ts. The MCP contract snapshots are unchanged. listDocuments applies the limit it is given, which is the seam #1351 needs. All CI jobs passed on the PR head (run 38029506593, checkout of the merge with main a8f884f). The dependants #1351, #1353, #1356 and #1398 are no longer blocked.
agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.area: corepackages/core: the brain CLI, indexer, hybrid search, config, taxonomy, skills.area: mcpThe stdio MCP server and its brain_* tools.priority: p2Wanted, not scheduled. Pulled in when a milestone has room.type: refactorStructure changes; behaviour does not. No changeset-visible effect.
Activity
schlessera commentedon Oct 10, 2026
Unblocked: #1350 merged in #1458 (a8f884f), its only listed blocker.
schlessera commentedon Oct 10, 2026
Claimed (token w1349-a). Working on branch
refactor/1349-mcp-shared-ops.CONTRACT: refactor(core): move MCP tool handler logic into shared ope…
schlessera commentedon Oct 10, 2026
Delivered in #1468, squash-merged as 62cf4d6 on main. The tool handler bodies now live in
packages/core/src/lib/ops/(staleness.ts,read.ts,write.ts).startMcpServerwent from 594 lines to 68 and contains no SQL.brain doctor'sdbcheck calls the sharedindexStaleness.index-staleness.test.tsasserts that MCP and doctor both report 3 stale files on one fixture; it failed first against a divergent doctor copy, and fails again when the shared function is mutated. Every extracted op has a direct test against the fixture corpus inops.test.ts. The MCP contract snapshots are unchanged.listDocumentsapplies the limit it is given, which is the seam #1351 needs. All CI jobs passed on the PR head (run 38029506593, checkout of the merge with main a8f884f). The dependants #1351, #1353, #1356 and #1398 are no longer blocked.