Skip to content

Commit 36b75c7

Browse files
authored
refactor: reorganize tool resolution order in resolveTools (#708)
1 parent e5cae2f commit 36b75c7

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/tool.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,29 +98,28 @@ export async function resolveTools(opts: ResolveToolsOpts) {
9898
...mcpTools,
9999
];
100100

101-
const toolsConfig = opts.context.config.tools;
102-
let availableTools = (() => {
103-
if (!toolsConfig || Object.keys(toolsConfig).length === 0) {
104-
return allTools;
105-
}
106-
return allTools.filter((tool) => {
107-
// Check if the tool is disabled (only explicitly set to false will disable)
108-
const isDisabled = toolsConfig[tool.name] === false;
109-
return !isDisabled;
110-
});
111-
})();
112-
101+
// 1. First, execute plugin hook to allow plugins to add/modify tools
102+
let availableTools = allTools;
113103
try {
114104
availableTools = await opts.context.apply({
115105
hook: 'tool',
116106
args: [{ isPlan: opts.isPlan, sessionId: opts.sessionId }],
117-
memo: availableTools,
107+
memo: allTools,
118108
type: PluginHookType.SeriesMerge,
119109
});
120110
} catch (error) {
121111
console.warn('[resolveTools] Plugin tool hook failed:', error);
122112
}
123113

114+
// 2. Then, filter all tools (including plugin-injected ones) by config
115+
const toolsConfig = opts.context.config.tools;
116+
if (toolsConfig && Object.keys(toolsConfig).length > 0) {
117+
availableTools = availableTools.filter((tool) => {
118+
// Only explicitly set to false will disable the tool
119+
return toolsConfig[tool.name] !== false;
120+
});
121+
}
122+
124123
const taskTools = (() => {
125124
// Task tool is only available in quiet mode
126125
if (!opts.task) return [];

0 commit comments

Comments
 (0)