From 988a82f8a772c2c09da1bf04b96fd2d4d7813373 Mon Sep 17 00:00:00 2001 From: Raed Date: Fri, 25 Apr 2025 16:11:55 +0200 Subject: [PATCH] feat: allow for allow-tools=all --- src/app.ts | 11 ++++++++--- src/commands/list-tools.ts | 10 ++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/app.ts b/src/app.ts index dc2992f..0c2b7ab 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,6 +1,6 @@ import { Command } from "commander"; import { type StartServerOptions } from "./commands/start-server.ts"; -import { type ListToolsOptions } from "./commands/list-tools.ts"; +import { getToolIds, type ListToolsOptions } from "./commands/list-tools.ts"; const program = new Command("algolia-mcp"); @@ -53,8 +53,13 @@ const DEFAULT_ALLOW_TOOLS = [ ]; const ALLOW_TOOLS_OPTIONS_TUPLE = [ "-t, --allow-tools ", - "Comma separated list of tool ids", - (val: string) => val.split(",").map((s) => s.trim()), + "Comma separated list of tool ids (or all)", + (val: string) => { + if (val.trim().toLowerCase() === "all") { + return getToolIds(); + } + return val.split(",").map((tool) => tool.trim()); + }, DEFAULT_ALLOW_TOOLS, ] as const; diff --git a/src/commands/list-tools.ts b/src/commands/list-tools.ts index d2ea312..70d8d84 100644 --- a/src/commands/list-tools.ts +++ b/src/commands/list-tools.ts @@ -1,8 +1,18 @@ import { operationId as GetUserInfoOperationId } from "../tools/registerGetUserInfo.ts"; import { operationId as GetApplicationsOperationId } from "../tools/registerGetApplications.ts"; import { ALL_SPECS, type OpenApiSpec } from "../openApi.ts"; +import type { ToolFilter } from "../toolFilters.ts"; import { type CliFilteringOptions, getToolFilter, isToolAllowed } from "../toolFilters.ts"; +export function getToolIds(toolFilter?: ToolFilter): string[] { + const results = []; + for (const spec of ALL_SPECS) { + const toolIds = extractToolIds(spec).filter((id) => isToolAllowed(id, toolFilter)); + results.push(...toolIds); + } + return results; +} + export type ListToolsOptions = CliFilteringOptions & { all: boolean; };