obsidian-mcp-server 3.6.0 → 3.6.1
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 +20 -17
- package/CLAUDE.md +20 -17
- package/Dockerfile +90 -47
- package/README.md +121 -151
- package/changelog/3.6.x/3.6.1.md +29 -0
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/mcp-server/tools/definitions/_shared/suggest-paths.d.ts +2 -1
- package/dist/mcp-server/tools/definitions/_shared/suggest-paths.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/_shared/suggest-paths.js +2 -2
- package/dist/mcp-server/tools/definitions/_shared/suggest-paths.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 +2 -1
- 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 +61 -15
- 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.map +1 -1
- package/dist/mcp-server/tools/definitions/obsidian-get-note.tool.js +1 -2
- 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.map +1 -1
- package/dist/mcp-server/tools/definitions/obsidian-list-notes.tool.js +1 -2
- 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.map +1 -1
- package/dist/mcp-server/tools/definitions/obsidian-list-tags.tool.js +1 -2
- 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-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 +1 -4
- package/dist/mcp-server/tools/definitions/obsidian-search-notes.tool.js.map +1 -1
- package/dist/services/obsidian/obsidian-service.d.ts.map +1 -1
- package/dist/services/obsidian/obsidian-service.js +15 -20
- package/dist/services/obsidian/obsidian-service.js.map +1 -1
- package/manifest.json +1 -1
- package/package.json +13 -10
- package/server.json +10 -24
package/AGENTS.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# Agent Protocol
|
|
2
2
|
|
|
3
3
|
**Server:** obsidian-mcp-server
|
|
4
|
-
**Version:** 3.6.
|
|
5
|
-
**Framework:** [@cyanheads/mcp-ts-core](https://www.npmjs.com/package/@cyanheads/mcp-ts-core) `^0.13.
|
|
4
|
+
**Version:** 3.6.1
|
|
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,9 +34,10 @@ 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
|
-
- **Confirm destructive ops with `ctx.requestInput
|
|
37
|
+
- **Confirm destructive ops with `ctx.requestInput`, gated on a consent record.** `obsidian_delete_note` redeems (reads and deletes) the `ctx.state` record named by `ctx.inputs.state()` before anything else, 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
42
|
- **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
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.
|
|
@@ -91,7 +92,7 @@ export const obsidianListTags = tool('obsidian_list_tags', {
|
|
|
91
92
|
});
|
|
92
93
|
```
|
|
93
94
|
|
|
94
|
-
For a destructive tool with human-in-the-loop confirmation, see `obsidian-delete-note.tool.ts` — it suspends with `ctx.requestInput` for an embedded `elicitation/create` round, branches on `ctx.inputs.view()` so a declined prompt fails instead of re-asking, and carries the `destructiveHint` annotation.
|
|
95
|
+
For a destructive tool with human-in-the-loop confirmation, see `obsidian-delete-note.tool.ts` — 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, branches on `ctx.inputs.view()` so a declined prompt on a matching round fails instead of re-asking, and carries the `destructiveHint` annotation. Pattern: framework `api-context` § Consent gates.
|
|
95
96
|
|
|
96
97
|
### Resource — `obsidian://status`
|
|
97
98
|
|
|
@@ -174,12 +175,14 @@ export function getServerConfig() {
|
|
|
174
175
|
```ts
|
|
175
176
|
await createApp({
|
|
176
177
|
// ...
|
|
177
|
-
sessionMode: 'stateful',
|
|
178
|
+
sessionMode: { default: 'stateful', require: 'stateful' },
|
|
178
179
|
teardown: () => obsidian.close(),
|
|
179
180
|
});
|
|
180
181
|
```
|
|
181
182
|
|
|
182
|
-
`sessionMode
|
|
183
|
+
`sessionMode` declares a requirement, not just a default: `obsidian_delete_note` 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. Unset, `MCP_SESSION_MODE` runs `stateful`; when the resolved HTTP mode is `stateless` (an explicit `MCP_SESSION_MODE=stateless`), startup fails with a `ConfigurationError` naming the conflict. stdio is never refused — `MCP_SESSION_MODE` has no effect there. `tests/integration/delete-note-confirmation.test.ts` pins both.
|
|
184
|
+
|
|
185
|
+
The delete confirmation's consent records 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
186
|
|
|
184
187
|
`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
188
|
|
|
@@ -193,11 +196,13 @@ Handlers receive a unified `ctx` object. Properties this server actually uses:
|
|
|
193
196
|
|:---------|:------------|
|
|
194
197
|
| `ctx.log` | Request-scoped logger — `.debug()`, `.info()`, `.notice()`, `.warning()`, `.error()`. Auto-correlates requestId, traceId, tenantId. |
|
|
195
198
|
| `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. |
|
|
199
|
+
| `ctx.state` | Tenant-scoped KV. Used only for `obsidian_delete_note`'s consent records (`consent/<uuid>`, 600 s TTL) — see Session posture above for provider requirements. |
|
|
200
|
+
| `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
201
|
| `ctx.signal` | `AbortSignal` propagated to the Local REST API client so per-request timeouts and client cancellations cut off in-flight HTTP. |
|
|
197
202
|
| `ctx.requestId` | Unique request ID — surfaces in log lines for correlation. |
|
|
198
203
|
| `ctx.tenantId` | Tenant ID from JWT or `'default'` for stdio. |
|
|
199
204
|
|
|
200
|
-
|
|
205
|
+
See the framework `CLAUDE.md` for the full surface.
|
|
201
206
|
|
|
202
207
|
---
|
|
203
208
|
|
|
@@ -205,7 +210,7 @@ The framework also provides `ctx.state`. It isn't used by this server — Obsidi
|
|
|
205
210
|
|
|
206
211
|
Handlers throw — the framework catches, classifies, and formats.
|
|
207
212
|
|
|
208
|
-
**Recommended: typed error contract.** Declare `errors: [{ reason, code, when, recovery, retryable? }]` on `tool()` / `resource()` to receive
|
|
213
|
+
**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
214
|
|
|
210
215
|
```ts
|
|
211
216
|
errors: [
|
|
@@ -218,29 +223,27 @@ errors: [
|
|
|
218
223
|
],
|
|
219
224
|
async handler(input, ctx) {
|
|
220
225
|
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
|
-
});
|
|
226
|
+
// Static recovery — the framework fills the contract's hint onto the wire.
|
|
227
|
+
if (!note) throw ctx.fail('note_missing', `Note ${input.path} not found`);
|
|
225
228
|
return note;
|
|
226
229
|
}
|
|
227
230
|
```
|
|
228
231
|
|
|
229
232
|
**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
233
|
|
|
231
|
-
|
|
234
|
+
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
235
|
|
|
233
236
|
```ts
|
|
234
237
|
// inside obsidian-service.ts
|
|
235
238
|
throw notFound(`Not found: ${display}`, data('note_missing'), { cause });
|
|
236
|
-
// where data(reason) does: { ...callerIdentifier(path), reason
|
|
239
|
+
// where data(reason) does: { ...callerIdentifier(path), reason }
|
|
237
240
|
// — `path` on a note route, `commandId` on /commands/<id>/, no key on routes
|
|
238
241
|
// that carry no caller input (/, /tags/, /commands/, /search/).
|
|
239
242
|
// The upstream body is never spread into `data` — it rides as `cause`, which
|
|
240
243
|
// is non-enumerable and so reaches the log without reaching the client.
|
|
241
244
|
```
|
|
242
245
|
|
|
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
|
|
246
|
+
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
247
|
|
|
245
248
|
**Fallback for ad-hoc throws** (no contract entry fits, prototype tools, service-layer code without a contract): use error factories.
|
|
246
249
|
|
|
@@ -414,7 +417,7 @@ security: false # optional — true ONLY for a source
|
|
|
414
417
|
|
|
415
418
|
## Publishing
|
|
416
419
|
|
|
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
|
|
420
|
+
**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
421
|
|
|
419
422
|
`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
423
|
|
package/CLAUDE.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# Agent Protocol
|
|
2
2
|
|
|
3
3
|
**Server:** obsidian-mcp-server
|
|
4
|
-
**Version:** 3.6.
|
|
5
|
-
**Framework:** [@cyanheads/mcp-ts-core](https://www.npmjs.com/package/@cyanheads/mcp-ts-core) `^0.13.
|
|
4
|
+
**Version:** 3.6.1
|
|
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,9 +34,10 @@ 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
|
-
- **Confirm destructive ops with `ctx.requestInput
|
|
37
|
+
- **Confirm destructive ops with `ctx.requestInput`, gated on a consent record.** `obsidian_delete_note` redeems (reads and deletes) the `ctx.state` record named by `ctx.inputs.state()` before anything else, 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
42
|
- **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
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.
|
|
@@ -91,7 +92,7 @@ export const obsidianListTags = tool('obsidian_list_tags', {
|
|
|
91
92
|
});
|
|
92
93
|
```
|
|
93
94
|
|
|
94
|
-
For a destructive tool with human-in-the-loop confirmation, see `obsidian-delete-note.tool.ts` — it suspends with `ctx.requestInput` for an embedded `elicitation/create` round, branches on `ctx.inputs.view()` so a declined prompt fails instead of re-asking, and carries the `destructiveHint` annotation.
|
|
95
|
+
For a destructive tool with human-in-the-loop confirmation, see `obsidian-delete-note.tool.ts` — 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, branches on `ctx.inputs.view()` so a declined prompt on a matching round fails instead of re-asking, and carries the `destructiveHint` annotation. Pattern: framework `api-context` § Consent gates.
|
|
95
96
|
|
|
96
97
|
### Resource — `obsidian://status`
|
|
97
98
|
|
|
@@ -174,12 +175,14 @@ export function getServerConfig() {
|
|
|
174
175
|
```ts
|
|
175
176
|
await createApp({
|
|
176
177
|
// ...
|
|
177
|
-
sessionMode: 'stateful',
|
|
178
|
+
sessionMode: { default: 'stateful', require: 'stateful' },
|
|
178
179
|
teardown: () => obsidian.close(),
|
|
179
180
|
});
|
|
180
181
|
```
|
|
181
182
|
|
|
182
|
-
`sessionMode
|
|
183
|
+
`sessionMode` declares a requirement, not just a default: `obsidian_delete_note` 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. Unset, `MCP_SESSION_MODE` runs `stateful`; when the resolved HTTP mode is `stateless` (an explicit `MCP_SESSION_MODE=stateless`), startup fails with a `ConfigurationError` naming the conflict. stdio is never refused — `MCP_SESSION_MODE` has no effect there. `tests/integration/delete-note-confirmation.test.ts` pins both.
|
|
184
|
+
|
|
185
|
+
The delete confirmation's consent records 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
186
|
|
|
184
187
|
`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
188
|
|
|
@@ -193,11 +196,13 @@ Handlers receive a unified `ctx` object. Properties this server actually uses:
|
|
|
193
196
|
|:---------|:------------|
|
|
194
197
|
| `ctx.log` | Request-scoped logger — `.debug()`, `.info()`, `.notice()`, `.warning()`, `.error()`. Auto-correlates requestId, traceId, tenantId. |
|
|
195
198
|
| `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. |
|
|
199
|
+
| `ctx.state` | Tenant-scoped KV. Used only for `obsidian_delete_note`'s consent records (`consent/<uuid>`, 600 s TTL) — see Session posture above for provider requirements. |
|
|
200
|
+
| `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
201
|
| `ctx.signal` | `AbortSignal` propagated to the Local REST API client so per-request timeouts and client cancellations cut off in-flight HTTP. |
|
|
197
202
|
| `ctx.requestId` | Unique request ID — surfaces in log lines for correlation. |
|
|
198
203
|
| `ctx.tenantId` | Tenant ID from JWT or `'default'` for stdio. |
|
|
199
204
|
|
|
200
|
-
|
|
205
|
+
See the framework `CLAUDE.md` for the full surface.
|
|
201
206
|
|
|
202
207
|
---
|
|
203
208
|
|
|
@@ -205,7 +210,7 @@ The framework also provides `ctx.state`. It isn't used by this server — Obsidi
|
|
|
205
210
|
|
|
206
211
|
Handlers throw — the framework catches, classifies, and formats.
|
|
207
212
|
|
|
208
|
-
**Recommended: typed error contract.** Declare `errors: [{ reason, code, when, recovery, retryable? }]` on `tool()` / `resource()` to receive
|
|
213
|
+
**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
214
|
|
|
210
215
|
```ts
|
|
211
216
|
errors: [
|
|
@@ -218,29 +223,27 @@ errors: [
|
|
|
218
223
|
],
|
|
219
224
|
async handler(input, ctx) {
|
|
220
225
|
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
|
-
});
|
|
226
|
+
// Static recovery — the framework fills the contract's hint onto the wire.
|
|
227
|
+
if (!note) throw ctx.fail('note_missing', `Note ${input.path} not found`);
|
|
225
228
|
return note;
|
|
226
229
|
}
|
|
227
230
|
```
|
|
228
231
|
|
|
229
232
|
**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
233
|
|
|
231
|
-
|
|
234
|
+
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
235
|
|
|
233
236
|
```ts
|
|
234
237
|
// inside obsidian-service.ts
|
|
235
238
|
throw notFound(`Not found: ${display}`, data('note_missing'), { cause });
|
|
236
|
-
// where data(reason) does: { ...callerIdentifier(path), reason
|
|
239
|
+
// where data(reason) does: { ...callerIdentifier(path), reason }
|
|
237
240
|
// — `path` on a note route, `commandId` on /commands/<id>/, no key on routes
|
|
238
241
|
// that carry no caller input (/, /tags/, /commands/, /search/).
|
|
239
242
|
// The upstream body is never spread into `data` — it rides as `cause`, which
|
|
240
243
|
// is non-enumerable and so reaches the log without reaching the client.
|
|
241
244
|
```
|
|
242
245
|
|
|
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
|
|
246
|
+
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
247
|
|
|
245
248
|
**Fallback for ad-hoc throws** (no contract entry fits, prototype tools, service-layer code without a contract): use error factories.
|
|
246
249
|
|
|
@@ -414,7 +417,7 @@ security: false # optional — true ONLY for a source
|
|
|
414
417
|
|
|
415
418
|
## Publishing
|
|
416
419
|
|
|
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
|
|
420
|
+
**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
421
|
|
|
419
422
|
`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
423
|
|
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}
|