Skip to main content
Glama
toolLoader.ts1.47 kB
import * as fs from "fs"; import * as path from "path"; export interface ToolDefinition { name: string; metadata: { title: string, description: string, inputSchema: Record<string, any> }; handler: (params: any) => Promise<any>; } export async function loadTools(): Promise<ToolDefinition[]> { const toolsDir = path.resolve( path.dirname(new URL(import.meta.url).pathname), "./tools" ); if (!fs.existsSync(toolsDir)) { console.warn(`Tools directory not found: ${toolsDir}`); return []; } const tools: ToolDefinition[] = []; const toolFiles = fs.readdirSync(toolsDir).filter(file => file.endsWith('.js') || file.endsWith('.ts') ); for (const file of toolFiles) { try { const toolPath = path.join(toolsDir, file); const toolModule = await import(toolPath); // Each tool file should export a default function that returns tool definitions if (typeof toolModule.default === 'function') { const toolDefs = await toolModule.default(); if (Array.isArray(toolDefs)) { tools.push(...toolDefs); } else { tools.push(toolDefs); } } } catch (error) { console.error(`Error loading tool file ${file}:`, error); } } return tools; }

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/jacopoc/mcp-for-apache-ofbiz'

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