-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add gzip tool (url input, resource / resource_link output) #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for later: at some point we should migrate this whole server to the newer nicer API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we might want to screen this to avoid SSRF attacks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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