Commit 9972ac7
Add get_document_thumbnail tool for retrieving document previews (#53)
Adds support for retrieving document thumbnail previews from
Paperless-NGX's `/api/documents/{id}/thumb/` endpoint.
## Changes
- **API Client** (`PaperlessAPI.ts`): Added `getThumbnail(id)` method
using axios with `responseType: "arraybuffer"` to fetch WebP thumbnails
- **MCP Tool** (`documents.ts`): Added `get_document_thumbnail` tool
that returns base64-encoded WebP image as MCP resource (consistent with
`download_document` pattern)
- **Documentation**: Updated `manifest.json` and `README.md` with new
tool
- **TypeScript Typing**: Added explicit return type
`Promise<AxiosResponse<ArrayBuffer>>` and generic type parameter
`axios.get<ArrayBuffer>` to both `getThumbnail` and `downloadDocument`
methods for improved type safety
- **Changeset**: Created changeset for version management (minor bump)
## Usage
```typescript
get_document_thumbnail({ id: 123 })
// Returns: base64-encoded WebP image as MCP resource with mimeType "image/webp"
```
The tool follows MCP conventions by returning the image binary directly
as a base64-encoded resource rather than a URL, enabling immediate
consumption by AI assistants and client applications.
<!-- START COPILOT ORIGINAL PROMPT -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>Feature: Add tool to get document thumbnail (image
preview)</issue_title>
> <issue_description>- Add a tool to MCP to retrieve a document
thumbnail (image preview)
> - Use the `/api/documents/{id}/thumb/` endpoint from paperless-ngx,
which returns a WebP image
> - API should accept a document ID and either:
> - Return the image binary as a base64-encoded resource directly
(common pattern in MCP tools, like `download_document`)
> - Or, optionally, allow returning a link to the image in cases where
direct serving isn't possible or secure
> - Expected usage: enable chat-based or API client applications to
request and display document thumbnails efficiently
> - Consider always adding the link to the document response, no harm in
adding it.
> - Reference: similar implementations for `download_document` return
the resource in the MCP response, not just a URL
> - MCP documentation and practice: tools for files and images return
the binary (as base64-encoded `resource.blob` with `mimeType`), not just
a link, for direct consumption
>
> Acceptance:
> - New tool for thumbnail retrieval is listed under Document Operations
> - Returns the image as a base64-encoded resource (with proper mime
type)
> - API docs/README are updated
> - Include tests for typical and edge cases
> - Ensure permission and error handling are robust</issue_description>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> </comments>
>
</details>
<!-- START COPILOT CODING AGENT SUFFIX -->
- Fixes #52
<!-- START COPILOT CODING AGENT TIPS -->
---
✨ Let Copilot coding agent [set things up for
you](https://github.com/baruchiro/paperless-mcp/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Added `get_document_thumbnail` tool to retrieve document preview
images by document ID, returning base64-encoded WebP thumbnail images.
* Updated API documentation with examples and usage instructions for the
new thumbnail retrieval functionality.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: baruchiro <17686879+baruchiro@users.noreply.github.com>1 parent e2ac0f6 commit 9972ac7
File tree
5 files changed
+64
-3
lines changed- .changeset
- src
- api
- tools
5 files changed
+64
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
131 | 143 | | |
132 | 144 | | |
133 | 145 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
43 | 47 | | |
44 | 48 | | |
45 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | | - | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
166 | 169 | | |
167 | | - | |
| 170 | + | |
168 | 171 | | |
169 | 172 | | |
170 | 173 | | |
| |||
176 | 179 | | |
177 | 180 | | |
178 | 181 | | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
179 | 195 | | |
180 | 196 | | |
181 | 197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
279 | 303 | | |
280 | 304 | | |
281 | 305 | | |
| |||
0 commit comments