Skip to main content
Glama
soriat

MCP Elicitations Demo Server

by soriat

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
NameRequiredDescriptionDefault
resourceIdYesID 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)"), });
  • 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, ];
  • Import of the getResourceReferenceTool from its implementation file.
    import { getResourceReferenceTool } from "./tool-get-resource-reference.js";

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/soriat/soria-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server