obsidian-mcp-server 3.6.0 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +40 -27
- package/CLAUDE.md +40 -27
- package/Dockerfile +90 -47
- package/README.md +130 -151
- package/changelog/3.6.x/3.6.1.md +29 -0
- package/changelog/3.7.x/3.7.0.md +34 -0
- package/dist/config/server-config.d.ts +1 -0
- package/dist/config/server-config.d.ts.map +1 -1
- package/dist/config/server-config.js +4 -0
- package/dist/config/server-config.js.map +1 -1
- package/dist/index.js +30 -10
- package/dist/index.js.map +1 -1
- package/dist/mcp-server/resources/definitions/obsidian-tags.resource.d.ts +7 -5
- package/dist/mcp-server/resources/definitions/obsidian-tags.resource.d.ts.map +1 -1
- package/dist/mcp-server/resources/definitions/obsidian-tags.resource.js +12 -8
- package/dist/mcp-server/resources/definitions/obsidian-tags.resource.js.map +1 -1
- package/dist/mcp-server/tools/definitions/_shared/suggest-paths.d.ts +32 -10
- package/dist/mcp-server/tools/definitions/_shared/suggest-paths.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/_shared/suggest-paths.js +30 -8
- package/dist/mcp-server/tools/definitions/_shared/suggest-paths.js.map +1 -1
- package/dist/mcp-server/tools/definitions/index.d.ts +230 -294
- package/dist/mcp-server/tools/definitions/index.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/index.js +9 -3
- package/dist/mcp-server/tools/definitions/index.js.map +1 -1
- package/dist/mcp-server/tools/definitions/obsidian-append-to-note.tool.js +1 -1
- package/dist/mcp-server/tools/definitions/obsidian-append-to-note.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/obsidian-delete-note.tool.d.ts +108 -10
- package/dist/mcp-server/tools/definitions/obsidian-delete-note.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/obsidian-delete-note.tool.js +254 -133
- package/dist/mcp-server/tools/definitions/obsidian-delete-note.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/obsidian-get-note.tool.d.ts +1 -0
- package/dist/mcp-server/tools/definitions/obsidian-get-note.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/obsidian-get-note.tool.js +62 -21
- package/dist/mcp-server/tools/definitions/obsidian-get-note.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/obsidian-list-commands.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/obsidian-list-commands.tool.js +1 -2
- package/dist/mcp-server/tools/definitions/obsidian-list-commands.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/obsidian-list-notes.tool.d.ts +6 -1
- package/dist/mcp-server/tools/definitions/obsidian-list-notes.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/obsidian-list-notes.tool.js +9 -12
- package/dist/mcp-server/tools/definitions/obsidian-list-notes.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/obsidian-list-tags.tool.d.ts +7 -5
- package/dist/mcp-server/tools/definitions/obsidian-list-tags.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/obsidian-list-tags.tool.js +14 -9
- package/dist/mcp-server/tools/definitions/obsidian-list-tags.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/obsidian-manage-frontmatter.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/obsidian-manage-frontmatter.tool.js +1 -2
- package/dist/mcp-server/tools/definitions/obsidian-manage-frontmatter.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/obsidian-manage-tags.tool.js +2 -2
- package/dist/mcp-server/tools/definitions/obsidian-manage-tags.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/obsidian-open-in-ui.tool.d.ts +4 -1
- package/dist/mcp-server/tools/definitions/obsidian-open-in-ui.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/obsidian-open-in-ui.tool.js +15 -4
- package/dist/mcp-server/tools/definitions/obsidian-open-in-ui.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/obsidian-replace-in-note.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/obsidian-replace-in-note.tool.js +2 -3
- package/dist/mcp-server/tools/definitions/obsidian-replace-in-note.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/obsidian-search-notes.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/obsidian-search-notes.tool.js +2 -5
- package/dist/mcp-server/tools/definitions/obsidian-search-notes.tool.js.map +1 -1
- package/dist/services/obsidian/obsidian-service.d.ts +7 -0
- package/dist/services/obsidian/obsidian-service.d.ts.map +1 -1
- package/dist/services/obsidian/obsidian-service.js +72 -35
- package/dist/services/obsidian/obsidian-service.js.map +1 -1
- package/dist/services/obsidian/patch-instruction.d.ts +20 -1
- package/dist/services/obsidian/patch-instruction.d.ts.map +1 -1
- package/dist/services/obsidian/patch-instruction.js +30 -0
- package/dist/services/obsidian/patch-instruction.js.map +1 -1
- package/dist/services/obsidian/path-policy.d.ts +23 -1
- package/dist/services/obsidian/path-policy.d.ts.map +1 -1
- package/dist/services/obsidian/path-policy.js +45 -3
- package/dist/services/obsidian/path-policy.js.map +1 -1
- package/dist/services/obsidian/section-extractor.d.ts +24 -0
- package/dist/services/obsidian/section-extractor.d.ts.map +1 -1
- package/dist/services/obsidian/section-extractor.js +37 -0
- package/dist/services/obsidian/section-extractor.js.map +1 -1
- package/manifest.json +9 -1
- package/package.json +13 -10
- package/server.json +24 -24
package/AGENTS.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# Agent Protocol
|
|
2
2
|
|
|
3
3
|
**Server:** obsidian-mcp-server
|
|
4
|
-
**Version:** 3.
|
|
5
|
-
**Framework:** [@cyanheads/mcp-ts-core](https://www.npmjs.com/package/@cyanheads/mcp-ts-core) `^0.13.
|
|
4
|
+
**Version:** 3.7.0
|
|
5
|
+
**Framework:** [@cyanheads/mcp-ts-core](https://www.npmjs.com/package/@cyanheads/mcp-ts-core) `^0.13.12`
|
|
6
6
|
**Engines:** Bun ≥1.4.0, Node ≥24.0.0
|
|
7
|
-
**MCP SDK:** `@modelcontextprotocol/server` ^2.
|
|
7
|
+
**MCP SDK:** `@modelcontextprotocol/server` ^2.2.0
|
|
8
8
|
**Zod:** ^4.6.5
|
|
9
9
|
|
|
10
10
|
> **Read the framework docs first:** `node_modules/@cyanheads/mcp-ts-core/CLAUDE.md` contains the full API reference — builders, Context, error codes, exports, patterns. This file covers server-specific conventions only.
|
|
@@ -34,11 +34,12 @@ Tailor suggestions to what's actually missing or stale — don't recite the full
|
|
|
34
34
|
|
|
35
35
|
- **Logic throws, framework catches.** Tool/resource handlers are pure — throw on failure, no `try/catch`. Plain `Error` is fine; the framework catches, classifies, and formats. Use error factories (`notFound()`, `validationError()`, etc.) when the error code matters.
|
|
36
36
|
- **Use `ctx.log`** for request-scoped logging. No `console` calls.
|
|
37
|
-
- **
|
|
37
|
+
- **The delete confirmation is opt-in; when on, it is gated on a consent record.** `OBSIDIAN_DELETE_ELICITATION` (default `false`) decides whether `obsidian_delete_note` confirms through `ctx.requestInput`. Off is the default for two reasons: a client that declares elicitation but cannot render the form declines every round automatically, which the server cannot tell from a real decline (#151), and the round forces a stateful HTTP session, which locks out `MCP_SESSION_MODE=stateless`. Off, `OBSIDIAN_WRITE_PATHS` / `OBSIDIAN_READ_ONLY` bound what a delete can reach — the same bound `obsidian_write_note` with `overwrite: true` has — and `destructiveHint` stays for client-side approval. The mode is the operator's choice alone: never derive it from `ctx.clientCapabilities` or from a decline. On, the handler redeems (reads and deletes) the `ctx.state` record named by `ctx.inputs.state()` before anything else, checks write scope on the resolved path before it reads the note or asks, and acts on the `ctx.inputs` answer only when that record deep-equals `{ operation, clientId, subject, target, contentHash }` for this call; otherwise it stores a fresh record (`ttl: 600`) and `return ctx.requestInput(...)` with the record id as `requestState`. An answer alone is never proof the user was asked. Never `await` user input mid-handler.
|
|
38
38
|
- **All Obsidian access goes through `getObsidianService()`.** No direct `fetch()` calls to the Local REST API in tools/resources — the service centralizes auth, TLS, timeouts, and `ctx.signal` propagation.
|
|
39
39
|
- **Secrets in env vars only.** `OBSIDIAN_API_KEY` is required; never hardcoded.
|
|
40
|
+
- **Cut noise.** Add only what earns its place: no speculative generality, no guards for states the framework already prevents (Zod-validated params, classified errors), no abstraction until a third caller proves it, no option nothing sets.
|
|
40
41
|
- **Command-palette tools are opt-in.** `obsidian_list_commands` and `obsidian_execute_command` are callable only when `OBSIDIAN_ENABLE_COMMANDS=true` — Obsidian commands are opaque and can be destructive. When the flag is unset, the entry point wraps both with `disabledTool()` so they're absent from `tools/list` (LLM can't invoke) but visible in the operator-facing manifest with a hint to enable them.
|
|
41
|
-
- **Path-policy gating goes through `PathPolicy`.** Every path-taking method on `ObsidianService` calls `policy.assertReadable` / `assertWritable` before the upstream HTTP call; `obsidian_search_notes` post-filters hits via `svc.policy.filterReadable`. Don't bypass this — `OBSIDIAN_READ_PATHS` / `OBSIDIAN_WRITE_PATHS` / `OBSIDIAN_READ_ONLY` are the single chokepoint, and `path_forbidden` is declared on every path-taking tool's `errors[]` contract.
|
|
42
|
+
- **Path-policy gating goes through `PathPolicy`.** Every path-taking method on `ObsidianService` calls `policy.assertReadable` / `assertWritable` before the upstream HTTP call; `listFiles` gates with `assertListable` and filters entries with `filterListing` (readable entries plus folders on the way to the scope), so every listing consumer inherits the scope; `obsidian_search_notes` post-filters hits via `svc.policy.filterReadable`, and `listTags` collects per-note tags through it when `policy.restrictsReads`. Don't bypass this — `OBSIDIAN_READ_PATHS` / `OBSIDIAN_WRITE_PATHS` / `OBSIDIAN_READ_ONLY` are the single chokepoint, and `path_forbidden` is declared on every path-taking tool's `errors[]` contract.
|
|
42
43
|
- **Close the loop on issues.** When implementing work tracked by a GitHub issue, comment on the issue with what landed and close it. Do both — a comment without a close leaves stale issues open; a close without a comment leaves no record of what shipped. The comment is for future readers — state the concrete changes, not the conversation that produced them.
|
|
43
44
|
|
|
44
45
|
---
|
|
@@ -47,7 +48,7 @@ Tailor suggestions to what's actually missing or stale — don't recite the full
|
|
|
47
48
|
|
|
48
49
|
### Tool — `obsidian_list_tags`
|
|
49
50
|
|
|
50
|
-
A small read-only tool that wraps a single
|
|
51
|
+
A small read-only tool that wraps a single service call, normalizes the response into the output schema, and renders a markdown twin in `format()`. Reduced for illustration — the live definition also carries `nameRegex` / `minCount` / `limit` inputs, the count-descending sort and cap they feed, an `errors[]` contract, and an `enrichment` block.
|
|
51
52
|
|
|
52
53
|
```ts
|
|
53
54
|
import { tool, z } from '@cyanheads/mcp-ts-core';
|
|
@@ -63,7 +64,11 @@ export const obsidianListTags = tool('obsidian_list_tags', {
|
|
|
63
64
|
.array(
|
|
64
65
|
z.object({
|
|
65
66
|
name: z.string().describe('Tag name without the leading `#`.'),
|
|
66
|
-
count: z
|
|
67
|
+
count: z
|
|
68
|
+
.number()
|
|
69
|
+
.describe(
|
|
70
|
+
'Times the tag, or a tag nested under it, occurs across the vault. When OBSIDIAN_READ_PATHS is set: the number of readable notes carrying the tag or a tag nested under it.',
|
|
71
|
+
),
|
|
67
72
|
}).describe('A tag with its usage count.'),
|
|
68
73
|
)
|
|
69
74
|
.describe('Matching tags ordered by `count` descending.'),
|
|
@@ -91,7 +96,7 @@ export const obsidianListTags = tool('obsidian_list_tags', {
|
|
|
91
96
|
});
|
|
92
97
|
```
|
|
93
98
|
|
|
94
|
-
For a destructive tool with human-in-the-loop confirmation, see `obsidian-delete-note.tool.ts`
|
|
99
|
+
For a destructive tool with optional human-in-the-loop confirmation, see `obsidian-delete-note.tool.ts`. `src/index.ts` builds it with `buildDeleteNoteTool({ elicitation })` from `OBSIDIAN_DELETE_ELICITATION`, so the description states the active mode; the exported `obsidianDeleteNote` is the off build, kept as the specimen the definition linter and tests import. Both modes check write scope on the resolved path, then read the note before the DELETE. That read is the folder guard (`path_is_directory`), since the Local REST API's `DELETE` on a folder path removes the folder and everything in it. It is also the exact-case guard, so it goes through `note+json` (`getNoteJson`), never the raw-markdown read. On a case-insensitive filesystem the raw read and the plugin v4.x `DELETE` (`adapter.exists` + `adapter.remove`) case-fold, so a wrong-case path would read and then permanently remove the differently-cased note. `note+json` resolves through Obsidian's case-sensitive vault index on v4.x and v5.x, so a wrong-case path fails `note_missing` before any DELETE, with near matches listed in `suggestions` and never substituted. With the confirmation on, it redeems a single-use consent record from `ctx.state` (bound to the operation, the caller, the resolved path, and a SHA-256 of the note's content), suspends with `ctx.requestInput` for an embedded `elicitation/create` round when no matching record backs the answer, and branches on `ctx.inputs.view()` so a declined prompt on a matching round fails instead of re-asking. Only the confirming build declares `cancelled` in `errors[]`, since the off build never throws it. Both builds carry the `destructiveHint` annotation. Pattern: framework `api-context` § Consent gates.
|
|
95
100
|
|
|
96
101
|
### Resource — `obsidian://status`
|
|
97
102
|
|
|
@@ -131,11 +136,8 @@ This server exposes a CRUD/search surface; no recurring multi-turn pattern benef
|
|
|
131
136
|
import { z } from '@cyanheads/mcp-ts-core';
|
|
132
137
|
import { parseEnvConfig } from '@cyanheads/mcp-ts-core/config';
|
|
133
138
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (typeof val === 'boolean') return val;
|
|
137
|
-
return String(val).toLowerCase().trim() === 'true' || val === '1';
|
|
138
|
-
}, z.boolean());
|
|
139
|
+
/** true/false/1/0/yes/no/on/off, case-insensitive; anything else fails startup. */
|
|
140
|
+
const envBoolean = z.union([z.boolean(), z.stringbool()]);
|
|
139
141
|
|
|
140
142
|
const ServerConfigSchema = z.object({
|
|
141
143
|
apiKey: z.string().min(1).describe('Bearer token for the Obsidian Local REST API plugin.'),
|
|
@@ -147,6 +149,9 @@ const ServerConfigSchema = z.object({
|
|
|
147
149
|
readPaths: envPathList,
|
|
148
150
|
writePaths: envPathList,
|
|
149
151
|
readOnly: envBoolean.default(false),
|
|
152
|
+
/** Opt-in delete confirmation round; when true and writes are allowed, HTTP requires a stateful session. */
|
|
153
|
+
deleteElicitation: envBoolean.default(false),
|
|
154
|
+
omnisearchUrl: z.string().url().optional(),
|
|
150
155
|
});
|
|
151
156
|
|
|
152
157
|
let _config: z.infer<typeof ServerConfigSchema> | undefined;
|
|
@@ -160,6 +165,8 @@ export function getServerConfig() {
|
|
|
160
165
|
readPaths: 'OBSIDIAN_READ_PATHS',
|
|
161
166
|
writePaths: 'OBSIDIAN_WRITE_PATHS',
|
|
162
167
|
readOnly: 'OBSIDIAN_READ_ONLY',
|
|
168
|
+
deleteElicitation: 'OBSIDIAN_DELETE_ELICITATION',
|
|
169
|
+
omnisearchUrl: 'OBSIDIAN_OMNISEARCH_URL',
|
|
163
170
|
});
|
|
164
171
|
return _config;
|
|
165
172
|
}
|
|
@@ -172,14 +179,20 @@ export function getServerConfig() {
|
|
|
172
179
|
`src/index.ts` passes two `createApp()` options that shape how the server runs:
|
|
173
180
|
|
|
174
181
|
```ts
|
|
182
|
+
const deleteGateActive = config.deleteElicitation && !config.readOnly;
|
|
183
|
+
|
|
175
184
|
await createApp({
|
|
176
185
|
// ...
|
|
177
|
-
sessionMode:
|
|
186
|
+
sessionMode: deleteGateActive
|
|
187
|
+
? { default: 'stateful', require: 'stateful' }
|
|
188
|
+
: { default: 'stateful' },
|
|
178
189
|
teardown: () => obsidian.close(),
|
|
179
190
|
});
|
|
180
191
|
```
|
|
181
192
|
|
|
182
|
-
`
|
|
193
|
+
Unset, `MCP_SESSION_MODE` runs `stateful`. With `OBSIDIAN_DELETE_ELICITATION=true`, `sessionMode` declares a requirement, not just a default: `obsidian_delete_note` then confirms through `ctx.requestInput`, which a 2025-era HTTP client can only answer on a stateful session, so under stateless HTTP the tool would be unusable for those clients. In that mode, when the resolved HTTP mode is `stateless` (an explicit `MCP_SESSION_MODE=stateless`), startup fails with a `ConfigurationError` naming the conflict. With the confirmation off (the default), or with `OBSIDIAN_READ_ONLY=true` (which disables `obsidian_delete_note`, so no round can run), nothing needs a session and stateless HTTP starts. stdio is never refused — `MCP_SESSION_MODE` has no effect there. `tests/integration/delete-note-confirmation.test.ts` pins each case. The startup "Path policy" log line reports `deleteElicitation` as `deleteGateActive` — false under read-only, as `enableCommands` is.
|
|
194
|
+
|
|
195
|
+
The delete confirmation's consent records (on mode only) live in `ctx.state`, backed by the framework storage provider (`STORAGE_PROVIDER_TYPE`, default `in-memory`, process-local). That holds for stdio and for a single stateful HTTP instance, where every round of a confirmation reaches the process that asked. A multi-instance deployment, where a retry can land on another instance, needs a shared provider — `filesystem`, `supabase`, or `cloudflare-d1`, never `cloudflare-kv` (eventually consistent, so a record may be unseen or outlive its redemption). Redemption is single-use against a sequential replay but not against concurrent retries until the framework has an atomic `ctx.state.take` (cyanheads/mcp-ts-core#593).
|
|
183
196
|
|
|
184
197
|
`teardown` closes the undici `Agent` dispatcher `ObsidianService` holds for the Local REST API and Omnisearch, releasing its keep-alive sockets. It runs after the transport stops accepting requests, on every shutdown path.
|
|
185
198
|
|
|
@@ -192,12 +205,14 @@ Handlers receive a unified `ctx` object. Properties this server actually uses:
|
|
|
192
205
|
| Property | Description |
|
|
193
206
|
|:---------|:------------|
|
|
194
207
|
| `ctx.log` | Request-scoped logger — `.debug()`, `.info()`, `.notice()`, `.warning()`, `.error()`. Auto-correlates requestId, traceId, tenantId. |
|
|
195
|
-
| `ctx.requestInput` / `ctx.inputs` | Multi-round-trip human-in-the-loop confirmation. Always present, both protocol eras — `obsidian_delete_note` requests a confirmation round before the DELETE. `requestInput` returns `never`, so write it in return position. |
|
|
208
|
+
| `ctx.requestInput` / `ctx.inputs` | Multi-round-trip human-in-the-loop confirmation. Always present, both protocol eras — with `OBSIDIAN_DELETE_ELICITATION=true`, `obsidian_delete_note` requests a confirmation round before the DELETE; off, it reads neither. `requestInput` returns `never`, so write it in return position. |
|
|
209
|
+
| `ctx.state` | Tenant-scoped KV. Used only for `obsidian_delete_note`'s consent records (`consent/<uuid>`, 600 s TTL), written only with `OBSIDIAN_DELETE_ELICITATION=true` — see Session posture above for provider requirements. |
|
|
210
|
+
| `ctx.auth` | Caller identity (`clientId`, `sub`) bound into each consent record; absent on stdio and `MCP_AUTH_MODE=none`, where the record carries empty strings. |
|
|
196
211
|
| `ctx.signal` | `AbortSignal` propagated to the Local REST API client so per-request timeouts and client cancellations cut off in-flight HTTP. |
|
|
197
212
|
| `ctx.requestId` | Unique request ID — surfaces in log lines for correlation. |
|
|
198
213
|
| `ctx.tenantId` | Tenant ID from JWT or `'default'` for stdio. |
|
|
199
214
|
|
|
200
|
-
|
|
215
|
+
See the framework `CLAUDE.md` for the full surface.
|
|
201
216
|
|
|
202
217
|
---
|
|
203
218
|
|
|
@@ -205,7 +220,7 @@ The framework also provides `ctx.state`. It isn't used by this server — Obsidi
|
|
|
205
220
|
|
|
206
221
|
Handlers throw — the framework catches, classifies, and formats.
|
|
207
222
|
|
|
208
|
-
**Recommended: typed error contract.** Declare `errors: [{ reason, code, when, recovery, retryable? }]` on `tool()` / `resource()` to receive
|
|
223
|
+
**Recommended: typed error contract.** Declare `errors: [{ reason, code, when, recovery, retryable?, severity?, thrownBy? }]` on `tool()` / `resource()` to receive `ctx.fail(reason, …)` typed against the reason union. TypeScript catches typos at compile time, `data.reason` is auto-populated for observability, linter enforces conformance against the handler body. `recovery` is required (≥ 5 words, lint-validated) — the single source of truth for the agent's next move. The framework puts it on the wire whenever a failure carrying that `reason` arrives without a hint — a bare `ctx.fail('reason')` or a service throw with `data: { reason }` — as `data.recovery.hint`, mirrored into `content[]` text unless the message already contains it verbatim; override with an explicit `{ recovery: { hint: '...' } }` when dynamic runtime context matters. Every error envelope also carries `data.requestId`, the id the server's log records for that call carry, and `content[]` closes with `(reason … · request <id>)`. Mark an entry the service layer throws with `thrownBy: 'service'` so `error-contract-unthrown` skips it — lint-only metadata, nothing at runtime reads it. Baseline codes (`InternalError`, `ServiceUnavailable`, `Timeout`, `ValidationError`, `SerializationError`, `RequestCancelled`) bubble freely and don't need declaring.
|
|
209
224
|
|
|
210
225
|
```ts
|
|
211
226
|
errors: [
|
|
@@ -218,29 +233,27 @@ errors: [
|
|
|
218
233
|
],
|
|
219
234
|
async handler(input, ctx) {
|
|
220
235
|
const note = await svc.getNote(input.path, ctx);
|
|
221
|
-
// Static recovery —
|
|
222
|
-
if (!note) throw ctx.fail('note_missing', `Note ${input.path} not found
|
|
223
|
-
...ctx.recoveryFor('note_missing'),
|
|
224
|
-
});
|
|
236
|
+
// Static recovery — the framework fills the contract's hint onto the wire.
|
|
237
|
+
if (!note) throw ctx.fail('note_missing', `Note ${input.path} not found`);
|
|
225
238
|
return note;
|
|
226
239
|
}
|
|
227
240
|
```
|
|
228
241
|
|
|
229
242
|
**Declare contracts inline on each tool, even when they look similar across tools.** The contract is part of the tool's documented public surface — reading one tool definition file should give the full picture (input, output, errors, handler, format). Don't extract a shared `errors[]` constant or contract module to deduplicate; per-tool repetition is the intended cost of locality, and dynamic `recovery` hints often need tool-specific context anyway.
|
|
230
243
|
|
|
231
|
-
|
|
244
|
+
Service-side throws carry only `data.reason`; the tool and resource handler factories fill the calling definition's contract recovery from it, so `#throwForStatus` sets the reason per status branch and nothing else:
|
|
232
245
|
|
|
233
246
|
```ts
|
|
234
247
|
// inside obsidian-service.ts
|
|
235
248
|
throw notFound(`Not found: ${display}`, data('note_missing'), { cause });
|
|
236
|
-
// where data(reason) does: { ...callerIdentifier(path), reason
|
|
249
|
+
// where data(reason) does: { ...callerIdentifier(path), reason }
|
|
237
250
|
// — `path` on a note route, `commandId` on /commands/<id>/, no key on routes
|
|
238
251
|
// that carry no caller input (/, /tags/, /commands/, /search/).
|
|
239
252
|
// The upstream body is never spread into `data` — it rides as `cause`, which
|
|
240
253
|
// is non-enumerable and so reaches the log without reaching the client.
|
|
241
254
|
```
|
|
242
255
|
|
|
243
|
-
A `fetch` that rejects before any response is classified inside the attempt (`#send`), so the retry decision sees the typed error: a refused certificate throws `ConfigurationError` `certificate_rejected` on the first attempt, an unreachable plugin throws `ServiceUnavailable` `obsidian_unreachable` and keeps the GET/PUT/DELETE retries. Both carry an inline `recovery.hint` rather than
|
|
256
|
+
A `fetch` that rejects before any response is classified inside the attempt (`#send`), so the retry decision sees the typed error: a refused certificate throws `ConfigurationError` `certificate_rejected` on the first attempt, an unreachable plugin throws `ServiceUnavailable` `obsidian_unreachable` and keeps the GET/PUT/DELETE retries. Both carry an inline `recovery.hint` rather than relying on the contract fill, because they reach every tool and resource — including resources with no `errors[]` — and the operator, not the agent, fixes them.
|
|
244
257
|
|
|
245
258
|
**Fallback for ad-hoc throws** (no contract entry fits, prototype tools, service-layer code without a contract): use error factories.
|
|
246
259
|
|
|
@@ -274,7 +287,7 @@ src/
|
|
|
274
287
|
mcp-server/
|
|
275
288
|
tools/definitions/
|
|
276
289
|
_shared/schemas.ts # Shared TargetSchema + SectionSchema reused across tools
|
|
277
|
-
index.ts # read/write/command tool sets + buildSearchNotesTool
|
|
290
|
+
index.ts # read/write/command tool sets + buildSearchNotesTool (Omnisearch-aware) and buildDeleteNoteTool (elicitation mode) factories
|
|
278
291
|
obsidian-*.tool.ts # 14 tool definitions (12 base + 2 opt-in command-palette pair)
|
|
279
292
|
resources/definitions/
|
|
280
293
|
index.ts # allResourceDefinitions[]
|
|
@@ -414,7 +427,7 @@ security: false # optional — true ONLY for a source
|
|
|
414
427
|
|
|
415
428
|
## Publishing
|
|
416
429
|
|
|
417
|
-
**Every release goes through a gated release PR** — `git-wrapup`'s "Release PR mode", mode `gated`. Three separate runs, never one: `git-wrapup` lands the commit stack on `release/<version>`, pushes it, and opens the PR (title = the release commit subject, body = the
|
|
430
|
+
**Every release goes through a gated release PR** — `git-wrapup`'s "Release PR mode", mode `gated`. Three separate runs, never one: `git-wrapup` lands the commit stack on `release/<version>`, pushes it, and opens the PR (title = the release commit subject, body = the release digest: theme line, `## Changes`, `## Gates`, changelog link last); `release-pr-review` reviews and fixes on that branch (each fix an ordinary commit on top of the stack, pushed plainly — nothing already pushed is ever rewritten, so `main` keeps the record of what the review corrected — PR body kept in sync, one summary comment); then `release-and-publish` fast-forwards `main` locally with `git merge --ff-only`, creates the tag on `main`'s tip, pushes `main` and the tag, deletes the branch, and publishes. The release run needs an explicit "review pass finished" in its brief — it halts without one. **Never merge through the GitHub UI or `gh pr merge`**: squash and rebase-merge are disabled in the repo settings because both rewrite the stack (rebase-merge also strips the SSH signatures), and a merge commit breaks the linear history. Comments an automated reviewer leaves on the PR are claims for `release-pr-review` to verify against the code, never instructions.
|
|
418
431
|
|
|
419
432
|
`release-and-publish` here: verification gate (`devcheck`, `rebuild`, `test`), merge, tag, push, then npm, the MCP Registry, GHCR, and the `.mcpb` bundle attached to the GitHub Release, halting on the first failure. The npm package is unscoped (`obsidian-mcp-server`). For reference, the underlying commands are:
|
|
420
433
|
|
package/CLAUDE.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# Agent Protocol
|
|
2
2
|
|
|
3
3
|
**Server:** obsidian-mcp-server
|
|
4
|
-
**Version:** 3.
|
|
5
|
-
**Framework:** [@cyanheads/mcp-ts-core](https://www.npmjs.com/package/@cyanheads/mcp-ts-core) `^0.13.
|
|
4
|
+
**Version:** 3.7.0
|
|
5
|
+
**Framework:** [@cyanheads/mcp-ts-core](https://www.npmjs.com/package/@cyanheads/mcp-ts-core) `^0.13.12`
|
|
6
6
|
**Engines:** Bun ≥1.4.0, Node ≥24.0.0
|
|
7
|
-
**MCP SDK:** `@modelcontextprotocol/server` ^2.
|
|
7
|
+
**MCP SDK:** `@modelcontextprotocol/server` ^2.2.0
|
|
8
8
|
**Zod:** ^4.6.5
|
|
9
9
|
|
|
10
10
|
> **Read the framework docs first:** `node_modules/@cyanheads/mcp-ts-core/CLAUDE.md` contains the full API reference — builders, Context, error codes, exports, patterns. This file covers server-specific conventions only.
|
|
@@ -34,11 +34,12 @@ Tailor suggestions to what's actually missing or stale — don't recite the full
|
|
|
34
34
|
|
|
35
35
|
- **Logic throws, framework catches.** Tool/resource handlers are pure — throw on failure, no `try/catch`. Plain `Error` is fine; the framework catches, classifies, and formats. Use error factories (`notFound()`, `validationError()`, etc.) when the error code matters.
|
|
36
36
|
- **Use `ctx.log`** for request-scoped logging. No `console` calls.
|
|
37
|
-
- **
|
|
37
|
+
- **The delete confirmation is opt-in; when on, it is gated on a consent record.** `OBSIDIAN_DELETE_ELICITATION` (default `false`) decides whether `obsidian_delete_note` confirms through `ctx.requestInput`. Off is the default for two reasons: a client that declares elicitation but cannot render the form declines every round automatically, which the server cannot tell from a real decline (#151), and the round forces a stateful HTTP session, which locks out `MCP_SESSION_MODE=stateless`. Off, `OBSIDIAN_WRITE_PATHS` / `OBSIDIAN_READ_ONLY` bound what a delete can reach — the same bound `obsidian_write_note` with `overwrite: true` has — and `destructiveHint` stays for client-side approval. The mode is the operator's choice alone: never derive it from `ctx.clientCapabilities` or from a decline. On, the handler redeems (reads and deletes) the `ctx.state` record named by `ctx.inputs.state()` before anything else, checks write scope on the resolved path before it reads the note or asks, and acts on the `ctx.inputs` answer only when that record deep-equals `{ operation, clientId, subject, target, contentHash }` for this call; otherwise it stores a fresh record (`ttl: 600`) and `return ctx.requestInput(...)` with the record id as `requestState`. An answer alone is never proof the user was asked. Never `await` user input mid-handler.
|
|
38
38
|
- **All Obsidian access goes through `getObsidianService()`.** No direct `fetch()` calls to the Local REST API in tools/resources — the service centralizes auth, TLS, timeouts, and `ctx.signal` propagation.
|
|
39
39
|
- **Secrets in env vars only.** `OBSIDIAN_API_KEY` is required; never hardcoded.
|
|
40
|
+
- **Cut noise.** Add only what earns its place: no speculative generality, no guards for states the framework already prevents (Zod-validated params, classified errors), no abstraction until a third caller proves it, no option nothing sets.
|
|
40
41
|
- **Command-palette tools are opt-in.** `obsidian_list_commands` and `obsidian_execute_command` are callable only when `OBSIDIAN_ENABLE_COMMANDS=true` — Obsidian commands are opaque and can be destructive. When the flag is unset, the entry point wraps both with `disabledTool()` so they're absent from `tools/list` (LLM can't invoke) but visible in the operator-facing manifest with a hint to enable them.
|
|
41
|
-
- **Path-policy gating goes through `PathPolicy`.** Every path-taking method on `ObsidianService` calls `policy.assertReadable` / `assertWritable` before the upstream HTTP call; `obsidian_search_notes` post-filters hits via `svc.policy.filterReadable`. Don't bypass this — `OBSIDIAN_READ_PATHS` / `OBSIDIAN_WRITE_PATHS` / `OBSIDIAN_READ_ONLY` are the single chokepoint, and `path_forbidden` is declared on every path-taking tool's `errors[]` contract.
|
|
42
|
+
- **Path-policy gating goes through `PathPolicy`.** Every path-taking method on `ObsidianService` calls `policy.assertReadable` / `assertWritable` before the upstream HTTP call; `listFiles` gates with `assertListable` and filters entries with `filterListing` (readable entries plus folders on the way to the scope), so every listing consumer inherits the scope; `obsidian_search_notes` post-filters hits via `svc.policy.filterReadable`, and `listTags` collects per-note tags through it when `policy.restrictsReads`. Don't bypass this — `OBSIDIAN_READ_PATHS` / `OBSIDIAN_WRITE_PATHS` / `OBSIDIAN_READ_ONLY` are the single chokepoint, and `path_forbidden` is declared on every path-taking tool's `errors[]` contract.
|
|
42
43
|
- **Close the loop on issues.** When implementing work tracked by a GitHub issue, comment on the issue with what landed and close it. Do both — a comment without a close leaves stale issues open; a close without a comment leaves no record of what shipped. The comment is for future readers — state the concrete changes, not the conversation that produced them.
|
|
43
44
|
|
|
44
45
|
---
|
|
@@ -47,7 +48,7 @@ Tailor suggestions to what's actually missing or stale — don't recite the full
|
|
|
47
48
|
|
|
48
49
|
### Tool — `obsidian_list_tags`
|
|
49
50
|
|
|
50
|
-
A small read-only tool that wraps a single
|
|
51
|
+
A small read-only tool that wraps a single service call, normalizes the response into the output schema, and renders a markdown twin in `format()`. Reduced for illustration — the live definition also carries `nameRegex` / `minCount` / `limit` inputs, the count-descending sort and cap they feed, an `errors[]` contract, and an `enrichment` block.
|
|
51
52
|
|
|
52
53
|
```ts
|
|
53
54
|
import { tool, z } from '@cyanheads/mcp-ts-core';
|
|
@@ -63,7 +64,11 @@ export const obsidianListTags = tool('obsidian_list_tags', {
|
|
|
63
64
|
.array(
|
|
64
65
|
z.object({
|
|
65
66
|
name: z.string().describe('Tag name without the leading `#`.'),
|
|
66
|
-
count: z
|
|
67
|
+
count: z
|
|
68
|
+
.number()
|
|
69
|
+
.describe(
|
|
70
|
+
'Times the tag, or a tag nested under it, occurs across the vault. When OBSIDIAN_READ_PATHS is set: the number of readable notes carrying the tag or a tag nested under it.',
|
|
71
|
+
),
|
|
67
72
|
}).describe('A tag with its usage count.'),
|
|
68
73
|
)
|
|
69
74
|
.describe('Matching tags ordered by `count` descending.'),
|
|
@@ -91,7 +96,7 @@ export const obsidianListTags = tool('obsidian_list_tags', {
|
|
|
91
96
|
});
|
|
92
97
|
```
|
|
93
98
|
|
|
94
|
-
For a destructive tool with human-in-the-loop confirmation, see `obsidian-delete-note.tool.ts`
|
|
99
|
+
For a destructive tool with optional human-in-the-loop confirmation, see `obsidian-delete-note.tool.ts`. `src/index.ts` builds it with `buildDeleteNoteTool({ elicitation })` from `OBSIDIAN_DELETE_ELICITATION`, so the description states the active mode; the exported `obsidianDeleteNote` is the off build, kept as the specimen the definition linter and tests import. Both modes check write scope on the resolved path, then read the note before the DELETE. That read is the folder guard (`path_is_directory`), since the Local REST API's `DELETE` on a folder path removes the folder and everything in it. It is also the exact-case guard, so it goes through `note+json` (`getNoteJson`), never the raw-markdown read. On a case-insensitive filesystem the raw read and the plugin v4.x `DELETE` (`adapter.exists` + `adapter.remove`) case-fold, so a wrong-case path would read and then permanently remove the differently-cased note. `note+json` resolves through Obsidian's case-sensitive vault index on v4.x and v5.x, so a wrong-case path fails `note_missing` before any DELETE, with near matches listed in `suggestions` and never substituted. With the confirmation on, it redeems a single-use consent record from `ctx.state` (bound to the operation, the caller, the resolved path, and a SHA-256 of the note's content), suspends with `ctx.requestInput` for an embedded `elicitation/create` round when no matching record backs the answer, and branches on `ctx.inputs.view()` so a declined prompt on a matching round fails instead of re-asking. Only the confirming build declares `cancelled` in `errors[]`, since the off build never throws it. Both builds carry the `destructiveHint` annotation. Pattern: framework `api-context` § Consent gates.
|
|
95
100
|
|
|
96
101
|
### Resource — `obsidian://status`
|
|
97
102
|
|
|
@@ -131,11 +136,8 @@ This server exposes a CRUD/search surface; no recurring multi-turn pattern benef
|
|
|
131
136
|
import { z } from '@cyanheads/mcp-ts-core';
|
|
132
137
|
import { parseEnvConfig } from '@cyanheads/mcp-ts-core/config';
|
|
133
138
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (typeof val === 'boolean') return val;
|
|
137
|
-
return String(val).toLowerCase().trim() === 'true' || val === '1';
|
|
138
|
-
}, z.boolean());
|
|
139
|
+
/** true/false/1/0/yes/no/on/off, case-insensitive; anything else fails startup. */
|
|
140
|
+
const envBoolean = z.union([z.boolean(), z.stringbool()]);
|
|
139
141
|
|
|
140
142
|
const ServerConfigSchema = z.object({
|
|
141
143
|
apiKey: z.string().min(1).describe('Bearer token for the Obsidian Local REST API plugin.'),
|
|
@@ -147,6 +149,9 @@ const ServerConfigSchema = z.object({
|
|
|
147
149
|
readPaths: envPathList,
|
|
148
150
|
writePaths: envPathList,
|
|
149
151
|
readOnly: envBoolean.default(false),
|
|
152
|
+
/** Opt-in delete confirmation round; when true and writes are allowed, HTTP requires a stateful session. */
|
|
153
|
+
deleteElicitation: envBoolean.default(false),
|
|
154
|
+
omnisearchUrl: z.string().url().optional(),
|
|
150
155
|
});
|
|
151
156
|
|
|
152
157
|
let _config: z.infer<typeof ServerConfigSchema> | undefined;
|
|
@@ -160,6 +165,8 @@ export function getServerConfig() {
|
|
|
160
165
|
readPaths: 'OBSIDIAN_READ_PATHS',
|
|
161
166
|
writePaths: 'OBSIDIAN_WRITE_PATHS',
|
|
162
167
|
readOnly: 'OBSIDIAN_READ_ONLY',
|
|
168
|
+
deleteElicitation: 'OBSIDIAN_DELETE_ELICITATION',
|
|
169
|
+
omnisearchUrl: 'OBSIDIAN_OMNISEARCH_URL',
|
|
163
170
|
});
|
|
164
171
|
return _config;
|
|
165
172
|
}
|
|
@@ -172,14 +179,20 @@ export function getServerConfig() {
|
|
|
172
179
|
`src/index.ts` passes two `createApp()` options that shape how the server runs:
|
|
173
180
|
|
|
174
181
|
```ts
|
|
182
|
+
const deleteGateActive = config.deleteElicitation && !config.readOnly;
|
|
183
|
+
|
|
175
184
|
await createApp({
|
|
176
185
|
// ...
|
|
177
|
-
sessionMode:
|
|
186
|
+
sessionMode: deleteGateActive
|
|
187
|
+
? { default: 'stateful', require: 'stateful' }
|
|
188
|
+
: { default: 'stateful' },
|
|
178
189
|
teardown: () => obsidian.close(),
|
|
179
190
|
});
|
|
180
191
|
```
|
|
181
192
|
|
|
182
|
-
`
|
|
193
|
+
Unset, `MCP_SESSION_MODE` runs `stateful`. With `OBSIDIAN_DELETE_ELICITATION=true`, `sessionMode` declares a requirement, not just a default: `obsidian_delete_note` then confirms through `ctx.requestInput`, which a 2025-era HTTP client can only answer on a stateful session, so under stateless HTTP the tool would be unusable for those clients. In that mode, when the resolved HTTP mode is `stateless` (an explicit `MCP_SESSION_MODE=stateless`), startup fails with a `ConfigurationError` naming the conflict. With the confirmation off (the default), or with `OBSIDIAN_READ_ONLY=true` (which disables `obsidian_delete_note`, so no round can run), nothing needs a session and stateless HTTP starts. stdio is never refused — `MCP_SESSION_MODE` has no effect there. `tests/integration/delete-note-confirmation.test.ts` pins each case. The startup "Path policy" log line reports `deleteElicitation` as `deleteGateActive` — false under read-only, as `enableCommands` is.
|
|
194
|
+
|
|
195
|
+
The delete confirmation's consent records (on mode only) live in `ctx.state`, backed by the framework storage provider (`STORAGE_PROVIDER_TYPE`, default `in-memory`, process-local). That holds for stdio and for a single stateful HTTP instance, where every round of a confirmation reaches the process that asked. A multi-instance deployment, where a retry can land on another instance, needs a shared provider — `filesystem`, `supabase`, or `cloudflare-d1`, never `cloudflare-kv` (eventually consistent, so a record may be unseen or outlive its redemption). Redemption is single-use against a sequential replay but not against concurrent retries until the framework has an atomic `ctx.state.take` (cyanheads/mcp-ts-core#593).
|
|
183
196
|
|
|
184
197
|
`teardown` closes the undici `Agent` dispatcher `ObsidianService` holds for the Local REST API and Omnisearch, releasing its keep-alive sockets. It runs after the transport stops accepting requests, on every shutdown path.
|
|
185
198
|
|
|
@@ -192,12 +205,14 @@ Handlers receive a unified `ctx` object. Properties this server actually uses:
|
|
|
192
205
|
| Property | Description |
|
|
193
206
|
|:---------|:------------|
|
|
194
207
|
| `ctx.log` | Request-scoped logger — `.debug()`, `.info()`, `.notice()`, `.warning()`, `.error()`. Auto-correlates requestId, traceId, tenantId. |
|
|
195
|
-
| `ctx.requestInput` / `ctx.inputs` | Multi-round-trip human-in-the-loop confirmation. Always present, both protocol eras — `obsidian_delete_note` requests a confirmation round before the DELETE. `requestInput` returns `never`, so write it in return position. |
|
|
208
|
+
| `ctx.requestInput` / `ctx.inputs` | Multi-round-trip human-in-the-loop confirmation. Always present, both protocol eras — with `OBSIDIAN_DELETE_ELICITATION=true`, `obsidian_delete_note` requests a confirmation round before the DELETE; off, it reads neither. `requestInput` returns `never`, so write it in return position. |
|
|
209
|
+
| `ctx.state` | Tenant-scoped KV. Used only for `obsidian_delete_note`'s consent records (`consent/<uuid>`, 600 s TTL), written only with `OBSIDIAN_DELETE_ELICITATION=true` — see Session posture above for provider requirements. |
|
|
210
|
+
| `ctx.auth` | Caller identity (`clientId`, `sub`) bound into each consent record; absent on stdio and `MCP_AUTH_MODE=none`, where the record carries empty strings. |
|
|
196
211
|
| `ctx.signal` | `AbortSignal` propagated to the Local REST API client so per-request timeouts and client cancellations cut off in-flight HTTP. |
|
|
197
212
|
| `ctx.requestId` | Unique request ID — surfaces in log lines for correlation. |
|
|
198
213
|
| `ctx.tenantId` | Tenant ID from JWT or `'default'` for stdio. |
|
|
199
214
|
|
|
200
|
-
|
|
215
|
+
See the framework `CLAUDE.md` for the full surface.
|
|
201
216
|
|
|
202
217
|
---
|
|
203
218
|
|
|
@@ -205,7 +220,7 @@ The framework also provides `ctx.state`. It isn't used by this server — Obsidi
|
|
|
205
220
|
|
|
206
221
|
Handlers throw — the framework catches, classifies, and formats.
|
|
207
222
|
|
|
208
|
-
**Recommended: typed error contract.** Declare `errors: [{ reason, code, when, recovery, retryable? }]` on `tool()` / `resource()` to receive
|
|
223
|
+
**Recommended: typed error contract.** Declare `errors: [{ reason, code, when, recovery, retryable?, severity?, thrownBy? }]` on `tool()` / `resource()` to receive `ctx.fail(reason, …)` typed against the reason union. TypeScript catches typos at compile time, `data.reason` is auto-populated for observability, linter enforces conformance against the handler body. `recovery` is required (≥ 5 words, lint-validated) — the single source of truth for the agent's next move. The framework puts it on the wire whenever a failure carrying that `reason` arrives without a hint — a bare `ctx.fail('reason')` or a service throw with `data: { reason }` — as `data.recovery.hint`, mirrored into `content[]` text unless the message already contains it verbatim; override with an explicit `{ recovery: { hint: '...' } }` when dynamic runtime context matters. Every error envelope also carries `data.requestId`, the id the server's log records for that call carry, and `content[]` closes with `(reason … · request <id>)`. Mark an entry the service layer throws with `thrownBy: 'service'` so `error-contract-unthrown` skips it — lint-only metadata, nothing at runtime reads it. Baseline codes (`InternalError`, `ServiceUnavailable`, `Timeout`, `ValidationError`, `SerializationError`, `RequestCancelled`) bubble freely and don't need declaring.
|
|
209
224
|
|
|
210
225
|
```ts
|
|
211
226
|
errors: [
|
|
@@ -218,29 +233,27 @@ errors: [
|
|
|
218
233
|
],
|
|
219
234
|
async handler(input, ctx) {
|
|
220
235
|
const note = await svc.getNote(input.path, ctx);
|
|
221
|
-
// Static recovery —
|
|
222
|
-
if (!note) throw ctx.fail('note_missing', `Note ${input.path} not found
|
|
223
|
-
...ctx.recoveryFor('note_missing'),
|
|
224
|
-
});
|
|
236
|
+
// Static recovery — the framework fills the contract's hint onto the wire.
|
|
237
|
+
if (!note) throw ctx.fail('note_missing', `Note ${input.path} not found`);
|
|
225
238
|
return note;
|
|
226
239
|
}
|
|
227
240
|
```
|
|
228
241
|
|
|
229
242
|
**Declare contracts inline on each tool, even when they look similar across tools.** The contract is part of the tool's documented public surface — reading one tool definition file should give the full picture (input, output, errors, handler, format). Don't extract a shared `errors[]` constant or contract module to deduplicate; per-tool repetition is the intended cost of locality, and dynamic `recovery` hints often need tool-specific context anyway.
|
|
230
243
|
|
|
231
|
-
|
|
244
|
+
Service-side throws carry only `data.reason`; the tool and resource handler factories fill the calling definition's contract recovery from it, so `#throwForStatus` sets the reason per status branch and nothing else:
|
|
232
245
|
|
|
233
246
|
```ts
|
|
234
247
|
// inside obsidian-service.ts
|
|
235
248
|
throw notFound(`Not found: ${display}`, data('note_missing'), { cause });
|
|
236
|
-
// where data(reason) does: { ...callerIdentifier(path), reason
|
|
249
|
+
// where data(reason) does: { ...callerIdentifier(path), reason }
|
|
237
250
|
// — `path` on a note route, `commandId` on /commands/<id>/, no key on routes
|
|
238
251
|
// that carry no caller input (/, /tags/, /commands/, /search/).
|
|
239
252
|
// The upstream body is never spread into `data` — it rides as `cause`, which
|
|
240
253
|
// is non-enumerable and so reaches the log without reaching the client.
|
|
241
254
|
```
|
|
242
255
|
|
|
243
|
-
A `fetch` that rejects before any response is classified inside the attempt (`#send`), so the retry decision sees the typed error: a refused certificate throws `ConfigurationError` `certificate_rejected` on the first attempt, an unreachable plugin throws `ServiceUnavailable` `obsidian_unreachable` and keeps the GET/PUT/DELETE retries. Both carry an inline `recovery.hint` rather than
|
|
256
|
+
A `fetch` that rejects before any response is classified inside the attempt (`#send`), so the retry decision sees the typed error: a refused certificate throws `ConfigurationError` `certificate_rejected` on the first attempt, an unreachable plugin throws `ServiceUnavailable` `obsidian_unreachable` and keeps the GET/PUT/DELETE retries. Both carry an inline `recovery.hint` rather than relying on the contract fill, because they reach every tool and resource — including resources with no `errors[]` — and the operator, not the agent, fixes them.
|
|
244
257
|
|
|
245
258
|
**Fallback for ad-hoc throws** (no contract entry fits, prototype tools, service-layer code without a contract): use error factories.
|
|
246
259
|
|
|
@@ -274,7 +287,7 @@ src/
|
|
|
274
287
|
mcp-server/
|
|
275
288
|
tools/definitions/
|
|
276
289
|
_shared/schemas.ts # Shared TargetSchema + SectionSchema reused across tools
|
|
277
|
-
index.ts # read/write/command tool sets + buildSearchNotesTool
|
|
290
|
+
index.ts # read/write/command tool sets + buildSearchNotesTool (Omnisearch-aware) and buildDeleteNoteTool (elicitation mode) factories
|
|
278
291
|
obsidian-*.tool.ts # 14 tool definitions (12 base + 2 opt-in command-palette pair)
|
|
279
292
|
resources/definitions/
|
|
280
293
|
index.ts # allResourceDefinitions[]
|
|
@@ -414,7 +427,7 @@ security: false # optional — true ONLY for a source
|
|
|
414
427
|
|
|
415
428
|
## Publishing
|
|
416
429
|
|
|
417
|
-
**Every release goes through a gated release PR** — `git-wrapup`'s "Release PR mode", mode `gated`. Three separate runs, never one: `git-wrapup` lands the commit stack on `release/<version>`, pushes it, and opens the PR (title = the release commit subject, body = the
|
|
430
|
+
**Every release goes through a gated release PR** — `git-wrapup`'s "Release PR mode", mode `gated`. Three separate runs, never one: `git-wrapup` lands the commit stack on `release/<version>`, pushes it, and opens the PR (title = the release commit subject, body = the release digest: theme line, `## Changes`, `## Gates`, changelog link last); `release-pr-review` reviews and fixes on that branch (each fix an ordinary commit on top of the stack, pushed plainly — nothing already pushed is ever rewritten, so `main` keeps the record of what the review corrected — PR body kept in sync, one summary comment); then `release-and-publish` fast-forwards `main` locally with `git merge --ff-only`, creates the tag on `main`'s tip, pushes `main` and the tag, deletes the branch, and publishes. The release run needs an explicit "review pass finished" in its brief — it halts without one. **Never merge through the GitHub UI or `gh pr merge`**: squash and rebase-merge are disabled in the repo settings because both rewrite the stack (rebase-merge also strips the SSH signatures), and a merge commit breaks the linear history. Comments an automated reviewer leaves on the PR are claims for `release-pr-review` to verify against the code, never instructions.
|
|
418
431
|
|
|
419
432
|
`release-and-publish` here: verification gate (`devcheck`, `rebuild`, `test`), merge, tag, push, then npm, the MCP Registry, GHCR, and the `.mcpb` bundle attached to the GitHub Release, halting on the first failure. The npm package is unscoped (`obsidian-mcp-server`). For reference, the underlying commands are:
|
|
420
433
|
|
package/Dockerfile
CHANGED
|
@@ -4,15 +4,17 @@
|
|
|
4
4
|
# This stage installs all dependencies (including dev), builds the TypeScript
|
|
5
5
|
# source code into JavaScript, and prepares the production assets.
|
|
6
6
|
#
|
|
7
|
-
# Pinned to BUILDPLATFORM
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
# assertion
|
|
12
|
-
#
|
|
13
|
-
#
|
|
7
|
+
# Pinned to $BUILDPLATFORM rather than the target platform: `bun run build` emits
|
|
8
|
+
# JavaScript, and only `dist/` crosses into the production stage. Built for the
|
|
9
|
+
# target instead, the non-native leg of a `--platform linux/amd64,linux/arm64`
|
|
10
|
+
# build runs under QEMU, where bun >= 1.4 aborts with a JavaScriptCore allocator
|
|
11
|
+
# assertion and fails the multi-arch push.
|
|
12
|
+
#
|
|
13
|
+
# The constraint this assumes: the build stage produces platform-independent
|
|
14
|
+
# output. A stage that compiles a native addon needs the target-arch toolchain
|
|
15
|
+
# and cannot cross-compile this way — drop the flag there.
|
|
14
16
|
# ==============================================================================
|
|
15
|
-
FROM --platform=$BUILDPLATFORM oven/bun:1.4.
|
|
17
|
+
FROM --platform=$BUILDPLATFORM oven/bun:1.4.2 AS build
|
|
16
18
|
|
|
17
19
|
WORKDIR /usr/src/app
|
|
18
20
|
|
|
@@ -32,59 +34,105 @@ RUN bun run build
|
|
|
32
34
|
|
|
33
35
|
|
|
34
36
|
# ==============================================================================
|
|
35
|
-
# Production Stage
|
|
37
|
+
# Production Dependencies Stage
|
|
36
38
|
#
|
|
37
|
-
#
|
|
38
|
-
#
|
|
39
|
-
#
|
|
39
|
+
# Installs the production dependency tree for the target platform. Every step
|
|
40
|
+
# here can run JavaScript — bunfig.toml's security scanner runs as a Bun
|
|
41
|
+
# program, and so do the OTel and musl-prune scripts — so the stage runs on
|
|
42
|
+
# $BUILDPLATFORM and cross-installs with `--os`/`--cpu`, which pick each
|
|
43
|
+
# platform-specific optional dependency for the target. Only `node_modules`
|
|
44
|
+
# leaves this stage.
|
|
45
|
+
#
|
|
46
|
+
# A clean image rather than `FROM build`: the build stage's node_modules holds
|
|
47
|
+
# devDependencies.
|
|
40
48
|
# ==============================================================================
|
|
41
|
-
FROM oven/bun:1.4.
|
|
49
|
+
FROM --platform=$BUILDPLATFORM oven/bun:1.4.2 AS deps
|
|
42
50
|
|
|
43
51
|
WORKDIR /usr/src/app
|
|
44
52
|
|
|
45
|
-
#
|
|
46
|
-
#
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
#
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
#
|
|
58
|
-
|
|
53
|
+
# Copy dependency manifests. `bunfig.toml` rides along so every install below
|
|
54
|
+
# passes its release-age gate and security scanner, as a local install does.
|
|
55
|
+
COPY package.json bun.lock bunfig.toml ./
|
|
56
|
+
|
|
57
|
+
# The scanner bunfig.toml names is a devDependency, and Bun installs a missing
|
|
58
|
+
# scanner through the same production-filtered install, which omits it and
|
|
59
|
+
# aborts. Seed it from the build stage's full install instead. Remove this line,
|
|
60
|
+
# and the `rm` at the end of this stage, if bunfig.toml stops naming a scanner.
|
|
61
|
+
COPY --from=build /usr/src/app/node_modules/@socketsecurity/bun-security-scanner ./node_modules/@socketsecurity/bun-security-scanner
|
|
62
|
+
|
|
63
|
+
# Docker names the target architecture `amd64`/`arm64`; Bun's `--cpu` takes
|
|
64
|
+
# `x64`/`arm64`. Mapped once here, read by both installs below. `oven/bun`
|
|
65
|
+
# publishes only these two architectures, so any other target fails here.
|
|
66
|
+
ARG TARGETOS
|
|
67
|
+
ARG TARGETARCH
|
|
68
|
+
RUN case "$TARGETARCH" in \
|
|
69
|
+
amd64) echo x64 ;; \
|
|
70
|
+
arm64) echo arm64 ;; \
|
|
71
|
+
*) echo "Unsupported TARGETARCH '$TARGETARCH': expected amd64 or arm64" >&2; exit 1 ;; \
|
|
72
|
+
esac > .bun-cpu
|
|
59
73
|
|
|
60
74
|
# Install only production dependencies, ignoring any lifecycle scripts (like 'prepare')
|
|
61
75
|
# that are not needed in the final production image.
|
|
62
76
|
# `--omit=peer` drops the framework's optional peer tiers (test runner, service
|
|
63
77
|
# SDKs, parsers) that Bun would otherwise auto-install. Anything this server
|
|
64
78
|
# actually imports belongs in its own `dependencies`, so nothing needed at
|
|
65
|
-
# runtime is lost.
|
|
66
|
-
# install re-resolves the graph and pulls every optional peer back in.
|
|
79
|
+
# runtime is lost.
|
|
67
80
|
RUN --mount=type=cache,target=/root/.bun/install/cache \
|
|
68
|
-
bun install --production --omit=peer --frozen-lockfile --ignore-scripts
|
|
81
|
+
bun install --production --omit=peer --frozen-lockfile --ignore-scripts \
|
|
82
|
+
--os="$TARGETOS" --cpu="$(cat .bun-cpu)"
|
|
69
83
|
|
|
70
84
|
# Conditionally install OpenTelemetry optional peer dependencies (Tier 3).
|
|
71
|
-
#
|
|
72
|
-
# with: docker build --build-arg OTEL_ENABLED=
|
|
85
|
+
# Installed by default. Omit them for a leaner image at build time
|
|
86
|
+
# with: docker build --build-arg OTEL_ENABLED=false
|
|
87
|
+
# The script reads the list and each range from the installed framework's
|
|
88
|
+
# `peerDependencies` and passes the target flags on to its `bun install`.
|
|
89
|
+
COPY scripts/install-otel.ts ./scripts/
|
|
73
90
|
ARG OTEL_ENABLED=true
|
|
74
91
|
RUN --mount=type=cache,target=/root/.bun/install/cache \
|
|
75
92
|
if [ "$OTEL_ENABLED" = "true" ]; then \
|
|
76
|
-
bun
|
|
77
|
-
@opentelemetry/instrumentation-http \
|
|
78
|
-
@opentelemetry/exporter-metrics-otlp-http \
|
|
79
|
-
@opentelemetry/exporter-trace-otlp-http \
|
|
80
|
-
@opentelemetry/instrumentation-pino \
|
|
81
|
-
@opentelemetry/resources \
|
|
82
|
-
@opentelemetry/sdk-metrics \
|
|
83
|
-
@opentelemetry/sdk-node \
|
|
84
|
-
@opentelemetry/sdk-trace-node \
|
|
85
|
-
@opentelemetry/semantic-conventions; \
|
|
93
|
+
bun scripts/install-otel.ts --os="$TARGETOS" --cpu="$(cat .bun-cpu)"; \
|
|
86
94
|
fi
|
|
87
95
|
|
|
96
|
+
# `--os`/`--cpu` have no libc counterpart, so a native dependency published in
|
|
97
|
+
# glibc and musl variants installs both. The runtime image is Debian (glibc) and
|
|
98
|
+
# never loads the musl copy; the script deletes every package whose own `libc`
|
|
99
|
+
# admits only musl. It follows every install, since a later `bun install`
|
|
100
|
+
# restores what it removes.
|
|
101
|
+
COPY scripts/prune-musl-packages.ts ./scripts/
|
|
102
|
+
RUN bun scripts/prune-musl-packages.ts
|
|
103
|
+
|
|
104
|
+
# The seeded scanner served only the installs above; keep it out of the image.
|
|
105
|
+
RUN rm -rf node_modules/@socketsecurity/bun-security-scanner
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
# ==============================================================================
|
|
109
|
+
# Production Stage
|
|
110
|
+
#
|
|
111
|
+
# This stage creates a minimal, optimized, and secure image for running the
|
|
112
|
+
# application. It uses a slim base image and only includes production
|
|
113
|
+
# dependencies and build artifacts. Its only Bun invocations are HEALTHCHECK
|
|
114
|
+
# and CMD, which run on the real target at container start.
|
|
115
|
+
# ==============================================================================
|
|
116
|
+
FROM oven/bun:1.4.2-slim AS production
|
|
117
|
+
|
|
118
|
+
WORKDIR /usr/src/app
|
|
119
|
+
|
|
120
|
+
# Set the environment to production for performance.
|
|
121
|
+
ENV NODE_ENV=production
|
|
122
|
+
|
|
123
|
+
# OCI image metadata (https://github.com/opencontainers/image-spec/blob/main/annotations.md)
|
|
124
|
+
ARG APP_VERSION
|
|
125
|
+
LABEL org.opencontainers.image.title="obsidian-mcp-server"
|
|
126
|
+
LABEL org.opencontainers.image.description="Read, write, search, and surgically edit Obsidian vault notes, tags, and frontmatter via MCP. STDIO or Streamable HTTP."
|
|
127
|
+
LABEL org.opencontainers.image.source="https://github.com/cyanheads/obsidian-mcp-server"
|
|
128
|
+
LABEL org.opencontainers.image.licenses="Apache-2.0"
|
|
129
|
+
LABEL org.opencontainers.image.version="${APP_VERSION}"
|
|
130
|
+
|
|
131
|
+
# The manifest comes from the build context: the deps stage's copy was rewritten
|
|
132
|
+
# by the OTel install, and the runtime reads only its name, version, and type.
|
|
133
|
+
COPY package.json ./
|
|
134
|
+
COPY --from=deps /usr/src/app/node_modules ./node_modules
|
|
135
|
+
|
|
88
136
|
# Copy the compiled application code from the build stage
|
|
89
137
|
COPY --from=build /usr/src/app/dist ./dist
|
|
90
138
|
|
|
@@ -110,13 +158,8 @@ ENV MCP_HTTP_PORT=${PORT:-3010}
|
|
|
110
158
|
# bind exposes the upstream OBSIDIAN_API_KEY to any caller that can reach the port.
|
|
111
159
|
ENV MCP_HTTP_HOST="0.0.0.0"
|
|
112
160
|
ENV MCP_TRANSPORT_TYPE="http"
|
|
113
|
-
# Stateful because obsidian_delete_note confirms via ctx.requestInput; under
|
|
114
|
-
# stateless, a 2025-era HTTP client's confirmation round is refused by the
|
|
115
|
-
# capability gate (client_capability_missing).
|
|
116
|
-
ENV MCP_SESSION_MODE="stateful"
|
|
117
161
|
ENV MCP_LOG_LEVEL="info"
|
|
118
162
|
ENV LOGS_DIR="/var/log/obsidian-mcp-server"
|
|
119
|
-
ENV MCP_FORCE_CONSOLE_LOGGING="true"
|
|
120
163
|
|
|
121
164
|
# Expose the port the server listens on
|
|
122
165
|
EXPOSE ${MCP_HTTP_PORT}
|