Skip to main content
Glama
select-apps-tool.ts1.49 kB
import { z } from "zod" import { SELECT_APPS_TOOL_NAME } from "../const" import { SelectAppsSchema } from "../schemas" import { wrapTool, type ToolDefinition } from "./wrapper" import { type ToolConfigStateMachine } from "./toolConfigStateMachine" import { pd } from "../../pd-client" const SelectSchema = z.object(SelectAppsSchema) const selectAppsToolDef: ToolDefinition = { name: SELECT_APPS_TOOL_NAME, isActive: (stage) => ["AVAILABLE_APPS", "APPS_SELECTED", "INITIAL"].includes(stage), description: "Select the apps you want to use", inputSchema: SelectSchema, callback: async (_args, _extra, machine) => { const args = SelectSchema.parse(_args) const { apps: selectedApps } = args const invalidApps: string[] = [] for (const app of selectedApps) { const appInfo = await pd.getApp(app) if (!appInfo) { invalidApps.push(app) } } if (invalidApps.length > 0) { return { content: [ { type: "text", text: `Invalid apps: ${invalidApps.join(", ")}`, }, ], } } machine.state = { ...machine.state, stage: "APPS_SELECTED", selectedApps, } return { content: [ { type: "text", text: `Thanks, I've exposed tools for ${selectedApps.join(", ")}.`, }, ], } }, } export const selectAppsTool = (machine: ToolConfigStateMachine) => wrapTool(selectAppsToolDef, 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