feat(attachments): add upload/delete/list_attachments tools#12
Open
jacky1967 wants to merge 1 commit into
Open
feat(attachments): add upload/delete/list_attachments tools#12jacky1967 wants to merge 1 commit into
jacky1967 wants to merge 1 commit into
Conversation
Adds 3 MCP tools for binary file management on the Obsidian backend, for consumers that prefer an MCP-driven write path over direct filesystem fallback for attachments (PDFs, images, audio): - upload_attachment(path, contentBase64) — atomic temp+rename, parent dirs auto-created, .md rejected (use create_page). - delete_attachment(path) — .md rejected (use delete_page), error if missing or directory. - list_attachments(folder, recursive?) — non-.md filter, sorted by path, returns size + RFC3339 mtime. Tools sit on *vault.Client directly (Obsidian-only by design); not added to the backend.Backend interface — Logseq has no filesystem concept. Registered in server.go alongside the existing Obsidian "reload" tool via type-assertion (skipped in --read-only mode). Path traversal protection reuses safePath() so attachments inherit the same boundary checks as pages. Tests: 14 vault layer + 10 tools layer + end-to-end smoke (stdio JSON-RPC: initialize, tools/list shows 35 tools incl. 3 new, upload →list→delete→list-empty chain, .md rejection). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds 3 new MCP tools to the Obsidian backend for binary file management (PDFs, images, audio attachments). Designed for consumers that prefer a single MCP-driven write path over a direct filesystem fallback for non-Markdown content.
Motivation
Current MCP tools cover Markdown pages but not binary attachments. Consumers wanting to operate strictly through MCP have to fall back to a separate filesystem layer for things like image uploads or PDF storage, which forces them to maintain two distinct write paths and complicates path-traversal hardening.
What's added
3 tools on
*vault.Client(Obsidian-only by design — Logseq has no filesystem concept, so not added tobackend.Backend):upload_attachment(path, contentBase64)— atomic temp+rename, auto-creates parent dirs, rejects.md(caller should usecreate_page).delete_attachment(path)— rejects.md, errors if missing or if target is a directory.list_attachments(folder, recursive?)— non-.mdfilter, sorted by path, returnssize+ RFC3339mtime.Registered in
server.goalongside the existing Obsidianreloadtool via type-assertion (skipped automatically in--read-onlymode).Path safety
Reuses the existing
safePath()helper so attachments inherit the same boundary checks as pages — no new attack surface.Tests
.mdrejection on upload/delete, missing path, directory-as-target, listing, recursion, sort order).initialize→tools/listshows the 3 new tools (35 total) →upload/list/delete/list-emptychain →.mdrejection path. (Smoke run locally during development, not committed.)No side-effect
Backendinterface change).--read-onlymode still skips all writers, including the 3 new ones.go.mod.Files
Compatibility note vs PR #11
This branch is independent of #11 (Dockerfile). They touch disjoint paths and can be merged in any order.