Skip to content

Commit 6f60e27

Browse files
committed
unauth tools configuration to make it futureproof using map
1 parent 909c46f commit 6f60e27

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/index-internals.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { ApifyClient } from './apify-client.js';
66
import { defaults, HelperTools } from './const.js';
77
import { processParamsGetTools } from './mcp/utils.js';
88
import { addTool } from './tools/helpers.js';
9-
import { defaultTools, getActorsAsTools, toolCategories, toolCategoriesEnabledByDefault } from './tools/index.js';
9+
import { defaultTools, getActorsAsTools, toolCategories,
10+
toolCategoriesEnabledByDefault, unauthEnabledToolCategories, unauthEnabledTools } from './tools/index.js';
1011
import { actorNameToToolName } from './tools/utils.js';
1112
import type { ToolCategory } from './types.js';
1213
import { getExpectedToolNamesByCategories, getToolPublicFieldOnly } from './utils/tools.js';
@@ -27,4 +28,6 @@ export {
2728
processParamsGetTools,
2829
getActorsAsTools,
2930
getToolPublicFieldOnly,
31+
unauthEnabledToolCategories,
32+
unauthEnabledTools,
3033
};

src/tools/index.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ import { getUserRunsList } from './run_collection.js';
1616
import { searchApifyDocsTool } from './search-apify-docs.js';
1717
import { searchActors } from './store_collection.js';
1818

19+
/* list of tools that can be used without authentication */
20+
export const unauthEnabledTools: string[] = [
21+
// docs
22+
searchApifyDocsTool.name,
23+
fetchApifyDocsTool.name,
24+
];
25+
1926
export const toolCategories = {
2027
experimental: [
2128
addTool,
@@ -49,11 +56,29 @@ export const toolCategories = {
4956
getHtmlSkeleton,
5057
],
5158
};
59+
5260
export const toolCategoriesEnabledByDefault: ToolCategory[] = [
5361
'actors',
5462
'docs',
5563
];
5664

65+
/**
66+
* Builds the list of tool categories that are enabled for unauthenticated users.
67+
* A category is included if all tools in it are in the unauthEnabledTools list.
68+
*/
69+
function buildUnauthEnabledToolCategories(): ToolCategory[] {
70+
const unauthEnabledToolsSet = new Set(unauthEnabledTools);
71+
72+
return (Object.entries(toolCategories) as [ToolCategory, typeof toolCategories[ToolCategory]][])
73+
.filter(([, tools]) => {
74+
// Include category only if all tools are in the unauthEnabledTools list
75+
return tools.every((tool) => unauthEnabledToolsSet.has(tool.name));
76+
})
77+
.map(([category]) => category);
78+
}
79+
80+
export const unauthEnabledToolCategories = buildUnauthEnabledToolCategories();
81+
5782
export const defaultTools = getExpectedToolsByCategories(toolCategoriesEnabledByDefault);
5883

5984
// Export only the tools that are being used

0 commit comments

Comments
 (0)