Skip to main content
Glama
runTool.test.ts1.36 kB
import { z } from 'zod'; import { runTool, text } from '@/utils/mcp'; describe('runTool wrapper', () => { it('validates input with schema and returns success content', async () => { const schema = z.object({ n: z.number().int() }); const handler = async (_args: { n: number }) => text('ok'); const res = await runTool('test_tool', schema, handler, { n: 1 }); expect(res.content?.[0]?.text).toBe('ok'); }); it('formats validation errors via global error handler', async () => { const schema = z.object({ n: z.number().int() }); const handler = async (_args: { n: number }) => text('ok'); const res = await runTool('test_tool', schema, handler, { n: 'oops' }); // Response content is JSON-encoded error from global handler const payload = JSON.parse((res.content?.[0]?.text as string) ?? '{}'); expect(payload.success).toBe(false); expect(payload.error?.code).toBe('VALIDATION_ERROR'); }); it('formats thrown errors via global error handler', async () => { const schema = z.object({}); const handler = async () => { throw new Error('boom'); }; const res = await runTool('test_tool', schema, handler, {}); const payload = JSON.parse((res.content?.[0]?.text as string) ?? '{}'); expect(payload.success).toBe(false); expect(payload.error?.code).toBeDefined(); }); });

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/Daghis/teamcity-mcp'

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