mcp-server-obsidian 0.0.0-stage → 2.0.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/CHANGELOG.md +168 -0
- package/LICENSE +21 -0
- package/SECURITY.md +56 -0
- package/dist/api/ObsidianAPI.d.ts +69 -0
- package/dist/api/ObsidianAPI.d.ts.map +1 -0
- package/dist/api/ObsidianAPI.js +205 -0
- package/dist/api/ObsidianAPI.js.map +1 -0
- package/dist/connectors/BaseConnector.d.ts +109 -0
- package/dist/connectors/BaseConnector.d.ts.map +1 -0
- package/dist/connectors/BaseConnector.js +153 -0
- package/dist/connectors/BaseConnector.js.map +1 -0
- package/dist/connectors/LocalConnector.d.ts +53 -0
- package/dist/connectors/LocalConnector.d.ts.map +1 -0
- package/dist/connectors/LocalConnector.js +363 -0
- package/dist/connectors/LocalConnector.js.map +1 -0
- package/dist/connectors/RemoteConnector.d.ts +33 -0
- package/dist/connectors/RemoteConnector.d.ts.map +1 -0
- package/dist/connectors/RemoteConnector.js +331 -0
- package/dist/connectors/RemoteConnector.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +125 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +61 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +831 -0
- package/dist/server.js.map +1 -0
- package/dist/services/CanvasService.d.ts +112 -0
- package/dist/services/CanvasService.d.ts.map +1 -0
- package/dist/services/CanvasService.js +343 -0
- package/dist/services/CanvasService.js.map +1 -0
- package/dist/services/DataviewService.d.ts +50 -0
- package/dist/services/DataviewService.d.ts.map +1 -0
- package/dist/services/DataviewService.js +524 -0
- package/dist/services/DataviewService.js.map +1 -0
- package/dist/services/KnowledgeGraph.d.ts +86 -0
- package/dist/services/KnowledgeGraph.d.ts.map +1 -0
- package/dist/services/KnowledgeGraph.js +364 -0
- package/dist/services/KnowledgeGraph.js.map +1 -0
- package/dist/services/PeriodicNotesService.d.ts +65 -0
- package/dist/services/PeriodicNotesService.d.ts.map +1 -0
- package/dist/services/PeriodicNotesService.js +309 -0
- package/dist/services/PeriodicNotesService.js.map +1 -0
- package/dist/services/TemplateService.d.ts +51 -0
- package/dist/services/TemplateService.d.ts.map +1 -0
- package/dist/services/TemplateService.js +308 -0
- package/dist/services/TemplateService.js.map +1 -0
- package/dist/types/canvas.d.ts +57 -0
- package/dist/types/canvas.d.ts.map +1 -0
- package/dist/types/canvas.js +13 -0
- package/dist/types/canvas.js.map +1 -0
- package/dist/types/dataview.d.ts +60 -0
- package/dist/types/dataview.d.ts.map +1 -0
- package/dist/types/dataview.js +5 -0
- package/dist/types/dataview.js.map +1 -0
- package/dist/types/index.d.ts +122 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +12 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/periodic.d.ts +45 -0
- package/dist/types/periodic.d.ts.map +1 -0
- package/dist/types/periodic.js +31 -0
- package/dist/types/periodic.js.map +1 -0
- package/dist/types/template.d.ts +63 -0
- package/dist/types/template.d.ts.map +1 -0
- package/dist/types/template.js +5 -0
- package/dist/types/template.js.map +1 -0
- package/dist/utils/config.d.ts +65 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +290 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/date.d.ts +64 -0
- package/dist/utils/date.d.ts.map +1 -0
- package/dist/utils/date.js +483 -0
- package/dist/utils/date.js.map +1 -0
- package/dist/utils/errors.d.ts +16 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +27 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/frontmatter.d.ts +58 -0
- package/dist/utils/frontmatter.d.ts.map +1 -0
- package/dist/utils/frontmatter.js +124 -0
- package/dist/utils/frontmatter.js.map +1 -0
- package/dist/utils/fs.d.ts +50 -0
- package/dist/utils/fs.d.ts.map +1 -0
- package/dist/utils/fs.js +177 -0
- package/dist/utils/fs.js.map +1 -0
- package/dist/utils/http.d.ts +41 -0
- package/dist/utils/http.d.ts.map +1 -0
- package/dist/utils/http.js +122 -0
- package/dist/utils/http.js.map +1 -0
- package/dist/utils/links.d.ts +28 -0
- package/dist/utils/links.d.ts.map +1 -0
- package/dist/utils/links.js +140 -0
- package/dist/utils/links.js.map +1 -0
- package/dist/utils/markdown.d.ts +58 -0
- package/dist/utils/markdown.d.ts.map +1 -0
- package/dist/utils/markdown.js +262 -0
- package/dist/utils/markdown.js.map +1 -0
- package/dist/utils/paths.d.ts +120 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +225 -0
- package/dist/utils/paths.js.map +1 -0
- package/docs/CLAUDE_DESKTOP_SETUP.md +315 -0
- package/docs/QUICKSTART.md +195 -0
- package/docs/README.md +820 -0
- package/docs/TESTING.md +232 -0
- package/docs/VAULT_TYPES.md +264 -0
- package/obsidian-mcp.example.json +37 -0
- package/package.json +82 -4
- package/README.md +0 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [2.0.0] - 2026-12-05
|
|
9
|
+
|
|
10
|
+
A security and correctness release. Everyone on 1.0.0 should upgrade. The project also has
|
|
11
|
+
a new name, `mcp-server-obsidian`, and is on npm for the first time.
|
|
12
|
+
|
|
13
|
+
### Security
|
|
14
|
+
|
|
15
|
+
- **Path traversal in every file tool** ([#3], [#5]). Note, canvas and template tools joined
|
|
16
|
+
caller-supplied paths onto the vault folder without checking the result, so an MCP client
|
|
17
|
+
could read, write and delete files anywhere the server process could reach, with paths
|
|
18
|
+
such as `../../.ssh/id_rsa`. All paths now go through `resolveVaultPath` (introduced in [#4]
|
|
19
|
+
for canvas and templates, and extended here to `get_note`, `create_note`, `update_note`,
|
|
20
|
+
`delete_note`, periodic notes and note resources): absolute paths and `..` segments are
|
|
21
|
+
rejected and the resolved path must lie inside the vault.
|
|
22
|
+
- **Symbolic links out of the vault are refused.** A link inside the vault that points
|
|
23
|
+
outside it was followed. It is now rejected, as is a broken link (writing through one
|
|
24
|
+
creates its target). Set `"allowSymlinksOutsideVault": true` on a vault that shares
|
|
25
|
+
folders through symlinks on purpose.
|
|
26
|
+
- **Code execution through frontmatter.** Notes were parsed with gray-matter, which
|
|
27
|
+
evaluates front matter fenced as `---js` as JavaScript. Opening or indexing a note with
|
|
28
|
+
such a block ran its code with the server's privileges. Frontmatter is now parsed as YAML
|
|
29
|
+
data only.
|
|
30
|
+
- **Tools are limited to their file types.** Note tools only touch `.md` files and canvas
|
|
31
|
+
tools only `.canvas` files, so they cannot be used on `.obsidian/` configuration, plugin
|
|
32
|
+
code or anything else in the vault folder.
|
|
33
|
+
- **Prototype pollution in `dataview_query`.** Field paths such as `__proto__.x` in
|
|
34
|
+
`select` could write to `Object.prototype`. Field paths now only follow own properties.
|
|
35
|
+
- **Vulnerable dependencies removed.** `npm audit` reported 17 advisories in production
|
|
36
|
+
dependencies (2 critical, 12 high); it now reports none. See *Dependencies* below.
|
|
37
|
+
- Error messages no longer include the absolute path of the vault on disk.
|
|
38
|
+
- Added `"readOnly": true` for vaults, [SECURITY.md](SECURITY.md) and tool annotations
|
|
39
|
+
(`readOnlyHint`, `destructiveHint`) so clients can tell which tools change things.
|
|
40
|
+
|
|
41
|
+
### Fixed
|
|
42
|
+
|
|
43
|
+
- **`create_note` silently replaced existing notes.** It now fails if the note exists, unless
|
|
44
|
+
`overwrite: true` is passed. `create_canvas` and `create_from_template` no longer overwrite
|
|
45
|
+
either.
|
|
46
|
+
- **`update_note` erased frontmatter** whenever it was called without a `frontmatter`
|
|
47
|
+
argument. The existing frontmatter is now kept, byte for byte. It also no longer creates
|
|
48
|
+
a note that does not exist.
|
|
49
|
+
- **Changes made in Obsidian were never seen.** The file watcher used a glob pattern that
|
|
50
|
+
chokidar 4 does not support, so it never fired, and newly created files were not handled
|
|
51
|
+
at all. The index is now checked against the vault folder (size and modification time)
|
|
52
|
+
before it is used, and re-reads only what changed.
|
|
53
|
+
- **Dates were off by one day west of UTC.** `create_daily_note` with `2025-10-16` created
|
|
54
|
+
the note for 15 October in American time zones, `{{date:FORMAT}}` in templates had the
|
|
55
|
+
same error, and date-range filters were off at their ends. Dates are now calendar days in
|
|
56
|
+
the server's time zone. An invalid date is an error rather than a note called `NaN-NaN-NaN.md`.
|
|
57
|
+
- **Weekly notes around New Year got the wrong name.** The week of 29 December 2025 was named
|
|
58
|
+
`2025-W01`, the same as the first week of January 2025. The default format is now
|
|
59
|
+
`GGGG-[W]WW` (ISO week-numbering year).
|
|
60
|
+
- **Week and month ranges were wrong** for weeks that cross a month boundary and for months
|
|
61
|
+
when computed from the 29th to the 31st (`startDate` / `endDate` template variables).
|
|
62
|
+
- **Template formats were cut at the first colon**: `{{time:HH:mm:ss}}` rendered only the
|
|
63
|
+
hour. Extra frontmatter passed to templates is now written as valid YAML (values with
|
|
64
|
+
colons, lists of objects and nested values were corrupted before).
|
|
65
|
+
- **Backlinks, related notes and orphan detection missed most links.** `[[Plan]]` was only
|
|
66
|
+
matched against `Plan.md` in the vault root. Links are now resolved the way Obsidian
|
|
67
|
+
resolves them: by file name anywhere in the vault, by partial path, or relative to the
|
|
68
|
+
linking note. `get_related_notes` could also miss notes within the requested depth.
|
|
69
|
+
- **Bogus tags and links.** `[[Note#Heading]]` produced a tag `Heading` and a link to a note
|
|
70
|
+
called `Note#Heading`; URL fragments and `#` inside code became tags; `![[embed]]` was
|
|
71
|
+
counted as an embed and as a link. Tags now also support non-ASCII characters.
|
|
72
|
+
- **`get_vault_stats` always returned `"tags": {}`** (a `Map` does not serialise to JSON).
|
|
73
|
+
- **A numeric frontmatter `title` broke `search_notes`** for the whole vault, and a note with
|
|
74
|
+
invalid YAML frontmatter disappeared from the vault. Such notes now stay visible and
|
|
75
|
+
carry a `frontmatterError`.
|
|
76
|
+
- **Canvas edits overwrote each other** when a client issued several tool calls at once;
|
|
77
|
+
edits to one canvas are now applied one after the other. Canvases that Obsidian created
|
|
78
|
+
as an empty file or `{}` no longer crash `add_canvas_node`, and `add_canvas_edge` rejects
|
|
79
|
+
edges to nodes that are not on the canvas.
|
|
80
|
+
- **`dataview_query`:** numbers and dates are compared as numbers and dates (`rating > "4"`,
|
|
81
|
+
`due < "2024-06-01"` and `modified >= "2024-01-01"` now work). A date in a filter is a
|
|
82
|
+
calendar day in the server's time zone and, compared with a time of day, stands for the
|
|
83
|
+
whole day, so `modified = "2024-06-01"` finds the notes changed that day. `groupBy`
|
|
84
|
+
together with `select` no longer puts everything in one `(none)` group; notes missing the
|
|
85
|
+
sort field always sort last; frontmatter can no longer override `path` or `tags`; `from`
|
|
86
|
+
and the `folder` filter of `search_notes` match whole folder names (`Proj` no longer
|
|
87
|
+
matches `Projects/`); inline fields inside code blocks are ignored.
|
|
88
|
+
- **The config file was not found under Claude Desktop.** It was looked up relative to the
|
|
89
|
+
working directory, which the client chooses. It is now also looked for next to the server,
|
|
90
|
+
and can be named with `--config` or `OBSIDIAN_MCP_CONFIG`. `~` in vault paths is expanded.
|
|
91
|
+
An invalid config file is reported instead of being silently ignored.
|
|
92
|
+
- **Resource URIs were invalid** for vault names or paths containing spaces; they are now
|
|
93
|
+
percent-encoded.
|
|
94
|
+
- The server now exits when the client disconnects instead of lingering.
|
|
95
|
+
- Failed operations are reported as MCP tool errors (`isError`); many previously came back
|
|
96
|
+
as successful results containing `"success": false`.
|
|
97
|
+
- `npm run lint` works again (ESLint 9 dropped the old config format; CI was hiding the
|
|
98
|
+
failure), and the coverage thresholds that failed CI are now met (96% of statements).
|
|
99
|
+
|
|
100
|
+
### Added
|
|
101
|
+
|
|
102
|
+
- Tools that were documented but missing: `delete_canvas_node`, `delete_canvas_edge` and
|
|
103
|
+
`find_path`.
|
|
104
|
+
- `list_vaults`, and `vault` may be omitted on every tool when only one vault is configured.
|
|
105
|
+
- Obsidian app tools, offered only when `obsidianApi` is configured: `open_in_obsidian`,
|
|
106
|
+
`get_active_note`, `list_obsidian_commands`, `execute_obsidian_command`. The previous
|
|
107
|
+
client used routes that the Local REST API plugin does not have and no tool called it.
|
|
108
|
+
- The documented `periodicNotes` config section now works, globally and per vault, along
|
|
109
|
+
with a `templates` section. With no configuration, daily notes and templates follow the
|
|
110
|
+
vault's own Obsidian settings (`.obsidian/daily-notes.json`, `.obsidian/templates.json`).
|
|
111
|
+
- Moment-style date formats everywhere (`dddd`, `MMMM`, `Do`, `[literal]`, ...).
|
|
112
|
+
- Markdown-style links to notes (`[text](Folder/Note.md)`) count as links.
|
|
113
|
+
- `analyze_graph` reports clusters; the graph marks unresolved links and attachments
|
|
114
|
+
instead of leaving edges that point nowhere.
|
|
115
|
+
- Input validation for every tool, with titles and descriptions.
|
|
116
|
+
- `--config`, `--version`, `--help`; a `LICENSE` file.
|
|
117
|
+
- The package is published to npm, so an MCP client can start the server with
|
|
118
|
+
`npx -y mcp-server-obsidian`; no clone or build is needed. `scripts/release.sh` runs the
|
|
119
|
+
checks, pushes, publishes to npm, tags and creates the GitHub release.
|
|
120
|
+
- `server.json` and the `mcpName` field, for listing the server in the MCP Registry.
|
|
121
|
+
- 570 new tests (625 in total), including end-to-end tests through an MCP client. Date
|
|
122
|
+
handling is tested in several time zones.
|
|
123
|
+
|
|
124
|
+
### Changed
|
|
125
|
+
|
|
126
|
+
- **New name: `mcp-server-obsidian`** (was `obsidian-mcp-server`), for the package and the
|
|
127
|
+
GitHub repository; links to the old repository redirect. The installed command is
|
|
128
|
+
`mcp-server-obsidian` (was `obsidian-mcp`). Configuration files (`obsidian-mcp.json`) and
|
|
129
|
+
environment variables keep their names.
|
|
130
|
+
- **Node.js 22.13 or newer is required** (was 18; Node.js 18 and 20 are end-of-life).
|
|
131
|
+
- `dataview_query` rows are flat: each field appears once instead of once at the top level
|
|
132
|
+
and again under `metadata`. `metadata.<field>` is still accepted in queries.
|
|
133
|
+
- Frontmatter dates are kept as written (`2024-01-15`) rather than converted to
|
|
134
|
+
timestamps (`2024-01-15T00:00:00.000Z`).
|
|
135
|
+
- Periodic note results give `date` as `YYYY-MM-DD` (the first day of the period).
|
|
136
|
+
- `{{week}}` in templates is zero-padded (`03`), as documented.
|
|
137
|
+
- Weekly notes are named by ISO week-numbering year (see *Fixed*).
|
|
138
|
+
- The server is built on the SDK's `McpServer` API; the low-level `Server` class it used is
|
|
139
|
+
deprecated. The entry point is split into `src/index.ts` (command line) and `src/server.ts`.
|
|
140
|
+
- Remote vaults: `get_note` always asks the server instead of answering from a cache that
|
|
141
|
+
was never refreshed; path segments are encoded separately (`a/b.md`, not `a%2Fb.md`);
|
|
142
|
+
empty notes are no longer dropped. The REST contract a remote server has to implement is
|
|
143
|
+
now documented in `docs/VAULT_TYPES.md`. The quick start wrongly said remote vaults work
|
|
144
|
+
with the Local REST API plugin; they do not.
|
|
145
|
+
- `server.version` in the config file is ignored; the version reported to clients is the
|
|
146
|
+
package version.
|
|
147
|
+
|
|
148
|
+
### Dependencies
|
|
149
|
+
|
|
150
|
+
- Removed `gray-matter` (unmaintained; see *Security*), `chokidar`, `glob`, `axios` and the
|
|
151
|
+
unused `ws`, in favour of the `yaml` package and Node.js built-ins. Production
|
|
152
|
+
dependencies are now `@modelcontextprotocol/sdk`, `yaml` and `zod`.
|
|
153
|
+
- `@modelcontextprotocol/sdk` 1.20.1 → 1.32.2, `zod` 4.1.12 → 4.6.7.
|
|
154
|
+
- TypeScript 5.9 → 6.0, ESLint 9 → 10 (flat config), Jest 30.2 → 30.5, typescript-eslint
|
|
155
|
+
8.46 → 8.74. TypeScript 7 is not used yet because ts-jest and typescript-eslint do not
|
|
156
|
+
support it.
|
|
157
|
+
- GitHub Actions updated to their current major versions; CI runs on Node.js 22 (including
|
|
158
|
+
22.13, the oldest supported version), 24 and 26, and on macOS.
|
|
159
|
+
|
|
160
|
+
## [1.0.0] - 2025-10-16
|
|
161
|
+
|
|
162
|
+
Initial version.
|
|
163
|
+
|
|
164
|
+
[2.0.0]: https://github.com/bazylhorsey/mcp-server-obsidian/releases/tag/v2.0.0
|
|
165
|
+
[1.0.0]: https://github.com/bazylhorsey/mcp-server-obsidian/tree/ba06b16757467b5a0acf5eebc71398213c254ede
|
|
166
|
+
[#3]: https://github.com/bazylhorsey/mcp-server-obsidian/issues/3
|
|
167
|
+
[#4]: https://github.com/bazylhorsey/mcp-server-obsidian/pull/4
|
|
168
|
+
[#5]: https://github.com/bazylhorsey/mcp-server-obsidian/issues/5
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Bazyl Horsey
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported versions
|
|
4
|
+
|
|
5
|
+
Security fixes are released for the latest version only.
|
|
6
|
+
|
|
7
|
+
| Version | Supported |
|
|
8
|
+
|---|---|
|
|
9
|
+
| 2.x | ✅ |
|
|
10
|
+
| 1.x | ❌ (upgrade to 2.x; see the [changelog](CHANGELOG.md)) |
|
|
11
|
+
|
|
12
|
+
## Reporting a vulnerability
|
|
13
|
+
|
|
14
|
+
Please report vulnerabilities privately, so that a fix can be released before the details
|
|
15
|
+
are public:
|
|
16
|
+
|
|
17
|
+
1. Open the repository's **Security** tab and choose **Report a vulnerability**
|
|
18
|
+
([direct link](https://github.com/bazylhorsey/mcp-server-obsidian/security/advisories/new)).
|
|
19
|
+
2. If that option is not available, open an issue that says only that you have a security
|
|
20
|
+
report and how to reach you. Do not include the details or a proof of concept in a
|
|
21
|
+
public issue.
|
|
22
|
+
|
|
23
|
+
Useful things to include: the affected version, the tool and arguments involved, what an
|
|
24
|
+
attacker gains, and a minimal reproduction.
|
|
25
|
+
|
|
26
|
+
Fixes are announced in the [changelog](CHANGELOG.md) and the release notes.
|
|
27
|
+
|
|
28
|
+
## What the server protects
|
|
29
|
+
|
|
30
|
+
This server lets an MCP client, usually an AI assistant, work with the notes in the vaults
|
|
31
|
+
you configure. The assistant may be acting on text it read somewhere else (a web page, an
|
|
32
|
+
email, another note), so tool arguments are treated as untrusted:
|
|
33
|
+
|
|
34
|
+
- **The vault folder is the boundary.** Every path is resolved inside the selected vault.
|
|
35
|
+
Absolute paths, `..` segments and symbolic links leading out of the vault are refused.
|
|
36
|
+
Symlinks out of the vault can be allowed per vault with `allowSymlinksOutsideVault`.
|
|
37
|
+
- **Only note and canvas files.** Note tools read and write `.md` files; canvas tools
|
|
38
|
+
`.canvas` files. Other files in the vault folder, such as `.obsidian/` settings and
|
|
39
|
+
plugin code, cannot be reached through them.
|
|
40
|
+
- **Notes are data.** Frontmatter is parsed as plain YAML. Nothing in a note is executed.
|
|
41
|
+
- **Read-only vaults.** `"readOnly": true` disables every tool that changes a vault.
|
|
42
|
+
|
|
43
|
+
## What it does not protect against
|
|
44
|
+
|
|
45
|
+
- **Anything the tools are meant to do.** A client that may call `update_note` or
|
|
46
|
+
`delete_note` can change or permanently delete any note in a writable vault. Use
|
|
47
|
+
`readOnly` and your MCP client's tool approvals accordingly.
|
|
48
|
+
- **Note contents reaching the model.** Whatever is in your notes can be read by the
|
|
49
|
+
client, and text inside a note can try to instruct the model (prompt injection).
|
|
50
|
+
- **`execute_obsidian_command`.** When `obsidianApi` is configured, this tool can run any
|
|
51
|
+
command in Obsidian's command palette, including commands added by plugins. Leave
|
|
52
|
+
`obsidianApi` out of the configuration if you do not need it.
|
|
53
|
+
- **Other local processes and users.** The server speaks MCP over stdio to the process that
|
|
54
|
+
started it and has no authentication of its own. API keys in `obsidian-mcp.json` are
|
|
55
|
+
stored in plain text; keep that file out of version control.
|
|
56
|
+
- **Remote vault servers.** A `remote` vault trusts the server at its `url`. Use HTTPS.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Obsidian API integration layer
|
|
3
|
+
* Controls the running Obsidian app through the "Local REST API" community
|
|
4
|
+
* plugin (https://github.com/coddingtonbear/obsidian-local-rest-api), with the
|
|
5
|
+
* Obsidian URI protocol as a fallback for opening notes.
|
|
6
|
+
*/
|
|
7
|
+
import type { VaultOperationResult } from '../types/index.js';
|
|
8
|
+
export interface ObsidianAPIConfig {
|
|
9
|
+
/**
|
|
10
|
+
* Base URL of the Local REST API plugin, e.g. `http://127.0.0.1:27123`
|
|
11
|
+
* (plain HTTP, has to be enabled in the plugin) or `https://127.0.0.1:27124`.
|
|
12
|
+
*/
|
|
13
|
+
restApiUrl?: string;
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
vaultName?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface OpenNoteOptions {
|
|
18
|
+
newLeaf?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface ObsidianCommand {
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
}
|
|
24
|
+
export interface CommandResult {
|
|
25
|
+
success: boolean;
|
|
26
|
+
result?: any;
|
|
27
|
+
error?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Integration with Obsidian's advanced features
|
|
31
|
+
*/
|
|
32
|
+
export declare class ObsidianAPI {
|
|
33
|
+
private client?;
|
|
34
|
+
private config;
|
|
35
|
+
constructor(config?: ObsidianAPIConfig);
|
|
36
|
+
/**
|
|
37
|
+
* True when the REST API is configured (as opposed to URI-only operation)
|
|
38
|
+
*/
|
|
39
|
+
get hasRestApi(): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Check if Obsidian REST API is available
|
|
42
|
+
*/
|
|
43
|
+
isAvailable(): Promise<boolean>;
|
|
44
|
+
/**
|
|
45
|
+
* Open a note in Obsidian
|
|
46
|
+
*/
|
|
47
|
+
openNote(path: string, options?: OpenNoteOptions): Promise<VaultOperationResult<string | void>>;
|
|
48
|
+
/**
|
|
49
|
+
* Execute an Obsidian command
|
|
50
|
+
*/
|
|
51
|
+
executeCommand(commandId: string): Promise<CommandResult>;
|
|
52
|
+
/**
|
|
53
|
+
* Get active file in Obsidian
|
|
54
|
+
*/
|
|
55
|
+
getActiveFile(): Promise<VaultOperationResult<any>>;
|
|
56
|
+
/**
|
|
57
|
+
* Get list of available commands
|
|
58
|
+
*/
|
|
59
|
+
listCommands(): Promise<VaultOperationResult<ObsidianCommand[]>>;
|
|
60
|
+
/**
|
|
61
|
+
* Build an Obsidian URI
|
|
62
|
+
*/
|
|
63
|
+
private buildObsidianURI;
|
|
64
|
+
/**
|
|
65
|
+
* Close the API connection
|
|
66
|
+
*/
|
|
67
|
+
close(): void;
|
|
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G,YAAY,IAAI,OAAO,CAAC,oBAAoB,CAAC,eAAe,EAAE,CAAC,CAAC;IAuBtE;;OAEG;IACH,OAAO,CAAC,gBAAgB;IASxB;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd"}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Obsidian API integration layer
|
|
3
|
+
* Controls the running Obsidian app through the "Local REST API" community
|
|
4
|
+
* plugin (https://github.com/coddingtonbear/obsidian-local-rest-api), with the
|
|
5
|
+
* Obsidian URI protocol as a fallback for opening notes.
|
|
6
|
+
*/
|
|
7
|
+
import { errorMessage } from '../utils/errors.js';
|
|
8
|
+
import { HttpClient, HttpError, encodePath } from '../utils/http.js';
|
|
9
|
+
import { normalizeVaultRelativePath, resolveVaultPath } from '../utils/paths.js';
|
|
10
|
+
function describe(error) {
|
|
11
|
+
if (error instanceof HttpError) {
|
|
12
|
+
// The plugin answers errors with { message, errorCode }.
|
|
13
|
+
try {
|
|
14
|
+
const body = JSON.parse(error.body);
|
|
15
|
+
if (body && typeof body.message === 'string') {
|
|
16
|
+
return `${error.message}: ${body.message}`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
// Not JSON; the status line is all there is.
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return errorMessage(error);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Integration with Obsidian's advanced features
|
|
27
|
+
*/
|
|
28
|
+
export class ObsidianAPI {
|
|
29
|
+
client;
|
|
30
|
+
config;
|
|
31
|
+
constructor(config = {}) {
|
|
32
|
+
this.config = config;
|
|
33
|
+
if (config.restApiUrl) {
|
|
34
|
+
this.client = new HttpClient({
|
|
35
|
+
baseUrl: config.restApiUrl,
|
|
36
|
+
apiKey: config.apiKey,
|
|
37
|
+
timeoutMs: 5000
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* True when the REST API is configured (as opposed to URI-only operation)
|
|
43
|
+
*/
|
|
44
|
+
get hasRestApi() {
|
|
45
|
+
return this.client !== undefined;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Check if Obsidian REST API is available
|
|
49
|
+
*/
|
|
50
|
+
async isAvailable() {
|
|
51
|
+
if (!this.client) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
await this.client.get('/');
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Open a note in Obsidian
|
|
64
|
+
*/
|
|
65
|
+
async openNote(path, options = {}) {
|
|
66
|
+
try {
|
|
67
|
+
const file = normalizeVaultRelativePath(path);
|
|
68
|
+
// Same rules as any vault path: relative, no `..` segments.
|
|
69
|
+
resolveVaultPath('/', file);
|
|
70
|
+
if (this.client) {
|
|
71
|
+
// Use REST API
|
|
72
|
+
await this.client.post(`/open/${encodePath(file)}`, undefined, {
|
|
73
|
+
query: { newLeaf: options.newLeaf ? 'true' : undefined }
|
|
74
|
+
});
|
|
75
|
+
return { success: true };
|
|
76
|
+
}
|
|
77
|
+
else if (this.config.vaultName) {
|
|
78
|
+
// Use URI protocol
|
|
79
|
+
const uri = this.buildObsidianURI('open', {
|
|
80
|
+
vault: this.config.vaultName,
|
|
81
|
+
file,
|
|
82
|
+
newpane: options.newLeaf ? 'true' : undefined
|
|
83
|
+
});
|
|
84
|
+
// A Node.js process cannot follow a URI itself; the client application
|
|
85
|
+
// (or the user) opens it.
|
|
86
|
+
return {
|
|
87
|
+
success: true,
|
|
88
|
+
data: uri
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
success: false,
|
|
93
|
+
error: 'No Obsidian API connection configured'
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
return {
|
|
98
|
+
success: false,
|
|
99
|
+
error: `Failed to open note: ${describe(error)}`
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Execute an Obsidian command
|
|
105
|
+
*/
|
|
106
|
+
async executeCommand(commandId) {
|
|
107
|
+
try {
|
|
108
|
+
if (!this.client) {
|
|
109
|
+
return {
|
|
110
|
+
success: false,
|
|
111
|
+
error: 'REST API not configured'
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
if (typeof commandId !== 'string' || commandId.trim().length === 0) {
|
|
115
|
+
return {
|
|
116
|
+
success: false,
|
|
117
|
+
error: 'Command id is required'
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const response = await this.client.post(`/commands/${encodeURIComponent(commandId.trim())}/`);
|
|
121
|
+
return {
|
|
122
|
+
success: true,
|
|
123
|
+
result: response.data
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
return {
|
|
128
|
+
success: false,
|
|
129
|
+
error: `Failed to execute command: ${describe(error)}`
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Get active file in Obsidian
|
|
135
|
+
*/
|
|
136
|
+
async getActiveFile() {
|
|
137
|
+
try {
|
|
138
|
+
if (!this.client) {
|
|
139
|
+
return {
|
|
140
|
+
success: false,
|
|
141
|
+
error: 'REST API not configured'
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
// The note+json representation carries the path along with the content.
|
|
145
|
+
const response = await this.client.get('/active/', {
|
|
146
|
+
accept: 'application/vnd.olrapi.note+json'
|
|
147
|
+
});
|
|
148
|
+
return {
|
|
149
|
+
success: true,
|
|
150
|
+
data: response.data
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
if (error instanceof HttpError && error.status === 404) {
|
|
155
|
+
return { success: false, error: 'No file is active in Obsidian' };
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
success: false,
|
|
159
|
+
error: `Failed to get active file: ${describe(error)}`
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Get list of available commands
|
|
165
|
+
*/
|
|
166
|
+
async listCommands() {
|
|
167
|
+
try {
|
|
168
|
+
if (!this.client) {
|
|
169
|
+
return {
|
|
170
|
+
success: false,
|
|
171
|
+
error: 'REST API not configured'
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
const response = await this.client.get('/commands/');
|
|
175
|
+
const commands = Array.isArray(response.data) ? response.data : response.data?.commands;
|
|
176
|
+
return {
|
|
177
|
+
success: true,
|
|
178
|
+
data: Array.isArray(commands) ? commands : []
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
return {
|
|
183
|
+
success: false,
|
|
184
|
+
error: `Failed to list commands: ${describe(error)}`
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Build an Obsidian URI
|
|
190
|
+
*/
|
|
191
|
+
buildObsidianURI(action, params) {
|
|
192
|
+
const cleanParams = Object.entries(params)
|
|
193
|
+
.filter(([_, value]) => value !== undefined)
|
|
194
|
+
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
|
|
195
|
+
.join('&');
|
|
196
|
+
return `obsidian://${action}?${cleanParams}`;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Close the API connection
|
|
200
|
+
*/
|
|
201
|
+
close() {
|
|
202
|
+
// Clean up resources if needed
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=ObsidianAPI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObsidianAPI.js","sourceRoot":"","sources":["../../src/api/ObsidianAPI.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,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AAc,EAAE,MAA0C;QACjF,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;aACvC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC;aAC3C,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,kBAAkB,CAAC,KAAM,CAAC,EAAE,CAAC;aAC7D,IAAI,CAAC,GAAG,CAAC,CAAC;QAEb,OAAO,cAAc,MAAM,IAAI,WAAW,EAAE,CAAC;IAC/C,CAAC;IAED;;OAEG;IACH,KAAK;QACH,+BAA+B;IACjC,CAAC;CACF"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base connector interface for vault connections
|
|
3
|
+
* All vault connectors (local, remote) must implement this interface
|
|
4
|
+
*/
|
|
5
|
+
import type { Note, SearchOptions, VaultOperationResult, VaultStats, VaultConfig } from '../types/index.js';
|
|
6
|
+
import type { VaultPathOptions } from '../utils/paths.js';
|
|
7
|
+
export interface CreateNoteOptions {
|
|
8
|
+
/** Replace the note if it already exists instead of failing. */
|
|
9
|
+
overwrite?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare abstract class BaseConnector {
|
|
12
|
+
protected config: VaultConfig;
|
|
13
|
+
constructor(config: VaultConfig);
|
|
14
|
+
/**
|
|
15
|
+
* Vault name, as used in tool arguments
|
|
16
|
+
*/
|
|
17
|
+
get name(): string;
|
|
18
|
+
/**
|
|
19
|
+
* Vault type
|
|
20
|
+
*/
|
|
21
|
+
get type(): VaultConfig['type'];
|
|
22
|
+
/**
|
|
23
|
+
* Get vault path (for local vaults)
|
|
24
|
+
*/
|
|
25
|
+
get vaultPath(): string | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* True when the vault refuses every change
|
|
28
|
+
*/
|
|
29
|
+
get readOnly(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* How paths inside this vault may be resolved
|
|
32
|
+
*/
|
|
33
|
+
get pathOptions(): VaultPathOptions;
|
|
34
|
+
/**
|
|
35
|
+
* The vault's configuration
|
|
36
|
+
*/
|
|
37
|
+
get vaultConfig(): Readonly<VaultConfig>;
|
|
38
|
+
/**
|
|
39
|
+
* Throw unless the vault accepts changes
|
|
40
|
+
*/
|
|
41
|
+
assertWritable(): void;
|
|
42
|
+
/**
|
|
43
|
+
* Tell the connector that vault files were changed without going through
|
|
44
|
+
* it, so its next answer has to be checked against the vault again.
|
|
45
|
+
*/
|
|
46
|
+
invalidate(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Initialize the connector
|
|
49
|
+
*/
|
|
50
|
+
abstract initialize(): Promise<VaultOperationResult<void>>;
|
|
51
|
+
/**
|
|
52
|
+
* Get a note by its path
|
|
53
|
+
*/
|
|
54
|
+
abstract getNote(path: string): Promise<VaultOperationResult<Note>>;
|
|
55
|
+
/**
|
|
56
|
+
* Get all notes in the vault
|
|
57
|
+
*/
|
|
58
|
+
abstract getAllNotes(): Promise<VaultOperationResult<Note[]>>;
|
|
59
|
+
/**
|
|
60
|
+
* Search for notes
|
|
61
|
+
*/
|
|
62
|
+
abstract searchNotes(options: SearchOptions): Promise<VaultOperationResult<Note[]>>;
|
|
63
|
+
/**
|
|
64
|
+
* Create a new note. Fails if the note exists unless `overwrite` is set.
|
|
65
|
+
*/
|
|
66
|
+
abstract createNote(path: string, content: string, frontmatter?: Record<string, any>, options?: CreateNoteOptions): Promise<VaultOperationResult<Note>>;
|
|
67
|
+
/**
|
|
68
|
+
* Update an existing note. When `frontmatter` is omitted the note keeps the
|
|
69
|
+
* frontmatter it has.
|
|
70
|
+
*/
|
|
71
|
+
abstract updateNote(path: string, content: string, frontmatter?: Record<string, any>): Promise<VaultOperationResult<Note>>;
|
|
72
|
+
/**
|
|
73
|
+
* Delete a note
|
|
74
|
+
*/
|
|
75
|
+
abstract deleteNote(path: string): Promise<VaultOperationResult<void>>;
|
|
76
|
+
/**
|
|
77
|
+
* Get vault statistics
|
|
78
|
+
*/
|
|
79
|
+
abstract getStats(): Promise<VaultOperationResult<VaultStats>>;
|
|
80
|
+
/**
|
|
81
|
+
* List all folders in the vault
|
|
82
|
+
*/
|
|
83
|
+
abstract listFolders(): Promise<VaultOperationResult<string[]>>;
|
|
84
|
+
/**
|
|
85
|
+
* List all tags used in the vault
|
|
86
|
+
*/
|
|
87
|
+
abstract listTags(): Promise<VaultOperationResult<string[]>>;
|
|
88
|
+
/**
|
|
89
|
+
* Close the connector and cleanup resources
|
|
90
|
+
*/
|
|
91
|
+
abstract close(): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Apply folder, tag, query and limit filters to a set of notes
|
|
94
|
+
*/
|
|
95
|
+
protected filterNotes(notes: Note[], options: SearchOptions): Note[];
|
|
96
|
+
/**
|
|
97
|
+
* Compute vault statistics from a set of notes
|
|
98
|
+
*/
|
|
99
|
+
protected computeStats(notes: Note[]): VaultStats;
|
|
100
|
+
/**
|
|
101
|
+
* Every folder that contains a note, including the folders above it
|
|
102
|
+
*/
|
|
103
|
+
protected collectFolders(notes: Note[]): string[];
|
|
104
|
+
/**
|
|
105
|
+
* Every tag used by a set of notes
|
|
106
|
+
*/
|
|
107
|
+
protected collectTags(notes: Note[]): string[];
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=BaseConnector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseConnector.d.ts","sourceRoot":"","sources":["../../src/connectors/BaseConnector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,oBAAoB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC5G,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAG1D,MAAM,WAAW,iBAAiB;IAChC,gEAAgE;IAChE,SAAS,CAAC,EAAE,OA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