Skip to content

feat(ocm): MCP server tools backed by the official Obsidian CLI#428

Merged
Luis85 merged 4 commits into
developfrom
claude/affectionate-ramanujan-SJHOH
May 24, 2026
Merged

feat(ocm): MCP server tools backed by the official Obsidian CLI#428
Luis85 merged 4 commits into
developfrom
claude/affectionate-ramanujan-SJHOH

Conversation

@Luis85
Copy link
Copy Markdown
Owner

@Luis85 Luis85 commented May 23, 2026

Summary

Delivers a fully integrated MCP server tool surface built upon the official Obsidian CLI, managed from the plugin's settings tab.

Research first confirmed the premise: the official Obsidian CLI is real (shipped Obsidian 1.12.0, Feb 2026; GA 1.12.4) — a bundled binary that remote-controls a running vault with 100+ commands, format=json output, and an eval escape hatch. The plugin already runs an in-process loopback-HTTP MCP server (ADR-013). This PR amends ADR-013 by adding a CLI-backed tool group rather than standing up a second server.

  • ObsidianCliPort (narrow port, ADR-008) + ObsidianCliAdapter — shell-free spawn (no injection), typed ObsidianCliError (not-configured/spawn-failed/nonzero-exit/timeout/invalid-json), 15 s timeout, defensive JSON parsing. Plus ObsidianCliBinaryResolver (sibling of the Claude/Cursor resolvers) and MockObsidianCliPort.
  • registerObsidianCliTools — allow-listed read tools (obsidian_cli_search/read_note/daily_note/get_properties/run) and a single proposal-queued write (obsidian_cli_append_note). eval and destructive commands are never exposed. Registered into ObsidianMcpServerAdapter only when a CLI path is configured (graceful degradation; the in-process groups keep working without a CLI).
  • Settings management — new obsidianCliPath setting (validated, no version bump) + an "Obsidian CLI path" field (autodetect/test, mirroring the Claude field) and an enhanced MCP status line that shows CLI-configured state and the loopback URL. A shared _testBinaryVersion helper keeps the single audited spawnSync site (NFR-ASM-004).
  • Spec-first artifactsspecs/obsidian-cli-mcp-server/ (idea → research → requirements → design → spec → tasks → workflow-state) and ADR-018. Requirements REQ-OCM-001..018 map to tests.

Security posture

  • Writes go through the existing ProposalStore (ADR-007/013): agents propose, humans accept. No trusted-tool bypass.
  • obsidian_cli_run accepts only a read-only allow-list; eval/delete/move/create/plugin/theme commands have no tool.
  • CLI JSON output treated as an unstable contract — parse failures degrade to typed errors, never crashes.

Test plan

  • npm run typecheck
  • npm run lint (0 errors)
  • npm run test:coverage — 2302 passed; thresholds met (stmts 91.34%, branches 85.25%, funcs 91%, lines 92.48%)
  • npm run build + npm run build:web + npm run docs:api
  • validate:manifest, verify:scaffold, verify:workflows, verify:bundle-size, npm audit (prod/high), git diff --check
  • Manual: settings-tab field/status is an Obsidian-only PluginSettingTab surface (not in the standalone Vue UI), so it is covered by source-level tests rather than browser verification. End-to-end CLI invocation requires Obsidian ≥1.12.4 with the obsidian binary on PATH.

Notes / open clarifications

  • CLAR-OCM-001: a standalone stdio MCP process is deferred — the CLI group rides the existing loopback HTTP transport.

https://claude.ai/code/session_01RgvChiRuc3tqVbhUwLHxHz


Generated by Claude Code

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 23d02dee93

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/infrastructure/obsidian/ObsidianCliAdapter.ts Outdated
Luis85 pushed a commit that referenced this pull request May 23, 2026
A `close` event with exitCode null means the child was killed by a
signal; its output may be partial. Previously this fell through to
ok(), so a queued write (obsidian_cli_append_note) could be marked
completed even though the CLI command never finished. Add a
`signal-terminated` error code and branch on exitCode === null.

Addresses Codex P1 review on PR #428.

https://claude.ai/code/session_01RgvChiRuc3tqVbhUwLHxHz
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3b246f624f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/infrastructure/obsidian/mcp/registerObsidianCliTools.ts Outdated
Luis85 pushed a commit that referenced this pull request May 23, 2026
The Obsidian CLI `daily` command can create today's note when missing —
a vault mutation. Exposing it via `obsidian_cli_daily_note` or the
`obsidian_cli_run` allow-list let agents mutate the vault outside the
ProposalStore write-approval boundary. Remove the daily read tool and
drop `daily` from SAFE_CLI_READ_COMMANDS; a confirmed read-only daily
variant is deferred (CLAR-OCM-003).

Addresses Codex P1 review on PR #428.

https://claude.ai/code/session_01RgvChiRuc3tqVbhUwLHxHz
claude added 3 commits May 23, 2026 22:25
Adds a CLI-backed tool group to the existing in-process MCP server
(ADR-013) so agents can use the official Obsidian CLI (1.12+) as a
first-party tool surface, managed from the settings tab.

- ObsidianCliPort + ObsidianCliAdapter (shell-free spawn, typed errors,
  timeout, JSON parsing) + ObsidianCliBinaryResolver + MockObsidianCliPort
- registerObsidianCliTools: allow-listed read tools + proposal-queued
  append; eval and destructive commands are never exposed
- Wired optionally into ObsidianMcpServerAdapter; group registered only
  when a CLI path is configured (graceful degradation)
- obsidianCliPath setting + settings-tab field (autodetect/test) and
  enhanced MCP status; shared single spawnSync site preserved
- ADR-018 + specs/obsidian-cli-mcp-server (idea→tasks), tests, verify green

https://claude.ai/code/session_01RgvChiRuc3tqVbhUwLHxHz
A `close` event with exitCode null means the child was killed by a
signal; its output may be partial. Previously this fell through to
ok(), so a queued write (obsidian_cli_append_note) could be marked
completed even though the CLI command never finished. Add a
`signal-terminated` error code and branch on exitCode === null.

Addresses Codex P1 review on PR #428.

https://claude.ai/code/session_01RgvChiRuc3tqVbhUwLHxHz
The Obsidian CLI `daily` command can create today's note when missing —
a vault mutation. Exposing it via `obsidian_cli_daily_note` or the
`obsidian_cli_run` allow-list let agents mutate the vault outside the
ProposalStore write-approval boundary. Remove the daily read tool and
drop `daily` from SAFE_CLI_READ_COMMANDS; a confirmed read-only daily
variant is deferred (CLAR-OCM-003).

Addresses Codex P1 review on PR #428.

https://claude.ai/code/session_01RgvChiRuc3tqVbhUwLHxHz
@Luis85 Luis85 force-pushed the claude/affectionate-ramanujan-SJHOH branch from 950346a to 1ba9369 Compare May 23, 2026 20:43
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1ba9369894

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/infrastructure/obsidian/ObsidianCliAdapter.ts Outdated
ObsidianCliAdapter previously accepted any non-empty configured path,
which meant a bare command name like `obsidian` would be resolved via
PATH and could execute a shadowed/hijacked binary while still reporting
the CLI MCP tools as `available`. The settings UI already documents the
absolute-path contract; enforce it at the adapter as the last line of
defence before spawn. Non-absolute values now map to `not-configured`.

Addresses PR #428 P2 review comment.
@Luis85 Luis85 merged commit 8b7cb77 into develop May 24, 2026
9 checks passed
@Luis85 Luis85 deleted the claude/affectionate-ramanujan-SJHOH branch May 24, 2026 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants