Skip to main content
Glama
autoloader.ts1.47 kB
import { readdir } from 'fs/promises'; import { join, dirname } from 'path'; import { fileURLToPath } from 'url'; import type { Ollama } from 'ollama'; import { ResponseFormat } from './types.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); /** * Represents a tool's metadata and handler function */ export interface ToolDefinition { name: string; description: string; inputSchema: { type: 'object'; properties: Record<string, unknown>; required?: string[]; }; handler: ( ollama: Ollama, args: Record<string, unknown>, format: ResponseFormat ) => Promise<string>; } /** * Discover and load all tools from the tools directory */ export async function discoverTools(): Promise<ToolDefinition[]> { const toolsDir = join(__dirname, 'tools'); const files = await readdir(toolsDir); // Filter for .js files (production) or .ts files (development) // Exclude test files and declaration files const toolFiles = files.filter( (file) => (file.endsWith('.js') || file.endsWith('.ts')) && !file.includes('.test.') && !file.endsWith('.d.ts') ); const tools: ToolDefinition[] = []; for (const file of toolFiles) { const toolPath = join(toolsDir, file); const module = await import(toolPath); // Check if module exports tool metadata if (module.toolDefinition) { tools.push(module.toolDefinition); } } 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/rawveg/ollama-mcp'

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