obsidian-mcp-server 2.0.4 → 2.0.5
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 +9 -0
- package/README.md +80 -88
- package/dist/mcp-server/server.js +2 -2
- package/dist/mcp-server/tools/obsidianListFilesTool/logic.js +5 -4
- package/dist/mcp-server/tools/{obsidianUpdateFileTool → obsidianUpdateNoteTool}/index.d.ts +4 -4
- package/dist/mcp-server/tools/{obsidianUpdateFileTool → obsidianUpdateNoteTool}/index.js +4 -4
- package/dist/mcp-server/tools/{obsidianUpdateFileTool → obsidianUpdateNoteTool}/logic.d.ts +8 -8
- package/dist/mcp-server/tools/{obsidianUpdateFileTool → obsidianUpdateNoteTool}/logic.js +7 -7
- package/dist/mcp-server/tools/{obsidianUpdateFileTool → obsidianUpdateNoteTool}/registration.d.ts +2 -2
- package/dist/mcp-server/tools/{obsidianUpdateFileTool → obsidianUpdateNoteTool}/registration.js +13 -13
- package/dist/mcp-server/transports/{authentication → auth/core}/authContext.d.ts +2 -2
- package/dist/mcp-server/transports/{authentication → auth/core}/authContext.js +1 -1
- package/dist/mcp-server/transports/{authentication/types.d.ts → auth/core/authTypes.d.ts} +1 -1
- package/dist/mcp-server/transports/{authentication/types.js → auth/core/authTypes.js} +1 -1
- package/dist/mcp-server/transports/{authentication → auth/core}/authUtils.d.ts +1 -1
- package/dist/mcp-server/transports/{authentication → auth/core}/authUtils.js +3 -3
- package/dist/mcp-server/transports/auth/index.d.ts +10 -0
- package/dist/mcp-server/transports/auth/index.js +9 -0
- package/dist/mcp-server/transports/{authentication/authMiddleware.d.ts → auth/strategies/jwt/jwtMiddleware.d.ts} +4 -7
- package/dist/mcp-server/transports/{authentication/authMiddleware.js → auth/strategies/jwt/jwtMiddleware.js} +40 -36
- package/dist/mcp-server/transports/{authentication → auth/strategies/oauth}/oauthMiddleware.d.ts +2 -6
- package/dist/mcp-server/transports/{authentication → auth/strategies/oauth}/oauthMiddleware.js +33 -18
- package/dist/mcp-server/transports/httpErrorHandler.d.ts +26 -0
- package/dist/mcp-server/transports/httpErrorHandler.js +73 -0
- package/dist/mcp-server/transports/httpTransport.d.ts +11 -14
- package/dist/mcp-server/transports/httpTransport.js +91 -379
- package/package.json +11 -16
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.0.5] - 2025-06-20
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- **Tool Renaming**: Renamed the `obsidian_update_file` tool to `obsidian_update_note` to avoid conflicts and better reflect its function. During agentic use, LLMs confused this tool with filesystem operations, leading to errors. The new name clarifies that it operates on Obsidian notes specifically.
|
|
13
|
+
- **HTTP Transport Refactor**: Restructured the HTTP transport layer for improved clarity and robustness. Authentication logic is now more modular, and a centralized error handler has been implemented.
|
|
14
|
+
- **Dependency Updates**: Updated all dependencies to their latest versions.
|
|
15
|
+
- **Documentation Improvements**: Enhanced the documentation around installation & MCP Client configuration. Suggested by [@bgheneti](https://github.com/bgheneti) in [PR #14](https://github.com/cyanheads/obsidian-mcp-server/pull/14). Thanks!
|
|
16
|
+
|
|
8
17
|
## [2.0.4] - 2025-06-13
|
|
9
18
|
|
|
10
19
|
### Added
|
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Obsidian MCP Server
|
|
2
2
|
|
|
3
3
|
[](https://www.typescriptlang.org/)
|
|
4
|
-
[](https://modelcontextprotocol.io/)
|
|
5
|
+
[](./CHANGELOG.md)
|
|
6
6
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
7
7
|
[](https://github.com/cyanheads/obsidian-mcp-server/issues)
|
|
8
8
|
[](https://github.com/cyanheads/obsidian-mcp-server)
|
|
@@ -20,7 +20,7 @@ This server equips your AI with specialized tools to interact with your Obsidian
|
|
|
20
20
|
| Tool Name | Description | Key Features |
|
|
21
21
|
| :------------------------------------------------------------------------------------- | :-------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
22
22
|
| [`obsidian_read_file`](./src/mcp-server/tools/obsidianReadFileTool/) | Retrieves the content and metadata of a specified file. | - Read in `markdown` or `json` format.<br/>- Case-insensitive path fallback.<br/>- Includes file stats (creation/modification time). |
|
|
23
|
-
| [`
|
|
23
|
+
| [`obsidian_update_note`](./src/mcp-server/tools/obsidianUpdateNoteTool/) | Modifies notes using whole-file operations. | - `append`, `prepend`, or `overwrite` content.<br/>- Can create files if they don't exist.<br/>- Targets files by path, active note, or periodic note. |
|
|
24
24
|
| [`obsidian_search_replace`](./src/mcp-server/tools/obsidianSearchReplaceTool/) | Performs search-and-replace operations within a target note. | - Supports string or regex search.<br/>- Options for case sensitivity, whole word, and replacing all occurrences. |
|
|
25
25
|
| [`obsidian_global_search`](./src/mcp-server/tools/obsidianGlobalSearchTool/) | Performs a search across the entire vault. | - Text or regex search.<br/>- Filter by path and modification date.<br/>- Paginated results. |
|
|
26
26
|
| [`obsidian_list_files`](./src/mcp-server/tools/obsidianListFilesTool/) | Lists files and subdirectories within a specified vault folder. | - Filter by file extension or name regex.<br/>- Provides a formatted tree view of the directory. |
|
|
@@ -32,8 +32,8 @@ This server equips your AI with specialized tools to interact with your Obsidian
|
|
|
32
32
|
|
|
33
33
|
## Table of Contents
|
|
34
34
|
|
|
35
|
-
| [Overview](#overview) | [Features](#features) | [
|
|
36
|
-
| [
|
|
35
|
+
| [Overview](#overview) | [Features](#features) | [Configuration](#configuration) |
|
|
36
|
+
| [Project Structure](#project-structure) | [Vault Cache Service](#vault-cache-service) |
|
|
37
37
|
| [Tools](#tools) | [Resources](#resources) | [Development](#development) | [License](#license) |
|
|
38
38
|
|
|
39
39
|
## Overview
|
|
@@ -54,7 +54,7 @@ Built on the robust `mcp-ts-template`, this server provides a standardized, secu
|
|
|
54
54
|
|
|
55
55
|
### Core Utilities
|
|
56
56
|
|
|
57
|
-
Leverages the robust utilities provided by
|
|
57
|
+
Leverages the robust utilities provided by `cyanheads/mcp-ts-template`:
|
|
58
58
|
|
|
59
59
|
- **Logging**: Structured, configurable logging (file rotation, console, MCP notifications) with sensitive data redaction.
|
|
60
60
|
- **Error Handling**: Centralized error processing, standardized error types (`McpError`), and automatic logging.
|
|
@@ -62,7 +62,7 @@ Leverages the robust utilities provided by the `mcp-ts-template`:
|
|
|
62
62
|
- **Input Validation/Sanitization**: Uses `zod` for schema validation and custom sanitization logic.
|
|
63
63
|
- **Request Context**: Tracking and correlation of operations via unique request IDs.
|
|
64
64
|
- **Type Safety**: Strong typing enforced by TypeScript and Zod schemas.
|
|
65
|
-
- **HTTP Transport Option**: Built-in Hono server with SSE, session management, CORS support, and JWT
|
|
65
|
+
- **HTTP Transport Option**: Built-in Hono server with SSE, session management, CORS support, and pluggable authentication strategies (JWT and OAuth 2.1).
|
|
66
66
|
|
|
67
67
|
### Obsidian Integration
|
|
68
68
|
|
|
@@ -82,52 +82,73 @@ Leverages the robust utilities provided by the `mcp-ts-template`:
|
|
|
82
82
|
3. **API Key**: Configure an API key within the Local REST API plugin settings in Obsidian. You will need this key to configure the server.
|
|
83
83
|
4. **Node.js & npm**: Ensure you have Node.js (v18 or later recommended) and npm installed.
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
## Configuration
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
npm install obsidian-mcp-server
|
|
89
|
-
```
|
|
87
|
+
### MCP Client Settings
|
|
90
88
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
1. Clone the repository:
|
|
94
|
-
```bash
|
|
95
|
-
git clone https://github.com/cyanheads/obsidian-mcp-server.git
|
|
96
|
-
cd obsidian-mcp-server
|
|
97
|
-
```
|
|
98
|
-
2. Install dependencies:
|
|
99
|
-
```bash
|
|
100
|
-
npm install
|
|
101
|
-
```
|
|
102
|
-
3. Build the project:
|
|
103
|
-
```bash
|
|
104
|
-
npm run build
|
|
105
|
-
```
|
|
106
|
-
This compiles the TypeScript code to JavaScript in the `dist/` directory and makes the entry point executable.
|
|
89
|
+
Add the following to your MCP client's configuration file (e.g., `cline_mcp_settings.json`). This configuration uses `npx` to run the server, which will automatically download & install the package if not already present:
|
|
107
90
|
|
|
108
|
-
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"mcpServers": {
|
|
94
|
+
"obsidian-mcp-server": {
|
|
95
|
+
"command": "npx",
|
|
96
|
+
"args": ["obsidian-mcp-server"],
|
|
97
|
+
"env": {
|
|
98
|
+
"OBSIDIAN_API_KEY": "YOUR_API_KEY_FROM_OBSIDIAN_PLUGIN",
|
|
99
|
+
"OBSIDIAN_BASE_URL": "http://127.0.0.1:27123",
|
|
100
|
+
"OBSIDIAN_VERIFY_SSL": "false",
|
|
101
|
+
"OBSIDIAN_ENABLE_CACHE": "true"
|
|
102
|
+
},
|
|
103
|
+
"disabled": false,
|
|
104
|
+
"autoApprove": []
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
**Note**: Verify SSL is set to false here because the Obsidian Local REST API plugin uses a self-signed certificate by default. If you are deploying this in a production environment, consider using the encrypted HTTPS endpoint and set `OBSIDIAN_VERIFY_SSL` to `true` after configuring your server to trust the self-signed certificate.
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
If you installed from source, change `command` and `args` to point to your local build:
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
```json
|
|
115
|
+
{
|
|
116
|
+
"mcpServers": {
|
|
117
|
+
"obsidian-mcp-server": {
|
|
118
|
+
"command": "node",
|
|
119
|
+
"args": ["/path/to/your/obsidian-mcp-server/dist/index.js"],
|
|
120
|
+
"env": {
|
|
121
|
+
"OBSIDIAN_API_KEY": "YOUR_OBSIDIAN_API_KEY",
|
|
122
|
+
"OBSIDIAN_BASE_URL": "http://127.0.0.1:27123",
|
|
123
|
+
"OBSIDIAN_VERIFY_SSL": "false",
|
|
124
|
+
"OBSIDIAN_ENABLE_CACHE": "true"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
```
|
|
115
130
|
|
|
116
|
-
|
|
131
|
+
### Environment Variables
|
|
117
132
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
|
121
|
-
|
|
|
122
|
-
|
|
|
123
|
-
|
|
|
124
|
-
| `
|
|
125
|
-
| `
|
|
126
|
-
|
|
|
127
|
-
| `
|
|
128
|
-
| `
|
|
129
|
-
|
|
|
130
|
-
| `
|
|
133
|
+
Configure the server using environment variables. These environmental variables are set within your MCP client config/settings (e.g. `cline_mcp_settings.json` for Cline, `claude_desktop_config.json` for Claude Desktop).
|
|
134
|
+
|
|
135
|
+
| Variable | Description | Required | Default |
|
|
136
|
+
| :------------------------------------ | :----------------------------------------------------------------------- | :------------------- | :----------------------- |
|
|
137
|
+
| **`OBSIDIAN_API_KEY`** | API Key from the Obsidian Local REST API plugin. | **Yes** | `undefined` |
|
|
138
|
+
| **`OBSIDIAN_BASE_URL`** | Base URL of your Obsidian Local REST API. | **Yes** | `http://127.0.0.1:27123` |
|
|
139
|
+
| `MCP_TRANSPORT_TYPE` | Server transport: `stdio` or `http`. | No | `stdio` |
|
|
140
|
+
| `MCP_HTTP_PORT` | Port for the HTTP server. | No | `3010` |
|
|
141
|
+
| `MCP_HTTP_HOST` | Host for the HTTP server. | No | `127.0.0.1` |
|
|
142
|
+
| `MCP_ALLOWED_ORIGINS` | Comma-separated origins for CORS. **Set for production.** | No | (none) |
|
|
143
|
+
| `MCP_AUTH_MODE` | Authentication strategy: `jwt` or `oauth`. | No | (none) |
|
|
144
|
+
| **`MCP_AUTH_SECRET_KEY`** | 32+ char secret for JWT. **Required for `jwt` mode.** | **Yes (if `jwt`)** | `undefined` |
|
|
145
|
+
| `OAUTH_ISSUER_URL` | URL of the OAuth 2.1 issuer. | **Yes (if `oauth`)** | `undefined` |
|
|
146
|
+
| `OAUTH_AUDIENCE` | Audience claim for OAuth tokens. | **Yes (if `oauth`)** | `undefined` |
|
|
147
|
+
| `OAUTH_JWKS_URI` | URI for the JSON Web Key Set (optional, derived from issuer if omitted). | No | (derived) |
|
|
148
|
+
| `MCP_LOG_LEVEL` | Logging level (`debug`, `info`, `error`, etc.). | No | `info` |
|
|
149
|
+
| `OBSIDIAN_VERIFY_SSL` | Set to `false` to disable SSL verification. | No | `true` |
|
|
150
|
+
| `OBSIDIAN_ENABLE_CACHE` | Set to `true` to enable the in-memory vault cache. | No | `true` |
|
|
151
|
+
| `OBSIDIAN_CACHE_REFRESH_INTERVAL_MIN` | Refresh interval for the vault cache in minutes. | No | `10` |
|
|
131
152
|
|
|
132
153
|
### Connecting to the Obsidian API
|
|
133
154
|
|
|
@@ -165,27 +186,6 @@ _Using the encrypted HTTPS URL:_
|
|
|
165
186
|
}
|
|
166
187
|
```
|
|
167
188
|
|
|
168
|
-
### MCP Client Settings
|
|
169
|
-
|
|
170
|
-
Add to your MCP client settings (e.g., `cline_mcp_settings.json`):
|
|
171
|
-
|
|
172
|
-
```json
|
|
173
|
-
{
|
|
174
|
-
"mcpServers": {
|
|
175
|
-
"obsidian-mcp-server": {
|
|
176
|
-
"command": "node",
|
|
177
|
-
"args": ["/path/to/your/obsidian-mcp-server/dist/index.js"],
|
|
178
|
-
"env": {
|
|
179
|
-
"OBSIDIAN_API_KEY": "YOUR_OBSIDIAN_API_KEY",
|
|
180
|
-
"OBSIDIAN_BASE_URL": "http://127.0.0.1:27123",
|
|
181
|
-
"OBSIDIAN_VERIFY_SSL": "false",
|
|
182
|
-
"OBSIDIAN_ENABLE_CACHE": "true"
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
```
|
|
188
|
-
|
|
189
189
|
## Project Structure
|
|
190
190
|
|
|
191
191
|
The codebase follows a modular structure within the `src/` directory:
|
|
@@ -199,7 +199,8 @@ src/
|
|
|
199
199
|
│ ├── server.ts # Server setup, transport handling, tool/resource registration
|
|
200
200
|
│ ├── resources/ # MCP Resource implementations (currently none)
|
|
201
201
|
│ ├── tools/ # MCP Tool implementations (subdirs per tool)
|
|
202
|
-
│ └── transports/ # Stdio and HTTP transport logic
|
|
202
|
+
│ └── transports/ # Stdio and HTTP transport logic
|
|
203
|
+
│ └── auth/ # Authentication strategies (JWT, OAuth)
|
|
203
204
|
├── services/ # Abstractions for external APIs or internal caching
|
|
204
205
|
│ └── obsidianRestAPI/ # Typed client for Obsidian Local REST API
|
|
205
206
|
├── types-global/ # Shared TypeScript type definitions (errors, etc.)
|
|
@@ -239,7 +240,7 @@ The Obsidian MCP Server provides a suite of tools for interacting with your vaul
|
|
|
239
240
|
| Tool Name | Description | Key Arguments |
|
|
240
241
|
| :---------------------------- | :-------------------------------------------------------- | :------------------------------------------------------------ |
|
|
241
242
|
| `obsidian_read_file` | Retrieves the content and metadata of a file. | `filePath`, `format?`, `includeStat?` |
|
|
242
|
-
| `
|
|
243
|
+
| `obsidian_update_note` | Modifies a file by appending, prepending, or overwriting. | `targetType`, `content`, `targetIdentifier?`, `wholeFileMode` |
|
|
243
244
|
| `obsidian_search_replace` | Performs search-and-replace operations in a note. | `targetType`, `replacements`, `useRegex?`, `replaceAll?` |
|
|
244
245
|
| `obsidian_global_search` | Searches the entire vault for content. | `query`, `searchInPath?`, `useRegex?`, `page?`, `pageSize?` |
|
|
245
246
|
| `obsidian_list_files` | Lists files and subdirectories in a folder. | `dirPath`, `fileExtensionFilter?`, `nameRegexFilter?` |
|
|
@@ -259,32 +260,23 @@ This server currently focuses on providing interactive tools for vault manipulat
|
|
|
259
260
|
|
|
260
261
|
### Build and Test
|
|
261
262
|
|
|
263
|
+
To get started with development, clone the repository, install dependencies, and use the following scripts:
|
|
264
|
+
|
|
262
265
|
```bash
|
|
263
|
-
#
|
|
264
|
-
npm
|
|
266
|
+
# Install dependencies
|
|
267
|
+
npm install
|
|
265
268
|
|
|
266
|
-
#
|
|
267
|
-
npm run
|
|
269
|
+
# Build the project (compile TS to JS in dist/ and make executable)
|
|
270
|
+
npm run rebuild
|
|
268
271
|
|
|
269
|
-
#
|
|
270
|
-
npm start
|
|
271
|
-
# or specifically:
|
|
272
|
-
npm run start:stdio
|
|
272
|
+
# Start the server locally using stdio transport
|
|
273
|
+
npm start:stdio
|
|
273
274
|
|
|
274
|
-
#
|
|
275
|
+
# Start the server using http transport
|
|
275
276
|
npm run start:http
|
|
276
277
|
|
|
277
|
-
#
|
|
278
|
-
npm run
|
|
279
|
-
|
|
280
|
-
# Clean build artifacts and then rebuild the project
|
|
281
|
-
npm run rebuild
|
|
282
|
-
|
|
283
|
-
# Fetch the Obsidian API spec (requires Obsidian running with Local REST API)
|
|
284
|
-
npm run fetch:spec http://127.0.0.1:27123/ docs/obsidian-api/obsidian_rest_api_spec
|
|
285
|
-
|
|
286
|
-
# Generate API documentation using TypeDoc
|
|
287
|
-
npm run docs:generate
|
|
278
|
+
# Format code using Prettier
|
|
279
|
+
npm run format
|
|
288
280
|
|
|
289
281
|
# Inspect the server's capabilities using the MCP Inspector tool
|
|
290
282
|
npm run inspect:stdio
|
|
@@ -24,7 +24,7 @@ import { registerObsidianGlobalSearchTool } from "./tools/obsidianGlobalSearchTo
|
|
|
24
24
|
import { registerObsidianListFilesTool } from "./tools/obsidianListFilesTool/index.js";
|
|
25
25
|
import { registerObsidianReadFileTool } from "./tools/obsidianReadFileTool/index.js";
|
|
26
26
|
import { registerObsidianSearchReplaceTool } from "./tools/obsidianSearchReplaceTool/index.js";
|
|
27
|
-
import {
|
|
27
|
+
import { registerObsidianUpdateNoteTool } from "./tools/obsidianUpdateNoteTool/index.js";
|
|
28
28
|
import { registerObsidianManageFrontmatterTool } from "./tools/obsidianManageFrontmatterTool/index.js";
|
|
29
29
|
import { registerObsidianManageTagsTool } from "./tools/obsidianManageTagsTool/index.js";
|
|
30
30
|
// Import transport setup functions.
|
|
@@ -93,7 +93,7 @@ async function createMcpServerInstance(obsidianService, vaultCacheService) {
|
|
|
93
93
|
logger.warning("Skipping registration of 'obsidian_global_search' because the Vault Cache Service is disabled.", context);
|
|
94
94
|
}
|
|
95
95
|
await registerObsidianSearchReplaceTool(server, obsidianService, vaultCacheService);
|
|
96
|
-
await
|
|
96
|
+
await registerObsidianUpdateNoteTool(server, obsidianService, vaultCacheService);
|
|
97
97
|
await registerObsidianManageFrontmatterTool(server, obsidianService, vaultCacheService);
|
|
98
98
|
await registerObsidianManageTagsTool(server, obsidianService, vaultCacheService);
|
|
99
99
|
logger.info("Resources and tools registered successfully", context);
|
|
@@ -118,9 +118,7 @@ async function buildFileTree(dirPath, currentDepth, params, context, obsidianSer
|
|
|
118
118
|
if (regex && !regex.test(cleanName)) {
|
|
119
119
|
continue;
|
|
120
120
|
}
|
|
121
|
-
if (!isDirectory &&
|
|
122
|
-
fileExtensionFilter &&
|
|
123
|
-
fileExtensionFilter.length > 0) {
|
|
121
|
+
if (!isDirectory && fileExtensionFilter && fileExtensionFilter.length > 0) {
|
|
124
122
|
const extension = path.posix.extname(name);
|
|
125
123
|
if (!fileExtensionFilter.includes(extension)) {
|
|
126
124
|
continue;
|
|
@@ -166,7 +164,10 @@ export const processObsidianListFiles = async (params, context, obsidianService)
|
|
|
166
164
|
try {
|
|
167
165
|
const effectiveDirPath = dirPath === "" ? "/" : dirPath;
|
|
168
166
|
// --- Step 1: Build the file tree recursively with retry for the initial call ---
|
|
169
|
-
const buildTreeContext = {
|
|
167
|
+
const buildTreeContext = {
|
|
168
|
+
...context,
|
|
169
|
+
operation: "buildFileTreeWithRetry",
|
|
170
|
+
};
|
|
170
171
|
const shouldRetryNotFound = (err) => err instanceof McpError && err.code === BaseErrorCode.NOT_FOUND;
|
|
171
172
|
const fileTree = await retryWithDelay(() => buildFileTree(effectiveDirPath, 0, // Start at depth 0
|
|
172
173
|
params, buildTreeContext, obsidianService), {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview Barrel file for the '
|
|
2
|
+
* @fileoverview Barrel file for the 'obsidian_update_note' MCP tool.
|
|
3
3
|
*
|
|
4
|
-
* This file serves as the public entry point for the
|
|
5
|
-
* It re-exports the primary registration function (`
|
|
4
|
+
* This file serves as the public entry point for the obsidian_update_note tool module.
|
|
5
|
+
* It re-exports the primary registration function (`registerObsidianUpdateNoteTool`)
|
|
6
6
|
* from the './registration.js' module. This pattern simplifies imports for consumers
|
|
7
7
|
* of the tool, allowing them to import necessary components from a single location.
|
|
8
8
|
*
|
|
9
9
|
* Consumers (like the main server setup) should import the registration function
|
|
10
10
|
* from this file to integrate the tool into the MCP server instance.
|
|
11
11
|
*/
|
|
12
|
-
export {
|
|
12
|
+
export { registerObsidianUpdateNoteTool } from "./registration.js";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview Barrel file for the '
|
|
2
|
+
* @fileoverview Barrel file for the 'obsidian_update_note' MCP tool.
|
|
3
3
|
*
|
|
4
|
-
* This file serves as the public entry point for the
|
|
5
|
-
* It re-exports the primary registration function (`
|
|
4
|
+
* This file serves as the public entry point for the obsidian_update_note tool module.
|
|
5
|
+
* It re-exports the primary registration function (`registerObsidianUpdateNoteTool`)
|
|
6
6
|
* from the './registration.js' module. This pattern simplifies imports for consumers
|
|
7
7
|
* of the tool, allowing them to import necessary components from a single location.
|
|
8
8
|
*
|
|
9
9
|
* Consumers (like the main server setup) should import the registration function
|
|
10
10
|
* from this file to integrate the tool into the MCP server instance.
|
|
11
11
|
*/
|
|
12
|
-
export {
|
|
12
|
+
export { registerObsidianUpdateNoteTool } from "./registration.js";
|
|
@@ -8,7 +8,7 @@ import { RequestContext } from "../../../utils/index.js";
|
|
|
8
8
|
* relying on the refined schema (`ObsidianUpdateFileInputSchema`) for stricter validation
|
|
9
9
|
* within the handler logic.
|
|
10
10
|
*/
|
|
11
|
-
declare const
|
|
11
|
+
declare const ObsidianUpdateNoteRegistrationSchema: z.ZodObject<{
|
|
12
12
|
/** Specifies the target note: 'filePath' (requires targetIdentifier), 'activeFile' (currently open file), or 'periodicNote' (requires targetIdentifier with period like 'daily'). */
|
|
13
13
|
targetType: z.ZodEnum<["filePath", "activeFile", "periodicNote"]>;
|
|
14
14
|
/** The content for the modification. Must be a string for whole-file operations. */
|
|
@@ -48,7 +48,7 @@ declare const ObsidianUpdateFileRegistrationSchema: z.ZodObject<{
|
|
|
48
48
|
* The shape of the registration schema, used by `server.tool` for basic validation.
|
|
49
49
|
* @see ObsidianUpdateFileRegistrationSchema
|
|
50
50
|
*/
|
|
51
|
-
export declare const
|
|
51
|
+
export declare const ObsidianUpdateNoteInputSchemaShape: {
|
|
52
52
|
/** Specifies the target note: 'filePath' (requires targetIdentifier), 'activeFile' (currently open file), or 'periodicNote' (requires targetIdentifier with period like 'daily'). */
|
|
53
53
|
targetType: z.ZodEnum<["filePath", "activeFile", "periodicNote"]>;
|
|
54
54
|
/** The content for the modification. Must be a string for whole-file operations. */
|
|
@@ -71,13 +71,13 @@ export declare const ObsidianUpdateFileInputSchemaShape: {
|
|
|
71
71
|
* received by the tool handler *before* refinement.
|
|
72
72
|
* @see ObsidianUpdateFileRegistrationSchema
|
|
73
73
|
*/
|
|
74
|
-
export type
|
|
74
|
+
export type ObsidianUpdateNoteRegistrationInput = z.infer<typeof ObsidianUpdateNoteRegistrationSchema>;
|
|
75
75
|
/**
|
|
76
76
|
* Refined Zod schema used internally within the tool's logic for strict validation.
|
|
77
77
|
* It builds upon `WholeFileUpdateSchema` and adds cross-field validation rules using `.refine()`.
|
|
78
78
|
* This ensures that `targetIdentifier` is provided and valid when required by `targetType`.
|
|
79
79
|
*/
|
|
80
|
-
export declare const
|
|
80
|
+
export declare const ObsidianUpdateNoteInputSchema: z.ZodEffects<z.ZodObject<{
|
|
81
81
|
/** Specifies the type of target note. */
|
|
82
82
|
targetType: z.ZodEnum<["filePath", "activeFile", "periodicNote"]>;
|
|
83
83
|
/** The content to use for the modification. Must be a string for whole-file operations. */
|
|
@@ -140,7 +140,7 @@ export declare const ObsidianUpdateFileInputSchema: z.ZodEffects<z.ZodObject<{
|
|
|
140
140
|
* TypeScript type inferred from the *refined* input schema (`ObsidianUpdateFileInputSchema`).
|
|
141
141
|
* This type represents the validated and structured input used within the core processing logic.
|
|
142
142
|
*/
|
|
143
|
-
export type
|
|
143
|
+
export type ObsidianUpdateNoteInput = z.infer<typeof ObsidianUpdateNoteInputSchema>;
|
|
144
144
|
/**
|
|
145
145
|
* Represents the structure of file statistics after formatting, including
|
|
146
146
|
* human-readable timestamps and an estimated token count.
|
|
@@ -157,7 +157,7 @@ type FormattedStat = {
|
|
|
157
157
|
* Defines the structure of the successful response returned by the `processObsidianUpdateFile` function.
|
|
158
158
|
* This object is typically serialized to JSON and sent back to the client.
|
|
159
159
|
*/
|
|
160
|
-
export interface
|
|
160
|
+
export interface ObsidianUpdateNoteResponse {
|
|
161
161
|
/** Indicates whether the operation was successful. */
|
|
162
162
|
success: boolean;
|
|
163
163
|
/** A human-readable message describing the outcome of the operation. */
|
|
@@ -178,6 +178,6 @@ export interface ObsidianUpdateFileResponse {
|
|
|
178
178
|
* @returns {Promise<ObsidianUpdateFileResponse>} A promise resolving to the structured success response.
|
|
179
179
|
* @throws {McpError} Throws an McpError if validation fails or the API interaction results in an error.
|
|
180
180
|
*/
|
|
181
|
-
export declare const
|
|
182
|
-
context: RequestContext, obsidianService: ObsidianRestApiService, vaultCacheService: VaultCacheService | undefined) => Promise<
|
|
181
|
+
export declare const processObsidianUpdateNote: (params: ObsidianUpdateNoteInput, // Use the refined, validated type
|
|
182
|
+
context: RequestContext, obsidianService: ObsidianRestApiService, vaultCacheService: VaultCacheService | undefined) => Promise<ObsidianUpdateNoteResponse>;
|
|
183
183
|
export {};
|
|
@@ -79,7 +79,7 @@ const WholeFileUpdateSchema = BaseUpdateSchema.extend({
|
|
|
79
79
|
* relying on the refined schema (`ObsidianUpdateFileInputSchema`) for stricter validation
|
|
80
80
|
* within the handler logic.
|
|
81
81
|
*/
|
|
82
|
-
const
|
|
82
|
+
const ObsidianUpdateNoteRegistrationSchema = z
|
|
83
83
|
.object({
|
|
84
84
|
/** Specifies the target note: 'filePath' (requires targetIdentifier), 'activeFile' (currently open file), or 'periodicNote' (requires targetIdentifier with period like 'daily'). */
|
|
85
85
|
targetType: TargetTypeSchema,
|
|
@@ -122,7 +122,7 @@ const ObsidianUpdateFileRegistrationSchema = z
|
|
|
122
122
|
* The shape of the registration schema, used by `server.tool` for basic validation.
|
|
123
123
|
* @see ObsidianUpdateFileRegistrationSchema
|
|
124
124
|
*/
|
|
125
|
-
export const
|
|
125
|
+
export const ObsidianUpdateNoteInputSchemaShape = ObsidianUpdateNoteRegistrationSchema.shape;
|
|
126
126
|
// ====================================================================================
|
|
127
127
|
// Refined Schema for Internal Logic and Strict Validation
|
|
128
128
|
// ====================================================================================
|
|
@@ -131,7 +131,7 @@ export const ObsidianUpdateFileInputSchemaShape = ObsidianUpdateFileRegistration
|
|
|
131
131
|
* It builds upon `WholeFileUpdateSchema` and adds cross-field validation rules using `.refine()`.
|
|
132
132
|
* This ensures that `targetIdentifier` is provided and valid when required by `targetType`.
|
|
133
133
|
*/
|
|
134
|
-
export const
|
|
134
|
+
export const ObsidianUpdateNoteInputSchema = WholeFileUpdateSchema.refine((data) => {
|
|
135
135
|
// Rule 1: If targetType is 'filePath' or 'periodicNote', targetIdentifier must be provided.
|
|
136
136
|
if ((data.targetType === "filePath" || data.targetType === "periodicNote") &&
|
|
137
137
|
!data.targetIdentifier) {
|
|
@@ -207,9 +207,9 @@ async function getFinalState(targetType, targetIdentifier, period, obsidianServi
|
|
|
207
207
|
* @returns {Promise<ObsidianUpdateFileResponse>} A promise resolving to the structured success response.
|
|
208
208
|
* @throws {McpError} Throws an McpError if validation fails or the API interaction results in an error.
|
|
209
209
|
*/
|
|
210
|
-
export const
|
|
210
|
+
export const processObsidianUpdateNote = async (params, // Use the refined, validated type
|
|
211
211
|
context, obsidianService, vaultCacheService) => {
|
|
212
|
-
logger.debug(`Processing
|
|
212
|
+
logger.debug(`Processing obsidian_update_note request (wholeFile mode)`, {
|
|
213
213
|
...context,
|
|
214
214
|
targetType: params.targetType,
|
|
215
215
|
wholeFileMode: params.wholeFileMode,
|
|
@@ -251,7 +251,7 @@ context, obsidianService, vaultCacheService) => {
|
|
|
251
251
|
existsBefore = true;
|
|
252
252
|
logger.debug(`Target exists before operation.`, checkContext);
|
|
253
253
|
}, {
|
|
254
|
-
operationName: "
|
|
254
|
+
operationName: "existenceCheckObsidianUpdateNote",
|
|
255
255
|
context: checkContext,
|
|
256
256
|
maxRetries: 3, // Total attempts: 1 initial + 2 retries
|
|
257
257
|
delayMs: 250,
|
|
@@ -263,7 +263,7 @@ context, obsidianService, vaultCacheService) => {
|
|
|
263
263
|
params.createIfNeeded;
|
|
264
264
|
if (error instanceof McpError &&
|
|
265
265
|
error.code === BaseErrorCode.NOT_FOUND) {
|
|
266
|
-
logger.debug(`
|
|
266
|
+
logger.debug(`existenceCheckObsidianUpdateNote: shouldRetry=${should} for NOT_FOUND (createIfNeeded: ${params.createIfNeeded})`, checkContext);
|
|
267
267
|
}
|
|
268
268
|
return should;
|
|
269
269
|
},
|
package/dist/mcp-server/tools/{obsidianUpdateFileTool → obsidianUpdateNoteTool}/registration.d.ts
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { ObsidianRestApiService, VaultCacheService } from "../../../services/obsidianRestAPI/index.js";
|
|
3
3
|
/**
|
|
4
|
-
* Registers the '
|
|
4
|
+
* Registers the 'obsidian_update_note' tool with the MCP server.
|
|
5
5
|
*
|
|
6
6
|
* This tool allows modification of Obsidian notes (specified by file path,
|
|
7
7
|
* the active file, or a periodic note) using whole-file operations:
|
|
@@ -18,4 +18,4 @@ import { ObsidianRestApiService, VaultCacheService } from "../../../services/obs
|
|
|
18
18
|
* @returns {Promise<void>} A promise that resolves when the tool registration is complete or rejects on error.
|
|
19
19
|
* @throws {McpError} Throws an McpError if registration fails critically.
|
|
20
20
|
*/
|
|
21
|
-
export declare const
|
|
21
|
+
export declare const registerObsidianUpdateNoteTool: (server: McpServer, obsidianService: ObsidianRestApiService, vaultCacheService: VaultCacheService | undefined) => Promise<void>;
|
package/dist/mcp-server/tools/{obsidianUpdateFileTool → obsidianUpdateNoteTool}/registration.js
RENAMED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BaseErrorCode, McpError } from "../../../types-global/errors.js";
|
|
2
2
|
import { ErrorHandler, logger, requestContextService, } from "../../../utils/index.js";
|
|
3
3
|
// Import the Zod schema for validation and the core processing logic
|
|
4
|
-
import {
|
|
4
|
+
import { ObsidianUpdateNoteInputSchema, ObsidianUpdateNoteInputSchemaShape, processObsidianUpdateNote, } from "./logic.js";
|
|
5
5
|
/**
|
|
6
|
-
* Registers the '
|
|
6
|
+
* Registers the 'obsidian_update_note' tool with the MCP server.
|
|
7
7
|
*
|
|
8
8
|
* This tool allows modification of Obsidian notes (specified by file path,
|
|
9
9
|
* the active file, or a periodic note) using whole-file operations:
|
|
@@ -20,26 +20,26 @@ import { ObsidianUpdateFileInputSchema, ObsidianUpdateFileInputSchemaShape, proc
|
|
|
20
20
|
* @returns {Promise<void>} A promise that resolves when the tool registration is complete or rejects on error.
|
|
21
21
|
* @throws {McpError} Throws an McpError if registration fails critically.
|
|
22
22
|
*/
|
|
23
|
-
export const
|
|
24
|
-
const toolName = "
|
|
23
|
+
export const registerObsidianUpdateNoteTool = async (server, obsidianService, vaultCacheService) => {
|
|
24
|
+
const toolName = "obsidian_update_note";
|
|
25
25
|
const toolDescription = "Tool to modify Obsidian notes (specified by file path, the active file, or a periodic note) using whole-file operations: 'append', 'prepend', or 'overwrite'. Options allow creating missing files/targets and controlling overwrite behavior. Returns success status, message, a formatted timestamp string, file stats (stats), and optionally the final file content.";
|
|
26
26
|
// Create a context for the registration process itself for better traceability.
|
|
27
27
|
const registrationContext = requestContextService.createRequestContext({
|
|
28
|
-
operation: "
|
|
28
|
+
operation: "RegisterObsidianUpdateNoteTool",
|
|
29
29
|
toolName: toolName,
|
|
30
|
-
module: "
|
|
30
|
+
module: "ObsidianUpdateNoteRegistration", // Identify the module performing registration
|
|
31
31
|
});
|
|
32
32
|
logger.info(`Attempting to register tool: ${toolName}`, registrationContext);
|
|
33
33
|
// Wrap the registration in a tryCatch block for robust error handling during setup.
|
|
34
34
|
await ErrorHandler.tryCatch(async () => {
|
|
35
35
|
// Use the high-level SDK method for tool registration.
|
|
36
36
|
// This handles schema generation, validation, and routing automatically.
|
|
37
|
-
server.tool(toolName, toolDescription,
|
|
37
|
+
server.tool(toolName, toolDescription, ObsidianUpdateNoteInputSchemaShape, // Provide the Zod schema shape for input validation.
|
|
38
38
|
/**
|
|
39
|
-
* The handler function executed when the '
|
|
39
|
+
* The handler function executed when the 'obsidian_update_note' tool is called.
|
|
40
40
|
*
|
|
41
|
-
* @param {
|
|
42
|
-
* matching the structure defined by
|
|
41
|
+
* @param {ObsidianUpdateNoteRegistrationInput} params - The raw input parameters received from the client,
|
|
42
|
+
* matching the structure defined by ObsidianUpdateNoteInputSchemaShape.
|
|
43
43
|
* @returns {Promise<CallToolResult>} A promise resolving to the structured result for the MCP client,
|
|
44
44
|
* containing either the successful response data or an error indication.
|
|
45
45
|
*/
|
|
@@ -47,7 +47,7 @@ export const registerObsidianUpdateFileTool = async (server, obsidianService, va
|
|
|
47
47
|
// Create a specific context for this handler invocation.
|
|
48
48
|
const handlerContext = requestContextService.createRequestContext({
|
|
49
49
|
parentContext: registrationContext, // Link to the registration context
|
|
50
|
-
operation: "
|
|
50
|
+
operation: "HandleObsidianUpdateNoteRequest",
|
|
51
51
|
toolName: toolName,
|
|
52
52
|
params: {
|
|
53
53
|
// Log key parameters for easier debugging, content is omitted for brevity/security
|
|
@@ -67,10 +67,10 @@ export const registerObsidianUpdateFileTool = async (server, obsidianService, va
|
|
|
67
67
|
// This ensures type safety and adherence to constraints defined in logic.ts.
|
|
68
68
|
// While server.tool performs initial validation based on the shape,
|
|
69
69
|
// this step applies any stricter rules or refinements from the full schema.
|
|
70
|
-
const validatedParams =
|
|
70
|
+
const validatedParams = ObsidianUpdateNoteInputSchema.parse(params);
|
|
71
71
|
// Delegate the actual file update logic to the dedicated processing function.
|
|
72
72
|
// Pass the validated parameters, the handler context, and the Obsidian service instance.
|
|
73
|
-
const response = await
|
|
73
|
+
const response = await processObsidianUpdateNote(validatedParams, handlerContext, obsidianService, vaultCacheService);
|
|
74
74
|
logger.debug(`'${toolName}' (wholeFile mode) processed successfully`, handlerContext);
|
|
75
75
|
// Format the successful response from the logic function into the MCP CallToolResult structure.
|
|
76
76
|
// The response object (containing status, message, timestamp, stat, etc.) is serialized to JSON.
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
* from the middleware layer down to the tool and resource handlers without
|
|
6
6
|
* drilling props.
|
|
7
7
|
*
|
|
8
|
-
* @module src/mcp-server/transports/
|
|
8
|
+
* @module src/mcp-server/transports/auth/core/authContext
|
|
9
9
|
*/
|
|
10
10
|
import { AsyncLocalStorage } from "async_hooks";
|
|
11
|
-
import type { AuthInfo } from "./
|
|
11
|
+
import type { AuthInfo } from "./authTypes.js";
|
|
12
12
|
/**
|
|
13
13
|
* Defines the structure of the store used within the AsyncLocalStorage.
|
|
14
14
|
* It holds the authentication information for the current request context.
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* from the middleware layer down to the tool and resource handlers without
|
|
6
6
|
* drilling props.
|
|
7
7
|
*
|
|
8
|
-
* @module src/mcp-server/transports/
|
|
8
|
+
* @module src/mcp-server/transports/auth/core/authContext
|
|
9
9
|
*/
|
|
10
10
|
import { AsyncLocalStorage } from "async_hooks";
|
|
11
11
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Shared types for authentication middleware.
|
|
3
|
-
* @module src/mcp-server/transports/
|
|
3
|
+
* @module src/mcp-server/transports/auth/core/auth.types
|
|
4
4
|
*/
|
|
5
5
|
import type { AuthInfo as SdkAuthInfo } from "@modelcontextprotocol/sdk/server/auth/types.js";
|
|
6
6
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Provides utility functions for authorization, specifically for
|
|
3
3
|
* checking token scopes against required permissions for a given operation.
|
|
4
|
-
* @module src/mcp-server/transports/
|
|
4
|
+
* @module src/mcp-server/transports/auth/core/authUtils
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
7
|
* Checks if the current authentication context contains all the specified scopes.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Provides utility functions for authorization, specifically for
|
|
3
3
|
* checking token scopes against required permissions for a given operation.
|
|
4
|
-
* @module src/mcp-server/transports/
|
|
4
|
+
* @module src/mcp-server/transports/auth/core/authUtils
|
|
5
5
|
*/
|
|
6
|
-
import { BaseErrorCode, McpError } from "
|
|
7
|
-
import { logger, requestContextService } from "
|
|
6
|
+
import { BaseErrorCode, McpError } from "../../../../types-global/errors.js";
|
|
7
|
+
import { logger, requestContextService } from "../../../../utils/index.js";
|
|
8
8
|
import { authContext } from "./authContext.js";
|
|
9
9
|
/**
|
|
10
10
|
* Checks if the current authentication context contains all the specified scopes.
|