Skip to main content
Glama
cli.tsโ€ข989 B
import { ZodError } from 'zod' import tools from './tools.js' import type { Tool } from './types.js' type Tools = typeof tools type ToolName = keyof Tools const cli = { isCommand: (arg: string) => arg in tools, async run(args: string[]) { try { const cmd = args.shift() as ToolName const tool = tools[cmd] const res = await cli.runTool(tool, tool.fromArgs(args)) console.log(res) } catch (err) { if (err instanceof ZodError) { const issues = err.issues.map(issue => `${issue.path.join('.')}: ${issue.message}`).join(', ') console.error(`Error: ${issues}`) process.exit(1) } throw err } }, async runTool(tool: Tool, args: any): Promise<string> { try { const validatedArgs = tool.schema.parse(args) const result = tool.handler(validatedArgs) return typeof result === 'string' ? result : JSON.stringify(result) } catch (err) { throw err } }, } export default cli

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/flesler/mcp-tasks'

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