-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Add getResourceLinks tool to return multiple resource references #2276
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
|
|
@@ -86,6 +86,15 @@ const GetResourceReferenceSchema = z.object({ | |
| .describe("ID of the resource to reference (1-100)"), | ||
| }); | ||
|
|
||
| const GetResourceLinksSchema = z.object({ | ||
| count: z | ||
| .number() | ||
| .min(1) | ||
| .max(10) | ||
| .default(3) | ||
| .describe("Number of resource links to return (1-10)"), | ||
| }); | ||
|
|
||
| enum ToolName { | ||
| ECHO = "echo", | ||
| ADD = "add", | ||
|
|
@@ -95,6 +104,7 @@ enum ToolName { | |
| GET_TINY_IMAGE = "getTinyImage", | ||
| ANNOTATED_MESSAGE = "annotatedMessage", | ||
| GET_RESOURCE_REFERENCE = "getResourceReference", | ||
| GET_RESOURCE_LINKS = "getResourceLinks", | ||
| } | ||
|
|
||
| enum PromptName { | ||
|
|
@@ -117,7 +127,7 @@ export const createServer = () => { | |
| logging: {}, | ||
| completions: {}, | ||
| }, | ||
| instructions | ||
| instructions, | ||
| } | ||
| ); | ||
|
|
||
|
|
@@ -164,13 +174,12 @@ export const createServer = () => { | |
| server.notification(message); | ||
| }, 20000); | ||
|
|
||
|
|
||
| // Set up update interval for stderr messages | ||
| stdErrUpdateInterval = setInterval(() => { | ||
| const shortTimestamp = new Date().toLocaleTimeString([], { | ||
| hour: "2-digit", | ||
| minute: "2-digit", | ||
| second: "2-digit" | ||
| second: "2-digit", | ||
| }); | ||
| server.notification({ | ||
| method: "notifications/stderr", | ||
|
|
@@ -459,6 +468,12 @@ export const createServer = () => { | |
| "Returns a resource reference that can be used by MCP clients", | ||
| inputSchema: zodToJsonSchema(GetResourceReferenceSchema) as ToolInput, | ||
| }, | ||
| { | ||
| name: ToolName.GET_RESOURCE_LINKS, | ||
| description: | ||
| "Returns multiple resource links that reference different types of resources", | ||
| inputSchema: zodToJsonSchema(GetResourceLinksSchema) as ToolInput, | ||
| }, | ||
| ]; | ||
|
|
||
| return { tools }; | ||
|
|
@@ -648,6 +663,42 @@ export const createServer = () => { | |
| return { content }; | ||
| } | ||
|
|
||
| if (name === ToolName.GET_RESOURCE_LINKS) { | ||
| const { count } = GetResourceLinksSchema.parse(args); | ||
| const content = []; | ||
|
|
||
| // Add intro text | ||
| content.push({ | ||
| type: "text", | ||
| text: `Here are ${count} resource links to resources available in this server (see full output in tool response if your client does not support resource_link yet):`, | ||
| }); | ||
|
|
||
| // Return resource links to actual resources from ALL_RESOURCES | ||
| const actualCount = Math.min(count, ALL_RESOURCES.length); | ||
| for (let i = 0; i < actualCount; i++) { | ||
| const resource = ALL_RESOURCES[i]; | ||
| content.push({ | ||
| type: "resource_link", | ||
| uri: resource.uri, | ||
| name: resource.name, | ||
| description: `Resource ${i + 1}: ${ | ||
| resource.mimeType === "text/plain" | ||
| ? "plaintext resource" | ||
| : "binary blob resource" | ||
| }`, | ||
| mimeType: resource.mimeType, | ||
| }); | ||
| } | ||
|
|
||
| // Add summary text | ||
| content.push({ | ||
| type: "text", | ||
| text: `\nThese resource links reference actual resources available through the resources/read endpoint.`, | ||
|
||
| }); | ||
|
|
||
| return { content }; | ||
| } | ||
|
|
||
| throw new Error(`Unknown tool: ${name}`); | ||
| }); | ||
|
|
||
|
|
||
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.

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.
is it necessary this comma at the end ?