obsidian-mcp-server 2.0.3 → 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 +22 -0
- package/README.md +80 -88
- package/dist/mcp-server/server.js +2 -2
- package/dist/mcp-server/tools/obsidianListFilesTool/logic.d.ts +20 -16
- package/dist/mcp-server/tools/obsidianListFilesTool/logic.js +142 -106
- package/dist/mcp-server/tools/obsidianListFilesTool/registration.d.ts +9 -5
- package/dist/mcp-server/tools/obsidianListFilesTool/registration.js +11 -9
- 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,28 @@ 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
|
+
|
|
17
|
+
## [2.0.4] - 2025-06-13
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- **Recursive File Listing**: The `obsidian_list_files` tool now supports recursive listing of directories with a `recursionDepth` parameter.
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- **Documentation**:
|
|
26
|
+
- Consolidated tool specifications into `obsidian_mcp_tools_spec.md`.
|
|
27
|
+
- Updated `.clinerules` with a detailed logger implementation example for the agent.
|
|
28
|
+
- Updated the repository's directory tree documentation.
|
|
29
|
+
|
|
8
30
|
## [2.0.3] - 2025-06-12
|
|
9
31
|
|
|
10
32
|
### Fixed
|
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);
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Core logic for the 'obsidian_list_files' tool.
|
|
3
|
+
* This module defines the input schema, response types, and processing logic for
|
|
4
|
+
* recursively listing files and directories in an Obsidian vault with filtering.
|
|
5
|
+
* @module src/mcp-server/tools/obsidianListFilesTool/logic
|
|
6
|
+
*/
|
|
1
7
|
import { z } from "zod";
|
|
2
8
|
import { ObsidianRestApiService } from "../../../services/obsidianRestAPI/index.js";
|
|
3
9
|
import { RequestContext } from "../../../utils/index.js";
|
|
@@ -7,58 +13,56 @@ import { RequestContext } from "../../../utils/index.js";
|
|
|
7
13
|
export declare const ObsidianListFilesInputSchema: z.ZodObject<{
|
|
8
14
|
/**
|
|
9
15
|
* The vault-relative path to the directory whose contents should be listed.
|
|
10
|
-
* Examples: "Attachments/Images", "Projects", "" (for vault root), "/" (for vault root).
|
|
11
16
|
* The path is treated as case-sensitive by the underlying Obsidian API.
|
|
12
17
|
*/
|
|
13
18
|
dirPath: z.ZodString;
|
|
14
19
|
/**
|
|
15
20
|
* Optional array of file extensions (including the leading dot) to filter the results.
|
|
16
|
-
* Only files matching one of these extensions will be included. Directories are always included
|
|
17
|
-
* Example: [".md", ".png"]
|
|
21
|
+
* Only files matching one of these extensions will be included. Directories are always included.
|
|
18
22
|
*/
|
|
19
23
|
fileExtensionFilter: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
20
24
|
/**
|
|
21
25
|
* Optional JavaScript-compatible regular expression pattern string to filter results by name.
|
|
22
26
|
* Only files and directories whose names match the regex will be included.
|
|
23
|
-
* Example: "^\\d{4}-\\d{2}-\\d{2}" (matches names starting with YYYY-MM-DD)
|
|
24
27
|
*/
|
|
25
28
|
nameRegexFilter: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
29
|
+
/**
|
|
30
|
+
* The maximum depth of subdirectories to list recursively.
|
|
31
|
+
* - A value of `0` lists only the files and directories in the specified `dirPath`.
|
|
32
|
+
* - A value of `1` lists the contents of `dirPath` and the contents of its immediate subdirectories.
|
|
33
|
+
* - A value of `-1` (the default) indicates infinite recursion, listing all subdirectories.
|
|
34
|
+
*/
|
|
35
|
+
recursionDepth: z.ZodDefault<z.ZodNumber>;
|
|
26
36
|
}, "strip", z.ZodTypeAny, {
|
|
27
37
|
dirPath: string;
|
|
38
|
+
recursionDepth: number;
|
|
28
39
|
fileExtensionFilter?: string[] | undefined;
|
|
29
40
|
nameRegexFilter?: string | null | undefined;
|
|
30
41
|
}, {
|
|
31
42
|
dirPath: string;
|
|
32
43
|
fileExtensionFilter?: string[] | undefined;
|
|
33
44
|
nameRegexFilter?: string | null | undefined;
|
|
45
|
+
recursionDepth?: number | undefined;
|
|
34
46
|
}>;
|
|
35
47
|
/**
|
|
36
48
|
* TypeScript type inferred from the input schema (`ObsidianListFilesInputSchema`).
|
|
37
|
-
* Represents the validated input parameters used within the core processing logic.
|
|
38
49
|
*/
|
|
39
50
|
export type ObsidianListFilesInput = z.infer<typeof ObsidianListFilesInputSchema>;
|
|
40
51
|
/**
|
|
41
|
-
* Defines the structure of the successful response returned by the
|
|
42
|
-
* This object is typically serialized to JSON and sent back to the client.
|
|
52
|
+
* Defines the structure of the successful response returned by the core logic function.
|
|
43
53
|
*/
|
|
44
54
|
export interface ObsidianListFilesResponse {
|
|
45
|
-
/** The vault-relative path of the directory whose contents were listed (normalized, e.g., "/" for root). */
|
|
46
55
|
directoryPath: string;
|
|
47
|
-
/** A string representation of the directory contents formatted as a simple tree structure. */
|
|
48
56
|
tree: string;
|
|
49
|
-
/** The total number of files and directories included in the formatted tree after filtering. */
|
|
50
57
|
totalEntries: number;
|
|
51
58
|
}
|
|
52
59
|
/**
|
|
53
|
-
* Processes the core logic for listing files and directories within
|
|
54
|
-
* directory in the Obsidian vault. Applies optional filters and formats the output.
|
|
60
|
+
* Processes the core logic for listing files and directories recursively within the Obsidian vault.
|
|
55
61
|
*
|
|
56
62
|
* @param {ObsidianListFilesInput} params - The validated input parameters.
|
|
57
63
|
* @param {RequestContext} context - The request context for logging and correlation.
|
|
58
64
|
* @param {ObsidianRestApiService} obsidianService - An instance of the Obsidian REST API service.
|
|
59
|
-
* @returns {Promise<ObsidianListFilesResponse>} A promise resolving to the structured success response
|
|
60
|
-
*
|
|
61
|
-
* @throws {McpError} Throws an McpError if the directory cannot be listed (e.g., not found)
|
|
62
|
-
* or if any other API interaction or validation fails.
|
|
65
|
+
* @returns {Promise<ObsidianListFilesResponse>} A promise resolving to the structured success response.
|
|
66
|
+
* @throws {McpError} Throws an McpError if the initial directory is not found or another error occurs.
|
|
63
67
|
*/
|
|
64
68
|
export declare const processObsidianListFiles: (params: ObsidianListFilesInput, context: RequestContext, obsidianService: ObsidianRestApiService) => Promise<ObsidianListFilesResponse>;
|