MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / filterToolsBySet

Function filterToolsBySet

server/src/addie/bolt-app.ts:1120–1157  ·  view source on GitHub ↗

* Filter tools to only include those in the selected tool sets. * This reduces the context sent to Sonnet based on Haiku's routing decision. * * @param userTools - All tools available to the user * @param selectedSets - Tool set names from the router's execution plan * @param isAAOAdmin - Wheth

(
  userTools: RequestTools,
  selectedSets: string[],
  isAAOAdmin: boolean,
  isPublicChannel: boolean = false
)

Source from the content-addressed store, hash-verified

1118 * @returns Filtered tools and a hint about unavailable sets
1119 */
1120function filterToolsBySet(
1121 userTools: RequestTools,
1122 selectedSets: string[],
1123 isAAOAdmin: boolean,
1124 isPublicChannel: boolean = false
1125): { filteredTools: RequestTools; unavailableHint: string } {
1126 // Get all tool names that should be available based on selected sets
1127 const allowedToolNames = new Set(getToolsForSets(selectedSets, isAAOAdmin, isPublicChannel));
1128
1129 // Filter tools to only those allowed
1130 const filteredToolDefs = userTools.tools.filter(tool => allowedToolNames.has(tool.name));
1131
1132 // Filter handlers to match
1133 const filteredHandlers = new Map<string, (input: Record<string, unknown>) => Promise<string>>();
1134 for (const [name, handler] of userTools.handlers) {
1135 if (allowedToolNames.has(name)) {
1136 filteredHandlers.set(name, handler);
1137 }
1138 }
1139
1140 // Build hint about unavailable tool sets
1141 const unavailableHint = buildUnavailableSetsHint(selectedSets, isAAOAdmin);
1142
1143 logger.debug({
1144 selectedSets,
1145 allowedCount: filteredToolDefs.length,
1146 totalCount: userTools.tools.length,
1147 filteredToolNames: filteredToolDefs.map(t => t.name),
1148 }, 'Addie Bolt: Filtered tools by set');
1149
1150 return {
1151 filteredTools: {
1152 tools: filteredToolDefs,
1153 handlers: filteredHandlers,
1154 },
1155 unavailableHint,
1156 };
1157}
1158
1159async function selectRoutedToolsForSlackResponse(
1160 messageText: string,

Callers 2

handleChannelMessageFunction · 0.85

Calls 4

getToolsForSetsFunction · 0.85
buildUnavailableSetsHintFunction · 0.85
hasMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected