Skip to main content
Glama
wrapper.ts1.3 kB
import { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js" import { CallToolResult, ServerNotification, ServerRequest, } from "@modelcontextprotocol/sdk/types.js" import { z, ZodType } from "zod" import { type ToolConfigStateMachine } from "./toolConfigStateMachine" import { Stage } from "./types" export type ToolCallback<Schema extends ZodType = ZodType> = ( args: z.infer<Schema>, extra: RequestHandlerExtra<ServerRequest, ServerNotification>, machine: ToolConfigStateMachine ) => CallToolResult | Promise<CallToolResult> export type ToolDefinition = { name: string description: string inputSchema: ZodType callback: ToolCallback<ZodType> isActive(stage: Stage): boolean } export const wrapTool = ( toolDef: ToolDefinition, machine: ToolConfigStateMachine ) => { const { isActive, name, callback, description, inputSchema, ...rest } = toolDef return { name, tool: { ...rest, description, inputSchema, callback: ( args: unknown = z.object({}), extra: RequestHandlerExtra<ServerRequest, ServerNotification> ) => { return callback(args, extra, machine) }, }, isActive: (stage: Stage) => isActive(stage), } } export type WrappedTool = ReturnType<typeof wrapTool>

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/rajnandan1/pd-mcp'

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