Skip to main content

@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-application and the vault-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, zod and Node built-ins.
  • No writes without a preview. Every writing tool is called with execute: false first; 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 calls McpVault.connect in 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) and library/ (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 generic call(tool, args, schema).
  • shared/ holds the schemas every port uses (PARA buckets, mastery, verdicts, dates, the climb write result) and translate, which turns client errors into application errors.
  • McpVault only 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 as UnusableReplyError; a server refusal comes through as VaultRefusedError with the server's own words.
  • Tier 2 stays strict. McpSessionLog.tier2Payload passes core assertions only when asked and re-checks the payload with the domain's tier2Payload, 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 of NotesRepository, SessionLog, VaultFiling and Library.
  • McpNotesRepository, McpSessionLog, McpVaultFiling, McpLibrary — the same ports one at a time, built on a VaultClient.
  • NotesTools, SessionTools, FilingTools, LibraryTools — typed wrappers around each server tool, including search and vault_graph, which the coach doesn't use yet.
  • VaultClient, vaultOptionsFromEnv, VaultToolError, VaultContractError — the connection and its errors.
  • The zod reply 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​

  1. Make sure the server offers the tool; if not, add it to vault-application and vault-mcp-server first.
  2. Add its reply schema to the port folder's schemas.ts and a typed method to that folder's tools.ts.
  3. Map the reply to the application's types in the port adapter (mcp-*.ts), catching errors with translate; if the port gained a method, add the delegating method to McpVault.
  4. Add a spec with a fake VaultClient next to the adapter and run npm exec nx test @ai-coach/adapter-vault-mcp and npm 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.