Skip to content

Conversation

ochafik
Copy link

@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 <[email protected]>
…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 <[email protected]>
@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

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.


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.

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