8 Commits

Author SHA1 Message Date
fe12e00e03 chore: bump version to 1.1.4 and update CHANGELOG
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-28 12:16:57 -05:00
3922056b25 fix: preserve Markdown code fences by escaping backticks instead of removing them (fixes #6)
Backticks were being stripped entirely by the sanitizer, destroying
Markdown code fences (```) in note content.

The real injection risk is backtick command substitution inside
double-quoted shell strings (e.g. content=`rm -rf /`). The fix is to
escape backticks as \` in formatParam — exactly as we already do for
double quotes — so the shell never interprets them while the content
is preserved intact.

Changes:
- sanitizer.ts: remove ` from DANGEROUS_CHARS and the backtick command
  substitution pattern from COMMAND_INJECTION_PATTERNS (now handled at
  the quoting layer, not the stripping layer)
- cli-helpers.ts: escape backticks as \` in formatParam alongside the
  existing double-quote escaping

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-28 12:15:28 -05:00
edd445f8ae docs: update CHANGELOG for v1.1.3
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-17 17:55:16 -05:00
c8abde8a88 chore: bump version to 1.1.3
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-17 17:38:55 -05:00
a0801a82fd fix: chunk large note reads to prevent output-too-large errors (fixes #5)
Add offset and max_chars parameters to obsidian_read_note:
- max_chars (default 50000, max 500000): caps characters returned per call
- offset (default 0): start position for reading, enabling pagination

When content is truncated a trailer message is appended telling the
caller the total size and the exact offset to pass on the next call.

This prevents the 26MB+ responses that caused Claude to reject output
when reading large PDFs stored in an Obsidian vault.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-17 17:36:33 -05:00
82d2409fe3 docs: clarify Obsidian must be running before using MCP tools (fixes #4)
- Add prominent note in Prerequisites that Obsidian must be open and running
- Expand Troubleshooting section with explanation of why the error occurs and how to fix it

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-16 09:22:57 -05:00
57b58a0d22 fix: allow ampersands in filenames while blocking command injection (v1.1.2)
Fixes #2 - Files with & in their names (e.g., 'Research & Development.md')
were being incorrectly sanitized, causing search and file-not-found errors.

Changes:
- Removed & from DANGEROUS_CHARS regex
- Single & is safe in quoted arguments passed to CLI
- Dangerous && patterns still blocked by COMMAND_INJECTION_PATTERNS
- Also allows (), [], {} which are safe in quoted args

Version: 1.1.2

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-14 17:05:18 -05:00
466587d1c5 fix: preserve square brackets and escape quotes in note content (v1.1.1)
- Fix square bracket removal: Remove [] from DANGEROUS_CHARS regex
  * Wikilinks ([[link]]) now work correctly
  * Task checkboxes (- [ ] Task) are properly preserved
  * Brackets are safe because values are quoted and passed as array args

- Fix quote truncation: Escape double quotes in formatParam
  * Content like "Bot QM" no longer truncates
  * Internal quotes escaped as \" before wrapping in parameter quotes
  * Prevents shell from misinterpreting quote boundaries

Bump version: 1.0.0 -> 1.1.1

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-10 00:07:13 -05:00
8 changed files with 125 additions and 16 deletions

View File

@@ -73,6 +73,56 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Comprehensive input schema definitions - Comprehensive input schema definitions
- Security audit of parameter handling - Security audit of parameter handling
## [1.1.4] - 2026-04-28
### Fixed
- **Markdown Code Fence Preservation**: Fixed issue #6 where backticks were being stripped from note content, destroying Markdown code fences (` ``` `)
- Backticks are now escaped as `` \` `` inside double-quoted CLI parameter strings instead of being removed
- This preserves code fences and inline code in note content while still preventing shell command substitution via backticks
- Affects all tools that pass content: create, append, prepend, etc.
## [1.1.3] - 2026-04-17
### Fixed
- **Large File Chunking**: Fixed issue #5 where reading large files (e.g. PDFs) caused a "Tool result is too large" error in Claude Desktop
- `obsidian_read_note` now returns at most 50,000 characters by default (configurable up to 500,000)
- New `max_chars` parameter caps the number of characters returned per call (default: 50000, max: 500000)
- New `offset` parameter enables pagination — pass the offset from the truncation message to read the next chunk
- When truncated, the response includes a message stating the total size and the exact `offset` to use for the next call
### Documentation
- **Obsidian Must Be Running**: Clarified in README (issue #4) that the Obsidian application must be open and running before any MCP tools are used
- Added prominent callout in Prerequisites section
- Expanded Troubleshooting entry with explanation of root cause and fix
## [1.1.2] - 2026-04-14
### Fixed
- **Ampersand in Filenames**: Fixed issue #2 where files with `&` in their names (e.g., "Research & Development.md") were causing search and file-not-found errors
- Single ampersands are now preserved in filenames and paths
- Security maintained: Dangerous `&&` command operators are still blocked by injection pattern detection
- Also preserves parentheses `()`, brackets `[]`, and braces `{}` which are safe in quoted CLI arguments
- Affects all file operations and search tools
## [1.1.1] - 2026-04-10
### Fixed
- **Quote Escaping**: Fixed critical bug where note content was being truncated when containing double quotes
- Content like `"Bot QM"` is now properly escaped and passed to the CLI without truncation
- Internal double quotes are escaped as `\"` before being wrapped in parameter quotes
- Prevents shell from misinterpreting quote boundaries in parameter values
- Affects all tools that pass content: create, append, prepend, search queries, etc.
## [1.1.0] - 2026-04-10
### Fixed
- **Square Brackets Preservation**: Fixed critical bug where square brackets `[` and `]` were being removed from note content during sanitization
- Wikilinks (`[[link]]`) now work correctly when creating or modifying notes
- Task checkboxes (`- [ ] Task` and `- [x] Done`) are properly preserved
- Array notation and date formats with brackets are no longer corrupted
- Security: Square brackets are safe because parameter values are quoted and passed as array arguments to the CLI
- All dangerous shell metacharacters (`;`, `|`, `$()`, backticks, etc.) are still properly blocked
## [Unreleased] ## [Unreleased]
### Planned ### Planned
@@ -86,9 +136,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Version History ## Version History
- **1.1.3** - Bug fix release: Large file chunking for obsidian_read_note; docs clarification for Obsidian must be running (fixes #4, #5)
- **1.1.2** - Bug fix release: Ampersand support in filenames (fixes #2)
- **1.1.1** - Bug fix release: Quote escaping in note content
- **1.1.0** - Bug fix release: Square brackets preservation in note content
- **1.0.0** - Initial release with 28 MCP tools across 3 user stories - **1.0.0** - Initial release with 28 MCP tools across 3 user stories
- File Operations (8 tools) - File Operations (8 tools)
- Search & Discovery (12 tools) - Search & Discovery (12 tools)
- Task & Property Management (8 tools) - Task & Property Management (8 tools)
[1.0.0]: https://github.com/yourusername/obsidian-mcp/releases/tag/v1.0.0 [1.1.4]: https://git.mortons.site/Peter.Morton/obsidian-mcp/releases/tag/v1.1.4
[1.1.3]: https://git.mortons.site/Peter.Morton/obsidian-mcp/releases/tag/v1.1.3
[1.1.2]: https://git.mortons.site/Peter.Morton/obsidian-mcp/releases/tag/v1.1.2
[1.1.1]: https://git.mortons.site/Peter.Morton/obsidian-mcp/releases/tag/v1.1.1
[1.1.0]: https://git.mortons.site/Peter.Morton/obsidian-mcp/releases/tag/v1.1.0
[1.0.0]: https://git.mortons.site/Peter.Morton/obsidian-mcp/releases/tag/v1.0.0

View File

@@ -19,7 +19,9 @@ An MCP (Model Context Protocol) Bundle that exposes Obsidian CLI capabilities to
- Node.js >= 18.0.0 - Node.js >= 18.0.0
- Obsidian CLI installed and configured - Obsidian CLI installed and configured
- Obsidian application installed - Obsidian application installed and **running**
> **Important:** The Obsidian application must be open and running before using any MCP tools. The CLI used by this bundle communicates with the running Obsidian instance. If Obsidian is not running, commands will launch the GUI instead of executing — start Obsidian first, then use the MCP tools.
### Install via Claude Desktop ### Install via Claude Desktop
@@ -194,7 +196,9 @@ Contributions are welcome! Please ensure:
### "Obsidian not running" error ### "Obsidian not running" error
Start the Obsidian application before using MCP tools. The Obsidian application must be running before using any MCP tools. The CLI communicates with the running Obsidian instance — if Obsidian is closed, commands will launch the GUI app instead of executing.
**Fix:** Open the Obsidian application and wait for it to fully load, then retry the operation.
### "Vault not found" error ### "Vault not found" error

View File

@@ -1,7 +1,7 @@
{ {
"manifest_version": "0.3", "manifest_version": "0.3",
"name": "obsidian-mcp", "name": "obsidian-mcp",
"version": "1.0.0", "version": "1.1.4",
"display_name": "Obsidian CLI Bundle", "display_name": "Obsidian CLI Bundle",
"description": "MCP Bundle for Obsidian CLI - Enable AI assistants to manage Obsidian vaults through conversational interface", "description": "MCP Bundle for Obsidian CLI - Enable AI assistants to manage Obsidian vaults through conversational interface",
"long_description": "This MCP bundle provides a comprehensive set of tools for AI assistants to interact with and manage Obsidian vaults. It includes capabilities for creating, reading, updating, and deleting notes, managing links and tags, handling tasks, and more. With this bundle, AI assistants can seamlessly integrate with Obsidian to help users organize their knowledge and workflows.", "long_description": "This MCP bundle provides a comprehensive set of tools for AI assistants to interact with and manage Obsidian vaults. It includes capabilities for creating, reading, updating, and deleting notes, managing links and tags, handling tasks, and more. With this bundle, AI assistants can seamlessly integrate with Obsidian to help users organize their knowledge and workflows.",

View File

@@ -1,6 +1,6 @@
{ {
"name": "obsidian-mcp", "name": "obsidian-mcp",
"version": "1.0.0", "version": "1.1.4",
"description": "MCP Bundle for Obsidian CLI - Enable AI assistants to manage Obsidian vaults through Model Context Protocol", "description": "MCP Bundle for Obsidian CLI - Enable AI assistants to manage Obsidian vaults through Model Context Protocol",
"type": "module", "type": "module",
"main": "dist/index.js", "main": "dist/index.js",

View File

@@ -130,7 +130,7 @@ export async function registerFileOperationTools(server: ObsidianMCPServer): Pro
// T031: Read note tool // T031: Read note tool
server.registerTool( server.registerTool(
'obsidian_read_note', 'obsidian_read_note',
'Read the content of a note from the Obsidian vault. Specify either the note name (file) or full path (path).', 'Read the content of a note from the Obsidian vault. Specify either the note name (file) or full path (path). For large files (e.g. PDFs), use max_chars and offset to read in chunks and avoid exceeding context limits.',
{ {
type: 'object', type: 'object',
properties: { properties: {
@@ -142,6 +142,14 @@ export async function registerFileOperationTools(server: ObsidianMCPServer): Pro
type: 'string', type: 'string',
description: 'Exact file path (folder/note.md)', description: 'Exact file path (folder/note.md)',
}, },
max_chars: {
type: 'number',
description: 'Maximum characters to return (default: 50000, max: 500000). Use to avoid output-too-large errors on big files.',
},
offset: {
type: 'number',
description: 'Character offset to start reading from (default: 0). Use with max_chars to page through large files.',
},
}, },
}, },
createToolHandler( createToolHandler(
@@ -157,6 +165,14 @@ export async function registerFileOperationTools(server: ObsidianMCPServer): Pro
type: 'string', type: 'string',
description: 'Exact file path (folder/note.md)', description: 'Exact file path (folder/note.md)',
}, },
max_chars: {
type: 'number',
description: 'Maximum characters to return (default: 50000, max: 500000)',
},
offset: {
type: 'number',
description: 'Character offset to start reading from (default: 0)',
},
}, },
}, },
async (args) => { async (args) => {
@@ -170,11 +186,24 @@ export async function registerFileOperationTools(server: ObsidianMCPServer): Pro
const result = await executeObsidianCommand('read', cmdArgs); const result = await executeObsidianCommand('read', cmdArgs);
handleCLIResult(result, { operation: 'read_note', identifier: sanitized.file || sanitized.path }); handleCLIResult(result, { operation: 'read_note', identifier: sanitized.file || sanitized.path });
const offset: number = validated.offset ?? 0;
const maxChars: number = validated.max_chars ?? 50000;
const fullContent = result.stdout;
const totalChars = fullContent.length;
const chunk = fullContent.slice(offset, offset + maxChars);
const isTruncated = offset + maxChars < totalChars;
let text = chunk;
if (isTruncated) {
const nextOffset = offset + maxChars;
text += `\n\n[Content truncated: showing characters ${offset}${offset + chunk.length} of ${totalChars} total. To read the next chunk, call obsidian_read_note again with offset=${nextOffset}.]`;
}
return { return {
content: [ content: [
{ {
type: 'text', type: 'text',
text: formatForMCP(result.stdout, 'text'), text,
}, },
], ],
}; };

View File

@@ -13,7 +13,15 @@
export function formatParam(key: string, value: string | number): string { export function formatParam(key: string, value: string | number): string {
// Always quote string values to handle spaces and special characters safely // Always quote string values to handle spaces and special characters safely
// Note: Obsidian CLI docs say: "Quote values with spaces: name="My Note"" // Note: Obsidian CLI docs say: "Quote values with spaces: name="My Note""
return `${key}="${value}"`;
// Escape double quotes and backticks to prevent shell interpretation inside double-quoted strings.
// In bash double-quoted strings: \" prevents quote termination, \` prevents command substitution.
// This preserves Markdown code fences (``` ` ```) while blocking injection via backticks.
const escapedValue = String(value)
.replace(/"/g, '\\"')
.replace(/`/g, '\\`');
return `${key}="${escapedValue}"`;
} }
/** /**

View File

@@ -8,11 +8,17 @@ import { logger } from '../utils/logger.js';
/** /**
* Characters that should be removed or escaped for security * Characters that should be removed or escaped for security
* Note: Brackets [], parentheses (), and braces {} are safe because values are quoted and passed as array args
* They're essential for Obsidian markdown (wikilinks [[link]], tasks - [ ] Task, templates {{...}}, etc.)
* Note: Single & is safe in quoted args (filenames like "Research & Development.md")
* Note: Backticks are safe because formatParam escapes them as \` inside double-quoted strings,
* preventing shell command substitution while preserving Markdown code fences (``` ```)
* We only block: ; | $ < > (command separators, pipes, substitution, redirects)
* Command injection patterns (&&, ||, etc.) are handled separately
*/ */
const DANGEROUS_CHARS = /[;&|`$(){}[\]<>]/g; const DANGEROUS_CHARS = /[;|$<>]/g;
const COMMAND_INJECTION_PATTERNS = [ const COMMAND_INJECTION_PATTERNS = [
/\$\(/g, // Command substitution $(...) /\$\(/g, // Command substitution $(...)
/`[^`]*`/g, // Command substitution `...`
/\|\|/g, // OR operator /\|\|/g, // OR operator
/&&/g, // AND operator /&&/g, // AND operator
/;/g, // Command separator /;/g, // Command separator
@@ -67,7 +73,8 @@ export function sanitizePath(path: string): string {
sanitized = sanitized.replace(/^\/+|\/+$/g, ''); sanitized = sanitized.replace(/^\/+|\/+$/g, '');
// Remove dangerous characters but allow path separators // Remove dangerous characters but allow path separators
sanitized = sanitized.replace(/[;&|`$(){}[\]<>]/g, ''); // Note: Brackets, parentheses, braces, and single & are safe in paths (quoted args)
sanitized = sanitized.replace(/[;|`$<>]/g, '');
return sanitized; return sanitized;
} }

View File

@@ -104,11 +104,13 @@ export const createNoteSchema = z.object({
}); });
// Read note parameters // Read note parameters
export const readNoteSchema = z.union([ export const readNoteSchema = z.object({
z.object({ file: noteNameSchema }), file: noteNameSchema.optional(),
z.object({ path: filePathSchema }), path: filePathSchema.optional(),
]).refine( offset: z.number().int().nonnegative().optional().default(0),
(data) => ('file' in data && data.file) || ('path' in data && data.path), max_chars: z.number().int().positive().max(500000).optional().default(50000),
}).refine(
(data) => data.file || data.path,
{ message: 'Either file or path must be provided' } { message: 'Either file or path must be provided' }
); );