Skip to main content
Glama

Backlog MCP Server

composeToolHandler.ts1.62 kB
/* eslint-disable @typescript-eslint/no-explicit-any */ import { wrapWithErrorHandling } from '../transformers/wrapWithErrorHandling.js'; import { wrapWithFieldPicking } from '../transformers/wrapWithFieldPicking.js'; import { wrapWithTokenLimit } from '../transformers/wrapWithTokenLimit.js'; import { wrapWithToolResult } from '../transformers/wrapWithToolResult.js'; import { z } from 'zod'; import { generateFieldsDescription } from '../../utils/generateFieldsDescription.js'; import { ErrorLike } from '../../types/result.js'; import { ToolDefinition } from '../../types/tool.js'; interface ComposeOptions { useFields: boolean; errorHandler?: (err: unknown) => ErrorLike; maxTokens: number; } export function composeToolHandler( tool: ToolDefinition<any, any>, options: ComposeOptions ) { const { useFields, errorHandler, maxTokens } = options; // Step 1: Add `fields` to schema if needed if (useFields) { const fieldDesc = generateFieldsDescription( tool.outputSchema, (tool.importantFields as string[]) ?? [], tool.name ); tool.schema = extendSchema(tool.schema, fieldDesc); } // Step 2: Compose let handler = wrapWithErrorHandling(tool.handler, errorHandler); if (useFields) { handler = wrapWithFieldPicking(handler); } return wrapWithToolResult(wrapWithTokenLimit(handler, maxTokens)); } function extendSchema<I extends z.ZodRawShape>( schema: z.ZodObject<I>, desc: string ): z.ZodObject<I & { fields: z.ZodString }> { return schema.extend({ fields: z.string().describe(desc), }) as z.ZodObject<I & { fields: z.ZodString }>; }

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/nulab/backlog-mcp-server'

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