Skip to main content
Glama
soriat

MCP Elicitations Demo Server

by soriat
tool-long-running-operation.ts1.48 kB
import { z } from "zod"; import { zodToJsonSchema } from "zod-to-json-schema"; import { Server } from "@modelcontextprotocol/sdk/server/index.js"; 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"), }); export const longRunningOperationTool = { name: "longRunningOperation", description: "Demonstrates a long running operation with progress updates", inputSchema: zodToJsonSchema(LongRunningOperationSchema), 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}.`, }, ], }; }, };

Implementation Reference

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