-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathapp.ts
More file actions
129 lines (121 loc) · 3.46 KB
/
app.ts
File metadata and controls
129 lines (121 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import { Command } from "commander";
import { type ListToolsOptions } from "./commands/list-tools.ts";
const program = new Command("algolia-mcp");
const DEFAULT_ALLOW_TOOLS = [
// Dashboard API Tools
"getUserInfo",
"getApplications",
// Search
"listIndices",
"getSettings",
"searchSingleIndex",
"searchRules",
"searchSynonyms",
"saveObject",
"batch",
"multipleBatch",
"partialUpdateObject",
"deleteByQuery",
"getObject",
"getObjects",
// Analytics
"getTopSearches",
"getTopHits",
"getNoResultsRate",
// AB Testing
"listABTests",
// Monitoring
"getClustersStatus",
"getIncidents",
// Ingestion
"listTransformations",
"listTasks",
"listDestinations",
"listSources",
// Usage
"retrieveMetricsRegistry",
"retrieveMetricsDaily",
"retrieveApplicationMetricsHourly",
// Collections
"listCollections",
"getCollection",
// Query Suggestions
"listQuerySuggestionsConfigs",
"getQuerySuggestionsConfig",
"createQuerySuggestionsConfig",
"updateQuerySuggestionsConfig",
"getQuerySuggestionConfigStatus",
"getQuerySuggestionLogFile",
// Custom settings
"setAttributesForFaceting",
"setCustomRanking",
];
const ALLOW_TOOLS_OPTIONS_TUPLE = [
"-t, --allow-tools <tools>",
"Comma separated list of tool ids (or all)",
(val: string) => {
if (val.trim().toLowerCase() === "all") {
return [];
}
return val.split(",").map((tool) => tool.trim());
},
DEFAULT_ALLOW_TOOLS,
] as const;
program
.command("start-server", { isDefault: true })
.description("Starts the Algolia MCP server")
.option<string[] | undefined>(...ALLOW_TOOLS_OPTIONS_TUPLE)
.option(
"--credentials <applicationId:apiKey>",
"Application ID and associated API key to use. Optional: the MCP will authenticate you if unspecified, giving you access to all your applications.",
(val) => {
const [applicationId, apiKey] = val.split(":");
if (!applicationId || !apiKey) {
throw new Error("Invalid credentials format. Use applicationId:apiKey");
}
return { applicationId, apiKey };
},
)
.option("--transport [stdio|http]", "Transport type, either `stdio` (default) or `http`", "stdio")
.action(async (opts) => {
switch (opts.transport) {
case "stdio": {
const { startServer } = await import("./commands/start-server.ts");
await startServer(opts);
break;
}
case "http": {
console.info('Starting server with HTTP transport support');
const { startHttpServer } = await import("./commands/start-http-server.ts");
await startHttpServer(opts);
break;
}
default:
console.error(`Unknown transport type: ${opts.transport}\nAllowed values: stdio, http`);
process.exit(1);
}
});
program
.command("authenticate")
.description("Authenticate with Algolia")
.action(async () => {
const { authenticate } = await import("./commands/authenticate.ts");
await authenticate();
});
program
.command("logout")
.description("Remove all stored credentials")
.action(async () => {
const { logout } = await import("./commands/logout.ts");
await logout();
});
program
.command("list-tools")
.description("List available tools")
.option<string[] | undefined>(...ALLOW_TOOLS_OPTIONS_TUPLE)
.option("--all", "List all tools")
.action(async (opts: ListToolsOptions) => {
const { listTools } = await import("./commands/list-tools.ts");
await listTools(opts);
});
program.parse();