Skip to content

pdf-server: CommandQueue, Vercel deployment, improved tool description#575

Open
ochafik wants to merge 1 commit intomainfrom
pdf-server-command-queue-vercel
Open

pdf-server: CommandQueue, Vercel deployment, improved tool description#575
ochafik wants to merge 1 commit intomainfrom
pdf-server-command-queue-vercel

Conversation

@ochafik
Copy link
Copy Markdown
Contributor

@ochafik ochafik commented Mar 30, 2026

Summary

  • CommandQueue<T> with pluggable backends (in-memory for stdio, Redis/Upstash REST for serverless) — replaces ~130 lines of hand-rolled queue infrastructure with long-polling, wake-on-enqueue, TTL pruning, and AbortSignal cancellation
  • Vercel deployment — stateless HTTP handler, DOMMatrix/ImageData/Path2D polyfills for pdfjs-dist on serverless, CORS headers. Deployed at https://pdf-server-sigma.vercel.app/mcp
  • Interact gatinginteract tool + command queue only enabled when Redis is configured on HTTP (without Redis, stateless handlers lose state between requests)
  • display_pdf description — tells the model the viewer's widget context reports current page/total pages, text selection, search results, and annotation details
  • 29 tests for CommandQueue (memory, Redis mock, Upstash REST fetch mock, MCP tool roundtrip)

Test plan

  • 263 unit tests pass (including 29 new CommandQueue tests)
  • Vercel deployment working (https://pdf-server-sigma.vercel.app/mcp)
  • MCP initialize + tools/list verified via curl
  • display_pdf + interact roundtrip tested via basic-host
  • interact tool correctly gated: available with Redis, hidden without

🤖 Generated with Claude Code

…ption

- Add CommandQueue<T> with pluggable backends (in-memory for stdio,
  Redis/Upstash REST for serverless). Supports long-polling with
  wake-on-enqueue, TTL pruning, and AbortSignal cancellation.

- Replace ~130 lines of hand-rolled queue infrastructure (Maps,
  pollWaiters, pruneStaleQueues) with CommandQueue. Same behavior,
  fewer moving parts.

- Add Vercel deployment support: stateless HTTP handler (http.ts),
  DOMMatrix/ImageData/Path2D polyfills for pdfjs-dist on serverless,
  CORS headers, vercel.json config.

- Gate interact tool on Redis availability for HTTP deployments —
  without Redis, stateless handlers lose command queue state between
  requests, so only read-only tools are exposed.

- Update display_pdf description to tell the model that the viewer's
  widget context automatically reports current page, total pages,
  text selection, search results, and annotation details.

- 29 new tests for CommandQueue (memory backend, Redis mock, Upstash
  REST fetch mock, MCP tool roundtrip simulation).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
}

async keys(pattern: string): Promise<string[]> {
const prefix = pattern.replace("*", "");

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High

This replaces only the first occurrence of "*".

Copilot Autofix

AI 1 day ago

Generally, to fix this kind of issue you should either (a) use a proper pattern-matching implementation (e.g., translating Redis glob patterns to a regular expression), or (b) if you intentionally only care about a simple suffix wildcard (like prefix*), ensure that all * characters are handled consistently using a global replacement. For this specific mock, the existing logic clearly aims to treat the pattern as "<prefix>*" by stripping * and using startsWith(prefix).

The minimal, non-breaking fix is therefore to strip all * characters from the pattern, not just the first one. We can achieve this by changing pattern.replace("*", "") to use a global regular expression: pattern.replace(/\*/g, ""). This keeps the existing semantics—extract “prefix” by removing wildcard characters—and ensures there are no remaining * characters that would interfere with startsWith. No additional methods or imports are needed; this is just a local change in MockRedis.keys in examples/pdf-server/src/command-queue.test.ts at line 56.

Suggested changeset 1
examples/pdf-server/src/command-queue.test.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/examples/pdf-server/src/command-queue.test.ts b/examples/pdf-server/src/command-queue.test.ts
--- a/examples/pdf-server/src/command-queue.test.ts
+++ b/examples/pdf-server/src/command-queue.test.ts
@@ -53,7 +53,7 @@
   }
 
   async keys(pattern: string): Promise<string[]> {
-    const prefix = pattern.replace("*", "");
+    const prefix = pattern.replace(/\*/g, "");
     return [...this.store.keys()].filter((k) => k.startsWith(prefix));
   }
 
EOF
@@ -53,7 +53,7 @@
}

async keys(pattern: string): Promise<string[]> {
const prefix = pattern.replace("*", "");
const prefix = pattern.replace(/\*/g, "");
return [...this.store.keys()].filter((k) => k.startsWith(prefix));
}

Copilot is powered by AI and may make mistakes. Always verify output.
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 30, 2026

Open in StackBlitz

@modelcontextprotocol/ext-apps

npm i https://pkg.pr.new/@modelcontextprotocol/ext-apps@575

@modelcontextprotocol/server-basic-preact

npm i https://pkg.pr.new/@modelcontextprotocol/server-basic-preact@575

@modelcontextprotocol/server-basic-react

npm i https://pkg.pr.new/@modelcontextprotocol/server-basic-react@575

@modelcontextprotocol/server-basic-solid

npm i https://pkg.pr.new/@modelcontextprotocol/server-basic-solid@575

@modelcontextprotocol/server-basic-svelte

npm i https://pkg.pr.new/@modelcontextprotocol/server-basic-svelte@575

@modelcontextprotocol/server-basic-vanillajs

npm i https://pkg.pr.new/@modelcontextprotocol/server-basic-vanillajs@575

@modelcontextprotocol/server-basic-vue

npm i https://pkg.pr.new/@modelcontextprotocol/server-basic-vue@575

@modelcontextprotocol/server-budget-allocator

npm i https://pkg.pr.new/@modelcontextprotocol/server-budget-allocator@575

@modelcontextprotocol/server-cohort-heatmap

npm i https://pkg.pr.new/@modelcontextprotocol/server-cohort-heatmap@575

@modelcontextprotocol/server-customer-segmentation

npm i https://pkg.pr.new/@modelcontextprotocol/server-customer-segmentation@575

@modelcontextprotocol/server-debug

npm i https://pkg.pr.new/@modelcontextprotocol/server-debug@575

@modelcontextprotocol/server-map

npm i https://pkg.pr.new/@modelcontextprotocol/server-map@575

@modelcontextprotocol/server-pdf

npm i https://pkg.pr.new/@modelcontextprotocol/server-pdf@575

@modelcontextprotocol/server-scenario-modeler

npm i https://pkg.pr.new/@modelcontextprotocol/server-scenario-modeler@575

@modelcontextprotocol/server-shadertoy

npm i https://pkg.pr.new/@modelcontextprotocol/server-shadertoy@575

@modelcontextprotocol/server-sheet-music

npm i https://pkg.pr.new/@modelcontextprotocol/server-sheet-music@575

@modelcontextprotocol/server-system-monitor

npm i https://pkg.pr.new/@modelcontextprotocol/server-system-monitor@575

@modelcontextprotocol/server-threejs

npm i https://pkg.pr.new/@modelcontextprotocol/server-threejs@575

@modelcontextprotocol/server-transcript

npm i https://pkg.pr.new/@modelcontextprotocol/server-transcript@575

@modelcontextprotocol/server-video-resource

npm i https://pkg.pr.new/@modelcontextprotocol/server-video-resource@575

@modelcontextprotocol/server-wiki-explorer

npm i https://pkg.pr.new/@modelcontextprotocol/server-wiki-explorer@575

commit: 389b36d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants