pdf-server: CommandQueue, Vercel deployment, improved tool description#575
pdf-server: CommandQueue, Vercel deployment, improved tool description#575
Conversation
…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
Show autofix suggestion
Hide autofix suggestion
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.
| @@ -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)); | ||
| } | ||
|
|
@modelcontextprotocol/ext-apps
@modelcontextprotocol/server-basic-preact
@modelcontextprotocol/server-basic-react
@modelcontextprotocol/server-basic-solid
@modelcontextprotocol/server-basic-svelte
@modelcontextprotocol/server-basic-vanillajs
@modelcontextprotocol/server-basic-vue
@modelcontextprotocol/server-budget-allocator
@modelcontextprotocol/server-cohort-heatmap
@modelcontextprotocol/server-customer-segmentation
@modelcontextprotocol/server-debug
@modelcontextprotocol/server-map
@modelcontextprotocol/server-pdf
@modelcontextprotocol/server-scenario-modeler
@modelcontextprotocol/server-shadertoy
@modelcontextprotocol/server-sheet-music
@modelcontextprotocol/server-system-monitor
@modelcontextprotocol/server-threejs
@modelcontextprotocol/server-transcript
@modelcontextprotocol/server-video-resource
@modelcontextprotocol/server-wiki-explorer
commit: |
Summary
interacttool + command queue only enabled when Redis is configured on HTTP (without Redis, stateless handlers lose state between requests)Test plan
🤖 Generated with Claude Code