Skip to main content
Glama
query-tool.ts1.4 kB
import { z } from "zod" import { findApps } from "../apps" import { QUERY_TOOL_NAME } from "../const" import { QueryToolSchema } from "../schemas" import { type ToolConfigStateMachine } from "./toolConfigStateMachine" import { wrapTool, type ToolDefinition } from "./wrapper" const QuerySchema = z.object(QueryToolSchema) const queryToolDef: ToolDefinition = { name: QUERY_TOOL_NAME, isActive: () => true, description: `What API or integration are you trying to use? What problem are you trying to solve? You can tell me multiple parts at the same time and I will return a list of apps that can solve your problem. `, inputSchema: QuerySchema, callback: async (args, extra, machine) => { const { query } = args const { topApps, relevantApps } = await findApps(query) // update machine.appSlugToHashid with the new apps relevantApps.forEach((app) => { machine.appSlugToHashid[app.slug] = app.hid }) machine.state = { ...machine.state, stage: "AVAILABLE_APPS", availableApps: topApps, } return { content: [ { type: "text", text: `Based on your query "${query}", I found these relevant apps: ${topApps.join(", ")}. Please select which ones you'd like to use.`, }, ], } }, } export const queryTool = (machine: ToolConfigStateMachine) => wrapTool(queryToolDef, machine)

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/rajnandan1/pd-mcp'

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