getResourceReference
Retrieve a resource reference for MCP clients by specifying a resource ID (1-100), enabling dynamic user input collection in the MCP Elicitations Demo Server.
Instructions
Returns a resource reference that can be used by MCP clients
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| resourceId | Yes | ID of the resource to reference (1-100) |
Implementation Reference
- The main exported tool object for getResourceReference, including the async handler function that executes the tool logic: validates resourceId, generates all resources, retrieves the specific resource, and returns MCP-formatted content with the resource reference.export const getResourceReferenceTool = { name: "getResourceReference", description: "Returns a resource reference that can be used by MCP clients", inputSchema: zodToJsonSchema(GetResourceReferenceSchema), handler: async (args: any) => { const validatedArgs = GetResourceReferenceSchema.parse(args); const resourceId = validatedArgs.resourceId; const ALL_RESOURCES = generateAllResources(); const resourceIndex = resourceId - 1; if (resourceIndex < 0 || resourceIndex >= ALL_RESOURCES.length) { throw new Error(`Resource with ID ${resourceId} does not exist`); } const resource = ALL_RESOURCES[resourceIndex]; return { content: [ { type: "text" as const, text: `Returning resource reference for Resource ${resourceId}:`, }, { type: "resource" as const, resource: resource, }, { type: "text" as const, text: `You can access this resource using the URI: ${resource.uri}`, }, ], }; }, };
- Zod schema defining the input for the tool: a number resourceId between 1 and 100.const GetResourceReferenceSchema = z.object({ resourceId: z .number() .min(1) .max(100) .describe("ID of the resource to reference (1-100)"), });
- src/tools/index.ts:22-37 (registration)The getResourceReferenceTool is registered by including it in the allTools array, which is used by getTools() to list tools and by getToolHandler() to dispatch calls to the correct handler.const allTools = [ echoTool, addTool, longRunningOperationTool, printEnvTool, sampleLlmTool, sampleWithPreferencesTool, sampleMultimodalTool, sampleConversationTool, sampleAdvancedTool, getTinyImageTool, annotatedMessageTool, getResourceReferenceTool, elicitationTool, getResourceLinksTool, ];
- src/tools/index.ts:14-14 (registration)Import of the getResourceReferenceTool from its implementation file.import { getResourceReferenceTool } from "./tool-get-resource-reference.js";