-
Notifications
You must be signed in to change notification settings - Fork 8.3k
everything: zip tool: add outputType to control resource vs. resource link output #2831
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
Open
ochafik
wants to merge
9
commits into
main
Choose a base branch
from
ochafik/zip-tool-outputs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+36
−12
Open
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1fb60a5
Add outputType to zip tool: (inlined /) resource link / resource
ochafik e1d2f40
Update everything.ts
ochafik 893ee9c
Update everything.ts
ochafik bd496fe
remove inlinedResourceLink
ochafik f88c03e
Merge branch 'main' into ochafik/zip-tool-outputs
ochafik ee5f803
Update everything.ts
ochafik 48d8afe
Forcing an empty commit.
ochafik 12e313b
Forcing an empty commit.
ochafik f3c5e4f
Apply suggestion from @cliffhall
cliffhall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
|
@@ -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) { | ||
|
@@ -859,8 +871,7 @@ export const createServer = () => { | |
} | ||
|
||
if (name === ToolName.ZIP_RESOURCES) { | ||
const { files } = ZipResourcesInputSchema.parse(args); | ||
|
||
const { files, outputType } = ZipResourcesInputSchema.parse(args); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
const zip = new JSZip(); | ||
|
||
for (const [fileName, fileUrl] of Object.entries(files)) { | ||
|
@@ -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) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.