@ai-coach/adapter-vault-mcp
The bridge to your Obsidian vault. ai-coach never opens the files in your vault itself. Every read and every change goes through the vault server, which this package starts and talks to over MCP. You change this package when the coach needs a vault ability the server already offers, or when a server reply changes shape.
What it does not do
- No vault logic. Folder layout, sparring history, quote checks and safe moves belong to
vault-applicationand thevault-mcp-server. If something is missing, add it there; this package only wraps what the server offers. - No file access. It never reads or writes vault files directly.
- No imports from
scope:vault. It speaks to the server over MCP only; Nx boundaries (adapter:vault-mcp) allow just@modelcontextprotocol/sdk,zodand Node built-ins. - No writes without a preview. Every writing tool is called with
execute: falsefirst; the CLI executes only after you confirm.
Architecture fit
- Scope:
scope:coach - Style:
architecture:hexagonal(type:adapter,adapter:vault-mcp) - Depends on:
@ai-coach/application(the ports),@ai-coach/domain - Used by:
@ai-coach/cli, which callsMcpVault.connectin its composition root
[use cases] ──▶ McpVault ──▶ McpNotesRepository ─┐
├─▶ McpSessionLog ───────┤
├─▶ McpVaultFiling ──────┼─▶ <Port>Tools ──▶ VaultClient.call ──▶ vault-mcp-server (stdio)
└─▶ McpLibrary ──────────┘
Internal architecture & rules
- One folder per port under
src/lib/:notes/(NotesRepository),sessions/(SessionLog),filing/(VaultFiling) andlibrary/(Library). Each holds the reply schemas for its tools (schemas.ts), a typed wrapper per server tool (tools.ts) and the port adapter (mcp-*.ts). A port folder never imports another port folder. client/starts the server (node <docsMcpBin> serve --vault <vault>), keeps the end of its stderr for start-up errors, and offers one genericcall(tool, args, schema).shared/holds the schemas every port uses (PARA buckets, mastery, verdicts, dates, the climb write result) andtranslate, which turns client errors into application errors.McpVaultonly composes. It connects once, builds the four port adapters on the same client and delegates each port method to them.- Every reply is validated. A reply that doesn't match its schema throws
VaultContractError, surfaced asUnusableReplyError; a server refusal comes through asVaultRefusedErrorwith the server's own words. - Tier 2 stays strict.
McpSessionLog.tier2Payloadpasses core assertions only when asked and re-checks the payload with the domain'stier2Payload, so nothing beyond questions and answers can reach the judge (privacy). - No comments in source code (DEC-AIC-0011).
Public surface
McpVault— what the coach uses:connect,close, and every method ofNotesRepository,SessionLog,VaultFilingandLibrary.McpNotesRepository,McpSessionLog,McpVaultFiling,McpLibrary— the same ports one at a time, built on aVaultClient.NotesTools,SessionTools,FilingTools,LibraryTools— typed wrappers around each server tool, includingsearchandvault_graph, which the coach doesn't use yet.VaultClient,vaultOptionsFromEnv,VaultToolError,VaultContractError— the connection and its errors.- The
zodreply schemas (ReadNoteResult,Tier2Payload,FilingResult, …).
Pointing ai-coach at your vault (vault, DOCS_MCP_VAULT, docsMcpBin) is covered in the configuration guide.
How to extend it
- Make sure the server offers the tool; if not, add it to
vault-applicationandvault-mcp-serverfirst. - Add its reply schema to the port folder's
schemas.tsand a typed method to that folder'stools.ts. - Map the reply to the application's types in the port adapter (
mcp-*.ts), catching errors withtranslate; if the port gained a method, add the delegating method toMcpVault. - Add a spec with a fake
VaultClientnext to the adapter and runnpm exec nx test @ai-coach/adapter-vault-mcpandnpm exec nx lint @ai-coach/adapter-vault-mcp.
Running & testing
npm exec nx test @ai-coach/adapter-vault-mcp
npm exec nx lint @ai-coach/adapter-vault-mcp
npm exec nx typecheck @ai-coach/adapter-vault-mcp
npm exec nx build @ai-coach/adapter-vault-mcp
The specs replace VaultClient with a fake that validates canned replies, so they need no running server. End-to-end changes are still tried by hand against a copy of a vault, never your real one.
Key ADRs
- DEC-AIC-0003 — the coach reaches the vault only through the MCP server.
- DEC-AIC-0048 — the server lives in this repository but stays behind the same MCP boundary.
- DEC-AIC-0004 — only the Tier 2 payload leaves the machine.
- DEC-AIC-0009 — every write is previewed before it runs.
- DEC-AIC-0010 — each layer is tested without depending on a running server.