Docs / MCP server
MCP server
SourceVault's MCP server gives the governed engine to any MCP client: Claude Code, Claude Desktop, VS Code, Cursor, OpenClaw, custom agents. One backend serves every surface, so an MCP client gets the same index, retrieval, citations, policy, redaction, and audit chain as the dashboard, with no per-client integration work.
Setup
SourceVault has to be installed first, with at least one repository indexed. Then pick your client.
Claude Code
claude mcp add sourcevault -- sourcevault mcp
Then, in any session: "use sourcevault to search my-repo for the auth middleware", or let the model pick the tools up on its own.
Any other MCP client
Configure a stdio server with command sourcevault and args ["mcp"]. To test it standalone, run sourcevault mcp in a terminal and type a JSON-RPC request; it answers on stdout. Its stdout carries frames only: every log line, the audit chain head included, goes to stderr (v1.58.2).
Claude Desktop and other bundle hosts
Hosts that install MCP bundles take sourcevault-mcp.mcpb, published with every release since v1.66.0 beside the tarball:
https://github.com/sourcevault-ai/homebrew-tap/releases/latest/download/sourcevault-mcp.mcpb
Open it in the host (Claude Desktop: Settings → Extensions, or double-click the file). The bundle is a launcher, not the product: it finds the installed sourcevault command and runs sourcevault mcp. Without an install, the bundle says so and shows the install line for your platform.
Its three options are all optional and map to the environment variables on this page: "Agent token" is SOURCEVAULT_AGENT_TOKEN, "State directory" is SOURCEVAULT_STATE_DIR, and "sourcevault command" names the command when it lives somewhere unusual. The same bundle is what the official MCP registry lists as ai.sourcevault/gateway, pinned by its SHA-256, so a client that installs from the registry gets it too.
VS Code
VS Code's own MCP support (agent mode, from 1.102) reads .vscode/mcp.json in the workspace, or the user-level file behind the MCP: Open User Configuration command. A local install is a stdio server; the env line names the agent (see Agent identity):
{
"servers": {
"sourcevault": {
"type": "stdio",
"command": "sourcevault",
"args": ["mcp"],
"env": { "SOURCEVAULT_AGENT_TOKEN": "${env:SOURCEVAULT_AGENT_TOKEN}" }
}
}
}
A team server is an http entry instead, with the token prompted once and kept in VS Code's secret storage rather than written into the file:
{
"inputs": [
{ "type": "promptString", "id": "sourcevault-token", "description": "SourceVault agent token", "password": true }
],
"servers": {
"sourcevault": {
"type": "http",
"url": "https://vault.example.com/mcp",
"headers": { "Authorization": "Bearer ${input:sourcevault-token}" }
}
}
}
That token has to be minted for the mcp-http surface; the team server section has the command. The Claude Code extension for VS Code needs none of this: it uses the same registration as the CLI above.
Cursor
Cursor reads ~/.cursor/mcp.json for every project, or .cursor/mcp.json in one project, as a mcpServers map. A local install:
{
"mcpServers": {
"sourcevault": {
"command": "sourcevault",
"args": ["mcp"],
"env": { "SOURCEVAULT_AGENT_TOKEN": "sva_..." }
}
}
}
Cursor has no secret store for this file, so the token sits in it. Keep the file at mode 0600 and mint the token for Cursor alone (sourcevault agent mint cursor --surfaces mcp), so the audit chain tells Cursor's reads from another editor's and revoking one leaves the other alone. A team server is a url entry with the token in a header; Cursor reads ${env:NAME} in either place if you would rather hold the token in the environment:
{
"mcpServers": {
"sourcevault": {
"url": "https://vault.example.com/mcp",
"headers": { "Authorization": "Bearer ${env:SOURCEVAULT_AGENT_TOKEN}" }
}
}
}
Settings → MCP lists the server with its six tools and three resources once it has started; toggle it off and on if it does not.
Installs older than v1.56.0, and source checkouts
The mcp subcommand ships in v1.56.0. On an earlier Homebrew install, point the client at the server script inside the install; on a source checkout, at the script in the tree:
claude mcp add sourcevault -- node "$(brew --prefix)/opt/sourcevault/libexec/tools/mcp-server.js" # Homebrew, before v1.56.0 claude mcp add sourcevault -- node /path/to/sourcevault/tools/mcp-server.js # source checkout (or: npm run mcp)
Connecting to a team server (MCP over HTTP)
When SourceVault runs as a team server, one governed install answers every developer's agent instead of each of them indexing locally. Since v1.67.0 the server answers MCP at POST /mcp on the same port as the dashboard. Mint a token scoped to the mcp-http surface and the repositories the agent may reach, then register the server by URL:
sourcevault agent mint alice-claude --surfaces mcp-http --repos backend,frontend
claude mcp add --transport http sourcevault https://vault.example.com/mcp \
--header "Authorization: Bearer ${SOURCEVAULT_AGENT_TOKEN}"
In a project's .mcp.json the same server reads the token from the environment rather than writing it into the file:
{
"type": "http",
"url": "https://vault.example.com/mcp",
"headers": { "Authorization": "Bearer ${SOURCEVAULT_AGENT_TOKEN}" }
}
What the door enforces:
- A token on every request. Missing, unknown or revoked is
401; a live token minted for another surface is403. There is no unattributed mode over HTTP and no shared-secret fallback. A token minted for localmcpdoes not open the door. - Repository scope, strictly: a scoped agent names exactly one of its repositories as a string. A list, a wildcard or a comma pair is refused and recorded, and
list_reposshows only what the agent may reach. - Plaintext only on the server's own machine. From anywhere else the server needs TLS or a trusted TLS proxy, otherwise
503 tls_required. TheOriginheader, when a client sends one, must match the server's advertised origin. - Both protocol eras on one endpoint: 2026-07-28 clients statelessly, older clients through an
initializesession bound to their token that idles out after 30 minutes. - Per-agent limits rather than per-IP: 120 requests a minute, 20
ask_codebasecalls per five minutes and one in flight at a time,429withRetry-Afterbeyond them. Every refusal at the door is anauth_failedrecord in the audit chain, and every served call carriesvia: mcp-httpand the agent's name.
The deploy guide in the release tarball covers exposing the door behind a TLS proxy.
Agent identity
Over stdio, MCP has no wire authentication, so identity arrives as an environment variable in the client's server config. Mint a token scoped to the mcp surface and the repositories the agent may reach, then set it:
sourcevault agent mint claude-mcp --surfaces mcp --repos backend,frontend
# the plaintext token is printed once; put it in the client's server env:
claude mcp add sourcevault -e SOURCEVAULT_AGENT_TOKEN=<token> -- sourcevault mcp
The server fails closed: a token that is set but unknown, revoked, or not scoped to mcp refuses to start rather than running unattributed. A scoped agent gets agent_repo_scope errors outside its repositories, every audit record carries subject: claude-mcp, and policy rules can be written for that subject. No token keeps the older, unattributed behaviour. The Gateway reference covers scopes and revocation.
The two MCP surfaces are separate grants on purpose. mcp is the stdio server on the token holder's own machine; mcp-http is the network door of a team server. A token minted for one does not open the other unless it names both (--surfaces mcp,mcp-http), so handing out local tokens never hands out network reach.
Transport and trust boundary
On your own machine the server speaks the MCP stdio transport (newline-delimited JSON-RPC) to a client process on the same host and calls the engine in-process. There is no listener; the trust boundary is "can you start a process on this machine", the same as the CLI. It needs the same local stack as everything else: Ollama running and repositories indexed. In lite mode, search and file reads work unchanged and ask_codebase declines with an explanation instead of a grounded answer.
A team server's HTTP door moves the boundary from "can run a process here" to "holds a named agent token scoped to the door". Every request carries a token, plaintext is served to the server's own machine only, and the engine's policy, redaction and audit chain apply as they do over stdio.
Client egress
The server transmits nothing. The client you pair it with might: an MCP client forwards tool results (retrieved chunks, file contents, cited answers) into its own model context, and a cloud-backed client sends that context to its vendor. The egress is the client's, made with the excerpts you let it retrieve; it is bounded and per question, far smaller than cloud indexing, but it is not zero.
- Under a zero-egress requirement (air gap, ITAR, strict compliance), use local-model MCP clients only, such as OpenClaw pointed at a model that runs on the box, or any other client whose model stays local. This is the configuration the compliance pack's verification procedure covers.
- Where cloud-assisted development is accepted, pairing with Claude Code or similar is a deliberate, visible choice, and with the audit log on every excerpt the client retrieved is on record. Content is policy-checked and redacted before it reaches the client, and therefore before the client could forward it.
Tools
All tools are annotated read-only and local. Results include structuredContent for clients on 2025-06-18 or later alongside the JSON text block older clients parse.
| Tool | Arguments | Purpose |
|---|---|---|
list_repos | Indexed repositories and index status. Names are case-sensitive; call this first. | |
search_codebase | repo_name, query, n_results?, include_content? | Hybrid semantic and literal search. Returns previews with file and line provenance. |
read_repo_file | repo_name, relative_path, max_bytes? | Exact file content, confined to the repository; traversal is rejected. |
ask_codebase | repo_name, question, query?, n_results? | A grounded, cited answer from a local model. |
list_provenance_alerts | repo_name?, since?, limit? | Signed AI-change attestations and the chain verdict, to gate a merge on unresolved AI drift. |
get_attestation | id | One attestation, including its verifiable DSSE envelope. |
search_codebase is a locator. Each result carries a short preview plus the file, line range, matched symbols, and match type: enough to pick a file and aim a read_repo_file at it. include_content defaults to false; pass true to get each chunk's full text inline, at roughly eight times the tokens per result.
ask_codebase is the dashboard engine end to end: the question retrieves on its own (query only steers), bounded multi-hop and symbol-graph grounding apply, empty retrieval declines instead of guessing, answers are cached, and citations carry per-file staleness. repo_name is one indexed repository.
Resources
Read-only views of the install's state, for clients that attach context by URI. Every resource read lands in the audit log exactly like a tool call.
| URI | Content |
|---|---|
sourcevault://repos | Indexed repositories and index status; the authority for case-sensitive names. |
sourcevault://policy | Sentinel enforcement state and the loaded access-policy rules. |
sourcevault://repos/{repo}/files/{+path} | Exact file content, through the same policy and DLP gate as read_repo_file. |
Prompts
Prompts encode the retrieval patterns agents get wrong unaided: tool selection and query phrasing.
| Prompt | Arguments | Teaches |
|---|---|---|
ground_in_repo | repo_name, question | Confirm exact repository casing, keep citations intact, steer retrieval instead of guessing on a decline. |
locate_implementation | repo_name, target | Query both retrieval legs (exact identifier and prose), then read the real file rather than trusting previews. |
pre_merge_provenance_gate | repo_name? | Treat unresolved AI-change attestations as blocking; verify the chain; never report a clean gate when the feature is off. |
repo_orientation | repo_name | Build a cited architecture overview and say what is unknown instead of filling gaps from general knowledge. |
Protocol support
The server is dual-era per the 2026-07-28 MCP specification. Modern clients work statelessly: declare the protocol version in each request's _meta, or call server/discover first to see what the server speaks. Legacy clients (2024-11-05 through 2025-11-25) open with the initialize handshake, and the negotiated version holds for the process over stdio and for the session over HTTP. Both are served concurrently by the same process; an unsupported declared version gets an error listing the supported versions, so a client can retry.
Troubleshooting
| Symptom | Cause and fix |
|---|---|
| Tool calls fail with connection errors | Ollama is down. Run sourcevault doctor (npm run doctor on a source checkout). |
ask_codebase declines every question | The repository is not indexed or the name is wrong. Names are case-sensitive; list_repos shows the truth. |
| The server refuses to start with an agent token set ("matches no active agent token … Refusing to start unattributed") | The token is unknown, revoked, or not scoped to mcp. Check sourcevault agent list. |
Over HTTP, 401 | The token is missing from the client's header or no longer active. |
Over HTTP, 403 agent_scope | The token was minted for mcp, not mcp-http. |
Over HTTP, 503 tls_required | The client is not on the server's own machine and the server has no TLS and no trusted proxy. The deploy guide's MCP section covers both. |
Over HTTP, 404 on a request that worked a moment ago | The session idled out or the server restarted. Clients re-initialise on their own. |
Over HTTP, 429 with Retry-After | This agent's budget is spent, or an ask_codebase is already in flight for it. |