Skip to content
Open
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 36 additions & 12 deletions src/everything/everything.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ const StructuredContentSchema = {

const ZipResourcesInputSchema = z.object({
files: z.record(z.string().url().describe("URL of the file to include in the zip")).describe("Mapping of file names to URLs to include in the zip"),
outputType: z.enum([
'resourceLink',
'resource'
]).default('resource').describe("How the resulting zip file should be returned. 'resourceLink' returns a linked to a resource that can be read later, 'resource' returns a full resource object."),
});

enum ToolName {
Expand Down Expand Up @@ -334,9 +338,17 @@ export const createServer = () => {
};
});

const transientResources = new Map<string, Resource>();

server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
const uri = request.params.uri;

if (transientResources.has(uri)) {
return {
contents: [transientResources.get(uri)!],
};
}

if (uri.startsWith("test://static/resource/")) {
const index = parseInt(uri.split("/").pop() ?? "", 10) - 1;
if (index >= 0 && index < ALL_RESOURCES.length) {
Expand Down Expand Up @@ -859,8 +871,7 @@ export const createServer = () => {
}

if (name === ToolName.ZIP_RESOURCES) {
const { files } = ZipResourcesInputSchema.parse(args);

const { files, outputType } = ZipResourcesInputSchema.parse(args);
Copy link
Member

@cliffhall cliffhall Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be some validation that the files are within roots or are valid resources? If I asked for /etc/passwd would it zip up and return it?

const zip = new JSZip();

for (const [fileName, fileUrl] of Object.entries(files)) {
Expand All @@ -876,17 +887,30 @@ export const createServer = () => {
}
}

const uri = `data:application/zip;base64,${await zip.generateAsync({ type: "base64" })}`;

return {
content: [
{
const blob = await zip.generateAsync({ type: "base64" });
const mimeType = "application/zip";
const name = `out_${Date.now()}.zip`;
const uri = `resource://${name}`;
const resource = <Resource>{uri, name, mimeType, blob};
if (outputType === 'resource') {
return {
content: [{
type: "resource",
resource
}]
};
} else if (outputType === 'resourceLink') {
transientResources.set(uri, resource);
return {
content: [{
type: "resource_link",
mimeType: "application/zip",
uri,
},
],
};
mimeType,
uri
}]
};
} else {
throw new Error(`Unknown outputType: ${outputType}`);
}
}

if (name === ToolName.LIST_ROOTS) {
Expand Down