Skip to content

Conversation

ochafik
Copy link
Contributor

@ochafik ochafik commented Oct 9, 2025

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

ochafik and others added 4 commits October 8, 2025 18:39
…, 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>
@ochafik ochafik requested a review from crondinini-ant October 9, 2025 15:20
} from "@modelcontextprotocol/sdk/types.js";
import { z } from "zod";
import { zodToJsonSchema } from "zod-to-json-schema";
import JSZip from "jszip";
Copy link
Member

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

Copy link
Contributor Author

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

return { content };
}

if (name === ToolName.ZIP_RESOURCES) {
Copy link
Member

@domdomegg domdomegg Oct 10, 2025

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

Copy link
Member

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, ...)


for (const [fileName, fileUrl] of Object.entries(files)) {
try {
const response = await fetch(fileUrl);
Copy link
Member

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.

Copy link
Contributor Author

@ochafik ochafik Oct 14, 2025

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


for (const [fileName, fileUrl] of Object.entries(files)) {
try {
const response = await fetch(fileUrl);
Copy link
Member

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.

Copy link
Contributor Author

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

@ochafik ochafik changed the title Ochafik/add zip tool add gzip tool (url input, resource / resource_link output) Oct 14, 2025
@ochafik ochafik changed the title add gzip tool (url input, resource / resource_link output) feat: add gzip tool (url input, resource / resource_link output) Oct 14, 2025
@ochafik ochafik requested a review from domdomegg October 16, 2025 09:26
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