Skip to content

Commit 0d6bf3e

Browse files
authored
feat: add cmd support for allowing all tools (#36)
## 🤔 What Allow for passing `start-server --allow-tools all` as a parameter. This helps with the ergonomics when configuring the server to take full advantage of all the tools. ```sh $ npm run start -- start-server --allow-tools all ```
1 parent 18f2c84 commit 0d6bf3e

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/app.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@ const DEFAULT_ALLOW_TOOLS = [
5353
];
5454
const ALLOW_TOOLS_OPTIONS_TUPLE = [
5555
"-t, --allow-tools <tools>",
56-
"Comma separated list of tool ids",
57-
(val: string) => val.split(",").map((s) => s.trim()),
56+
"Comma separated list of tool ids (or all)",
57+
(val: string) => {
58+
if (val.trim().toLowerCase() === "all") {
59+
return undefined;
60+
}
61+
return val.split(",").map((tool) => tool.trim());
62+
},
5863
DEFAULT_ALLOW_TOOLS,
5964
] as const;
6065

@@ -75,7 +80,7 @@ function formatErrorForCli(error: unknown): string {
7580
program
7681
.command("start-server", { isDefault: true })
7782
.description("Starts the Algolia MCP server")
78-
.option<string[]>(...ALLOW_TOOLS_OPTIONS_TUPLE)
83+
.option<string[] | undefined>(...ALLOW_TOOLS_OPTIONS_TUPLE)
7984
.option(
8085
"--credentials <applicationId:apiKey>",
8186
"Application ID and associated API key to use. Optional: the MCP will authenticate you if unspecified, giving you access to all your applications.",
@@ -116,7 +121,7 @@ program
116121
program
117122
.command("list-tools")
118123
.description("List available tools")
119-
.option<string[]>(...ALLOW_TOOLS_OPTIONS_TUPLE)
124+
.option<string[] | undefined>(...ALLOW_TOOLS_OPTIONS_TUPLE)
120125
.option("--all", "List all tools")
121126
.action(async (opts: ListToolsOptions) => {
122127
const { listTools } = await import("./commands/list-tools.ts");

src/commands/list-tools.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
import { operationId as GetUserInfoOperationId } from "../tools/registerGetUserInfo.ts";
22
import { operationId as GetApplicationsOperationId } from "../tools/registerGetApplications.ts";
33
import { ALL_SPECS, type OpenApiSpec } from "../openApi.ts";
4+
import type { ToolFilter } from "../toolFilters.ts";
45
import { type CliFilteringOptions, getToolFilter, isToolAllowed } from "../toolFilters.ts";
56

7+
export function getToolIds(toolFilter?: ToolFilter): string[] {
8+
const results = [];
9+
for (const spec of ALL_SPECS) {
10+
const toolIds = extractToolIds(spec).filter((id) => isToolAllowed(id, toolFilter));
11+
results.push(...toolIds);
12+
}
13+
return results;
14+
}
15+
616
export type ListToolsOptions = CliFilteringOptions & {
717
all: boolean;
818
};

0 commit comments

Comments
 (0)