Skip to content

Commit c484529

Browse files
ochafikclaude
andcommitted
pdf-server: add example prompts, testing docs, and updated tools table to README
- Example prompts for annotations, navigation, page extraction, stamps, forms - Documents how to run E2E tests and API prompt discovery tests - Updated tools table to include interact tool - Updated key patterns table with annotations, command queue, file download - Added pdf-lib to dependencies list Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6264371 commit c484529

File tree

1 file changed

+90
-5
lines changed

1 file changed

+90
-5
lines changed

examples/pdf-server/README.md

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,92 @@ bun examples/pdf-server/main.ts --stdio ./papers/
156156

157157
## Tools
158158

159-
| Tool | Visibility | Purpose |
160-
| ---------------- | ---------- | -------------------------------------- |
161-
| `list_pdfs` | Model | List available local files and origins |
162-
| `display_pdf` | Model + UI | Display interactive viewer |
163-
| `read_pdf_bytes` | App only | Stream PDF data in chunks |
159+
| Tool | Visibility | Purpose |
160+
| ---------------- | ---------- | ----------------------------------------------------- |
161+
| `list_pdfs` | Model | List available local files and origins |
162+
| `display_pdf` | Model + UI | Display interactive viewer |
163+
| `interact` | Model | Navigate, annotate, search, extract pages, fill forms |
164+
| `read_pdf_bytes` | App only | Stream PDF data in chunks |
165+
166+
## Example Prompts
167+
168+
After the model calls `display_pdf`, it receives the `viewUUID` and a description of all capabilities. Here are example prompts and follow-ups that exercise annotation features:
169+
170+
### Annotating
171+
172+
> **User:** Show me the Attention Is All You Need paper
173+
>
174+
> _Model calls `display_pdf` → viewer opens_
175+
>
176+
> **User:** Highlight the title and add an APPROVED stamp on the first page.
177+
>
178+
> _Model calls `interact` with `highlight_text` for the title and `add_annotations` with a stamp_
179+
180+
> **User:** Can you annotate this PDF? Mark important sections for me.
181+
>
182+
> _Model calls `interact` with `get_pages` to read content first, then `add_annotations` with highlights/notes_
183+
184+
> **User:** Add a note on page 1 saying "Key contribution" at position (200, 500), and highlight the abstract.
185+
>
186+
> _Model calls `interact` with `add_annotations` containing a `note` and either `highlight_text` or a `highlight` annotation_
187+
188+
### Navigation & Search
189+
190+
> **User:** Search for "self-attention" in the paper.
191+
>
192+
> _Model calls `interact` with action `search`, query `"self-attention"`_
193+
194+
> **User:** Go to page 5.
195+
>
196+
> _Model calls `interact` with action `navigate`, page `5`_
197+
198+
### Page Extraction
199+
200+
> **User:** Give me the text of pages 1–3.
201+
>
202+
> _Model calls `interact` with action `get_pages`, intervals `[{start:1, end:3}]`, getText `true`_
203+
204+
> **User:** Take a screenshot of the first page.
205+
>
206+
> _Model calls `interact` with action `get_pages`, intervals `[{start:1, end:1}]`, getScreenshots `true`_
207+
208+
### Stamps & Form Filling
209+
210+
> **User:** Stamp this document as CONFIDENTIAL on every page.
211+
>
212+
> _Model calls `interact` with `add_annotations` containing `stamp` annotations on each page_
213+
214+
> **User:** Fill in the "Name" field with "Alice" and "Date" with "2026-02-26".
215+
>
216+
> _Model calls `interact` with action `fill_form`, fields `[{name:"Name", value:"Alice"}, {name:"Date", value:"2026-02-26"}]`_
217+
218+
## Testing
219+
220+
### E2E Tests (Playwright)
221+
222+
```bash
223+
# Run annotation E2E tests (renders annotations in a real browser)
224+
npx playwright test tests/e2e/pdf-annotations.spec.ts
225+
226+
# Run all PDF server tests
227+
npx playwright test -g "PDF Server"
228+
```
229+
230+
### API Prompt Discovery Tests
231+
232+
These tests verify that Claude can discover and use annotation capabilities by calling the Anthropic Messages API with the tool schemas. They are **disabled by default** — skipped unless `ANTHROPIC_API_KEY` is set:
233+
234+
```bash
235+
ANTHROPIC_API_KEY=sk-ant-... npx playwright test tests/e2e/pdf-annotations-api.spec.ts
236+
```
237+
238+
The API tests simulate a conversation where `display_pdf` has already been called, then send a follow-up user message and verify the model uses annotation actions (or at least the `interact` tool). Three scenarios are tested:
239+
240+
| Scenario | User prompt | Expected model behavior |
241+
| -------------------- | ----------------------------------------------------------------- | ------------------------------------------ |
242+
| Direct annotation | "Highlight the title and add an APPROVED stamp" | Uses `highlight_text` or `add_annotations` |
243+
| Capability discovery | "Can you annotate this PDF?" | Uses interact or mentions annotations |
244+
| Specific notes | "Add a note saying 'Key contribution' and highlight the abstract" | Uses `interact` tool |
164245

165246
## Architecture
166247

@@ -182,8 +263,12 @@ src/
182263
| External links | `app.openLink()` |
183264
| View persistence | `viewUUID` + localStorage |
184265
| Theming | `applyDocumentTheme()` + CSS `light-dark()` |
266+
| Annotations | DOM overlays + pdf-lib embed on download |
267+
| Command queue | Server enqueues → client polls + processes |
268+
| File download | `app.downloadFile()` for annotated PDF |
185269

186270
## Dependencies
187271

188272
- `pdfjs-dist`: PDF rendering (frontend only)
273+
- `pdf-lib`: Client-side PDF modification for annotated download
189274
- `@modelcontextprotocol/ext-apps`: MCP Apps SDK

0 commit comments

Comments
 (0)