Repository navigation
Add add_attachment, the tool that produces an attachmentId - #242
tsuda-haruni wants to merge 7 commits into
Conversation
add_issue, update_issue and add_issue_comment all accept an attachmentId array, but nothing in the server produced one: POST /api/v2/space/attachment was never exposed, so the parameter could be passed and never filled. This is the write-side counterpart of nulab#221, which added get_issue_attachment for the same gap in the read direction. The tool takes a server-side filePath and returns { id, name, size }. Reading the host's filesystem is a capability the server did not previously have, so BACKLOG_ATTACHMENT_ROOTS bounds it to a set of directories when an operator sets it. Symlinks are resolved before the containment test, since a link inside an allowed root would otherwise reach anything. node:fs is imported at call time rather than at module scope: src/lib.ts re-exports allTools and promises that nothing reachable from it touches a Node built-in on import. openAsBlob backs the upload with the file instead of buffering it, so a large attachment is streamed into the request.
There was a problem hiding this comment.
🟡 Changes recommended
There are a couple of correctness/documentation issues in the new attachment upload path handling that should be addressed before merging.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds an add_attachment MCP tool that uploads a local file to Backlog via POST /api/v2/space/attachment and returns { id, name, size }, enabling existing attachmentId parameters in add_issue, update_issue, and add_issue_comment to be used as intended.
Changes:
- Introduces
add_attachmenttool (space toolset) with filesystem-path validation and optional allowlist viaBACKLOG_ATTACHMENT_ROOTS. - Adds pure string utilities (
parseAttachmentRoots,isInsideRoot) and tests for root parsing/containment semantics. - Documents attachment uploads and the
BACKLOG_ATTACHMENT_ROOTSenvironment variable in the README.
File summaries
| File | Description |
|---|---|
| src/utils/attachmentRoots.ts | Adds allowlist parsing and containment helper used by attachment uploads. |
| src/utils/attachmentRoots.test.ts | Unit tests for allowlist parsing and containment logic. |
| src/tools/addAttachment.ts | Implements the add_attachment tool including root allowlist enforcement and upload wiring. |
| src/tools/addAttachment.test.ts | Integration-style tests using a real temp directory, including symlink containment behavior. |
| src/tools/tools.ts | Registers add_attachment in the space toolset. |
| README.md | Documents the new tool and attachment upload configuration. |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…curately Two review points from nulab#242. The multipart part was named after the real path, so a symlink named `evidence.png` that points at `IMG_0522.PNG` was uploaded as `IMG_0522.PNG`. The security checks still run against the real path — that is the file that will be read — but the name now comes from the path as the caller wrote it, which is the name the caller chose. `isInsideRoot`'s comment said both inputs were real paths. They are not: when `realpath()` fails the requested path is compared as `path.resolve`d, and the allowlist keeps each root in its written form alongside its resolved one. The comment now says what the function actually needs, which is absolute, normalized paths, and why it does not normalize them itself.
|
Addressed both Copilot points in 3ba02dd.
On #251's |
nulab#258 moved the repository to Vite+, and its lint rule now rejects a bare `vitest` import. The two test files added by this PR predate that change. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
- Call backlog-js 1.x's postSpaceAttachment(client, form); tools receive a Client, which has no postSpaceAttachment method. - Require BACKLOG_ATTACHMENT_ROOTS unless the transport is stdio, so remote HTTP callers cannot upload arbitrary server files. - Annotate add_attachment as a write with openWorldHint, since it reads the server's filesystem, and list it in the annotation tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@tsuda-haruni |
|
Of course — take your time. If it helps to narrow the decision, I'm happy to reshape it: stdio-only, a separate toolset that's off by default, or whatever boundary you'd prefer. |
Closes #241.
add_issue,update_issueandadd_issue_commentall accept anattachmentIdarray, but no tool produced one:POST /api/v2/space/attachmentwas never exposed, so the parameter could be passed and never filled. This addsadd_attachment, the write-side counterpart ofget_issue_attachment(#221).The id goes into the existing
attachmentIdparameters.backlog-jsalready hadpostSpaceAttachment(form), so the SDK is untouched.Design notes
Three choices a reviewer may want to push back on:
node:fsis imported at call time, not at module scope.src/lib.tsre-exportsallToolsand promises that nothing reachable from it touches a Node built-in on import (getIssueAttachmentavoidsBufferfor the same reason). A static import here would break that for every consumer, including ones that never call this tool. Deferring it moves the failure to the only place it means anything: a runtime withoutnode:fscannot serve a local path anyway.BACKLOG_ATTACHMENT_ROOTSbounds what the tool may read. This is the first tool that reads the host's filesystem, which makes it the first that can send a local file somewhere else. When the variable is set (path-delimiter separated), the file must resolve inside one of the listed directories; symlinks are resolved first so a link inside an allowed root cannot reach outside it. The containment test runs before the existence and regular-file checks, and everything outside the allowlist gets one error, so the messages cannot be used to map the filesystem beyond the allowed directories. Unset means no restriction — the only default that works out of the box for stdio/npx, where server and caller share a machine. Happy to flip to deny-by-default if you'd rather.openAsBlobrather thanreadFile. The Blob is backed by the file, so a large attachment is streamed into the request instead of being buffered once and then copied again intoFormData.Placed in the
spacetoolset since the endpoint isspace/attachment; easy to move ifissuereads better.Not included: a base64
contentvariant for container deployments where the client's filesystem is not visible to the server. It would work anywhere but puts the whole file through the model's context, which makes anything beyond a screenshot impractical. The README documents the bind-mount route instead.Verification
Also exercised against a real space: uploading a file through the built tool returned
{ id, name, size }as documented.The 12 tool tests use a real temp directory rather than a mocked
node:fs, since symlink resolution and containment are properties of the filesystem, not of the calls.