Add getResourceLinks tool to return multiple resource references
- Implement new tool that returns configurable number of resource links (1-10) - Each link includes URI, name, description, and MIME type from available resources - Minor formatting fixes for trailing commas and whitespace 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
e39a6653c5
commit
6a7ef8f955
1 changed files with 54 additions and 3 deletions
|
|
@ -86,6 +86,15 @@ const GetResourceReferenceSchema = z.object({
|
||||||
.describe("ID of the resource to reference (1-100)"),
|
.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 {
|
enum ToolName {
|
||||||
ECHO = "echo",
|
ECHO = "echo",
|
||||||
ADD = "add",
|
ADD = "add",
|
||||||
|
|
@ -95,6 +104,7 @@ enum ToolName {
|
||||||
GET_TINY_IMAGE = "getTinyImage",
|
GET_TINY_IMAGE = "getTinyImage",
|
||||||
ANNOTATED_MESSAGE = "annotatedMessage",
|
ANNOTATED_MESSAGE = "annotatedMessage",
|
||||||
GET_RESOURCE_REFERENCE = "getResourceReference",
|
GET_RESOURCE_REFERENCE = "getResourceReference",
|
||||||
|
GET_RESOURCE_LINKS = "getResourceLinks",
|
||||||
}
|
}
|
||||||
|
|
||||||
enum PromptName {
|
enum PromptName {
|
||||||
|
|
@ -117,7 +127,7 @@ export const createServer = () => {
|
||||||
logging: {},
|
logging: {},
|
||||||
completions: {},
|
completions: {},
|
||||||
},
|
},
|
||||||
instructions
|
instructions,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -164,13 +174,12 @@ export const createServer = () => {
|
||||||
server.notification(message);
|
server.notification(message);
|
||||||
}, 20000);
|
}, 20000);
|
||||||
|
|
||||||
|
|
||||||
// Set up update interval for stderr messages
|
// Set up update interval for stderr messages
|
||||||
stdErrUpdateInterval = setInterval(() => {
|
stdErrUpdateInterval = setInterval(() => {
|
||||||
const shortTimestamp = new Date().toLocaleTimeString([], {
|
const shortTimestamp = new Date().toLocaleTimeString([], {
|
||||||
hour: "2-digit",
|
hour: "2-digit",
|
||||||
minute: "2-digit",
|
minute: "2-digit",
|
||||||
second: "2-digit"
|
second: "2-digit",
|
||||||
});
|
});
|
||||||
server.notification({
|
server.notification({
|
||||||
method: "notifications/stderr",
|
method: "notifications/stderr",
|
||||||
|
|
@ -459,6 +468,12 @@ export const createServer = () => {
|
||||||
"Returns a resource reference that can be used by MCP clients",
|
"Returns a resource reference that can be used by MCP clients",
|
||||||
inputSchema: zodToJsonSchema(GetResourceReferenceSchema) as ToolInput,
|
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 };
|
return { tools };
|
||||||
|
|
@ -648,6 +663,42 @@ export const createServer = () => {
|
||||||
return { content };
|
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:`,
|
||||||
|
});
|
||||||
|
|
||||||
|
// 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}`);
|
throw new Error(`Unknown tool: ${name}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue