feat: add gzip tool (url input, resource / resource_link output)#15
feat: add gzip tool (url input, resource / resource_link output)#15
Conversation
…, incl. data URIs) This change ports the ZIP tool from PR #2830 in the modelcontextprotocol/servers repository to the example-remote-server codebase. The zip tool: - Takes a mapping of filenames to URLs (which can be data URIs) - Fetches files from those URLs - Compresses them into a zip archive - Returns the zip as a data URI resource link This demonstrates best practices for handling URIs in MCP tools, including both consuming input URIs and producing output data URIs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…rce) This change ports the enhancements from PR #2831 in the modelcontextprotocol/servers repository to the example-remote-server codebase. The zip tool now supports three output formats via the 'outputType' parameter: 1. 'inlinedResourceLink' (default) - Returns a resource_link with a data URI (the original behavior, most efficient for small files) 2. 'resourceLink' - Returns a link to a resource stored in a transient map, allowing clients to read the resource later via ReadResource requests 3. 'resource' - Returns the full resource object directly inline This demonstrates best practices for handling multiple output formats and managing transient resources that can be read after the tool completes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
mcp-server/src/services/mcp.ts
Outdated
| } from "@modelcontextprotocol/sdk/types.js"; | ||
| import { z } from "zod"; | ||
| import { zodToJsonSchema } from "zod-to-json-schema"; | ||
| import JSZip from "jszip"; |
There was a problem hiding this comment.
I think you can do this with node:zlib (https://nodejs.org/api/zlib.html) so you don't need to add another dependency
There was a problem hiding this comment.
Thanks, switched from zip + multiple files to gzip of single file, no deps
mcp-server/src/services/mcp.ts
Outdated
| return { content }; | ||
| } | ||
|
|
||
| if (name === ToolName.ZIP_RESOURCES) { |
There was a problem hiding this comment.
for later: at some point we should migrate this whole server to the newer nicer API
There was a problem hiding this comment.
i.e. server.registerTool, rather than server.setRequestHandler(CallToolRequestSchema, ...)
mcp-server/src/services/mcp.ts
Outdated
|
|
||
| for (const [fileName, fileUrl] of Object.entries(files)) { | ||
| try { | ||
| const response = await fetch(fileUrl); |
There was a problem hiding this comment.
I think we might want to screen this to avoid SSRF attacks.
There was a problem hiding this comment.
Great point, thanks! Added ZIP_ALLOWED_DOMAINS that defaults to just raw.githubusercontent.com
mcp-server/src/services/mcp.ts
Outdated
|
|
||
| for (const [fileName, fileUrl] of Object.entries(files)) { | ||
| try { | ||
| const response = await fetch(fileUrl); |
There was a problem hiding this comment.
I think we want to be careful handling the result / set some limit to avoid DoS attacks. E.g. getting us to download a 2GB file.
There was a problem hiding this comment.
Added limits on total fetch size + time
Porting over zip tool from everything-server: shows how to accept binary inputs (as uri strings) and produce binary outputs (resources or resource links)
cc/ @crondinini-ant