Skip to main content
Glama
spinner.ts2.34 kB
import { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol" import { ServerNotification, ServerRequest, } from "@modelcontextprotocol/sdk/types" export function spinner( text: string, extra?: RequestHandlerExtra<ServerRequest, ServerNotification>, progressToken: string = "spinner", total: number = 100, updateRequestId?: string | number ) { const isExtra = extra?.sendNotification !== undefined const requestId = updateRequestId || extra?.requestId function notify(payload: ServerNotification | null) { if (!isExtra || !payload) { console.error("extra is required") return spinnerObj } extra.sendNotification(payload) return spinnerObj } const spinnerObj = { start: (msg?: string) => notify({ method: "notifications/progress", params: { progressToken, message: msg || text, progress: 0, total, requestId, }, }), succeed: (msg?: string) => notify({ method: "notifications/progress", params: { progressToken, message: msg || text, progress: 1, total, requestId, }, }), fail: (msg?: string) => notify({ method: "notifications/message", params: { level: "error", data: { text: msg || text }, requestId }, }), info: (msg?: string) => notify({ method: "notifications/message", params: { level: "info", data: { text: msg || text }, requestId }, }), warn: (msg?: string) => notify({ method: "notifications/message", params: { level: "warning", data: { text: msg || text }, requestId }, }), stop: () => notify({ method: "notifications/message", params: { level: "info", data: { text: "Stopped" }, requestId }, }), stopAndPersist: () => notify({ method: "notifications/message", params: { level: "info", data: { text: "Stopped and persisted" }, requestId, }, }), progress: (progress: number, message?: string) => notify({ method: "notifications/progress", params: { progressToken, progress, message, total, requestId }, }), text, } return spinnerObj }

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/reuvenaor/israel-statistics-mcp'

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