Skip to main content
Glama
soriat

MCP Elicitations Demo Server

by soriat

longRunningOperation

Simulates and tracks long-running operations with progress updates by defining duration and steps, aiding in testing and monitoring dynamic processes on MCP Elicitations Demo Server.

Instructions

Demonstrates a long running operation with progress updates

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
durationNoDuration of the operation in seconds
stepsNoNumber of steps in the operation

Implementation Reference

  • The handler function that executes the long-running operation logic, parsing inputs, simulating steps with delays, sending progress notifications if available, and returning a completion message.
    handler: async (args: any, request: any, server: Server) => {
      const validatedArgs = LongRunningOperationSchema.parse(args);
      const { duration, steps } = validatedArgs;
      const stepDuration = duration / steps;
      const progressToken = request.params._meta?.progressToken;
    
      for (let i = 1; i < steps + 1; i++) {
        await new Promise((resolve) =>
          setTimeout(resolve, stepDuration * 1000)
        );
    
        if (progressToken !== undefined) {
          await server.notification({
            method: "notifications/progress",
            params: {
              progress: i,
              total: steps,
              progressToken,
            },
          });
        }
      }
    
      return {
        content: [
          {
            type: "text" as const,
            text: `Long running operation completed. Duration: ${duration} seconds, Steps: ${steps}.`,
          },
        ],
      };
    },
  • Zod schema for validating tool inputs: duration (default 10 seconds) and steps (default 5). Used in handler and converted to JSON schema for inputSchema.
    const LongRunningOperationSchema = z.object({
      duration: z
        .number()
        .default(10)
        .describe("Duration of the operation in seconds"),
      steps: z.number().default(5).describe("Number of steps in the operation"),
    });
  • Registration of the longRunningOperationTool in the allTools array, which is used by getTools() to list tools and getToolHandler() to find the handler for execution.
    const allTools = [
      echoTool,
      addTool,
      longRunningOperationTool,
      printEnvTool,
      sampleLlmTool,
      sampleWithPreferencesTool,
      sampleMultimodalTool,
      sampleConversationTool,
      sampleAdvancedTool,
      getTinyImageTool,
      annotatedMessageTool,
      getResourceReferenceTool,
      elicitationTool,
      getResourceLinksTool,
    ];
  • Setup function that registers the general request handlers for listing tools (ListToolsRequestSchema) and calling tools (CallToolRequestSchema) on the MCP server, enabling execution of longRunningOperationTool.
    export const setupTools = (server: Server) => {
      // Handle listing all available tools
      server.setRequestHandler(ListToolsRequestSchema, async () => {
        return { tools: getTools() };
      });
    
      // Handle tool execution
      server.setRequestHandler(CallToolRequestSchema, async (request) => {
        const { name, arguments: args } = request.params;
        const handler = getToolHandler(name);
    
        if (handler) {
          return await handler(args, request, server);
        }
    
        throw new Error(`Unknown tool: ${name}`);
      });
    };
Install Server

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