getResourceLinks
Generate resource links for multiple resource types by specifying the desired count (1-10) using a tool designed for dynamic user input within the MCP Elicitations Demo Server.
Instructions
Returns multiple resource links that reference different types of resources
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| count | No | Number of resource links to return (1-10) |
Implementation Reference
- The main handler function for the getResourceLinks tool. It parses the count parameter, generates resources using generateAllResources(), constructs a content array with an introductory text block and resource_link blocks for the specified number of resources, and returns it.handler: async (args: any) => { const { count } = GetResourceLinksSchema.parse(args); const content: any[] = []; // Add intro text content.push({ type: "text" as const, 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 ALL_RESOURCES = generateAllResources(); 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" as const, uri: resource.uri, name: resource.name, description: `Resource ${i + 1}: ${ resource.mimeType === "text/plain" ? "plaintext resource" : "binary blob resource" }`, mimeType: resource.mimeType, }); } return { content }; },
- Zod schema defining the input for getResourceLinks: optional count (number, 1-10, default 3). Used for inputSchema and parsing args.const GetResourceLinksSchema = z.object({ count: z .number() .min(1) .max(10) .default(3) .describe("Number of resource links to return (1-10)"), });
- src/tools/index.ts:22-37 (registration)Registration of getResourceLinksTool in the allTools array (line 36), which is used by getTools() to list tools and getToolHandler() to dispatch calls.const allTools = [ echoTool, addTool, longRunningOperationTool, printEnvTool, sampleLlmTool, sampleWithPreferencesTool, sampleMultimodalTool, sampleConversationTool, sampleAdvancedTool, getTinyImageTool, annotatedMessageTool, getResourceReferenceTool, elicitationTool, getResourceLinksTool, ];
- src/lib/resources.ts:4-24 (helper)Helper function that generates 100 static test resources (alternating plaintext and binary blobs), called by the tool handler to provide resources for linking.export const generateAllResources = (): Resource[] => { return Array.from({ length: 100 }, (_, i) => { const uri = `test://static/resource/${i + 1}`; if (i % 2 === 0) { return { uri, name: `Resource ${i + 1}`, mimeType: "text/plain", text: `Resource ${i + 1}: This is a plaintext resource`, }; } else { const buffer = Buffer.from(`Resource ${i + 1}: This is a base64 blob`); return { uri, name: `Resource ${i + 1}`, mimeType: "application/octet-stream", blob: buffer.toString("base64"), }; } }); };