@@ -22,7 +22,6 @@ import { redactToolPayloadText } from "../logging/redact.js";
2222import type { PluginManifestRegistry } from "../plugins/manifest-registry.js" ;
2323import { runTasksWithConcurrency } from "../utils/run-with-concurrency.js" ;
2424import { mergeMcpToolCatalogs } from "./agent-bundle-mcp-combined.js" ;
25- import { matchesMcpToolFilterPattern } from "./agent-bundle-mcp-filter.js" ;
2625import {
2726 completeDeferredSessionMcpRuntimeRetirement ,
2827 disposeAllSessionMcpRuntimes ,
@@ -69,6 +68,7 @@ import { createMcpJsonSchemaValidator } from "./mcp-json-schema-validator.js";
6968import { sanitizeMcpMetadataText } from "./mcp-metadata.js" ;
7069import { collectMcpPaginatedItems } from "./mcp-pagination.js" ;
7170import { OpenClawStdioClientTransport } from "./mcp-stdio-transport.js" ;
71+ import { isMcpToolAllowed , normalizeMcpToolFilter } from "./mcp-tool-filter.js" ;
7272import { resolveMcpTransport } from "./mcp-transport.js" ;
7373
7474type BundleMcpSession = {
@@ -114,11 +114,6 @@ function getBundleMcpTestState(): BundleMcpTestState {
114114 return state ;
115115}
116116
117- type McpToolSelection = {
118- include ?: readonly string [ ] ;
119- exclude ?: readonly string [ ] ;
120- } ;
121-
122117type McpServerBackoffState = {
123118 session : BundleMcpSession ;
124119 failures : number ;
@@ -285,14 +280,6 @@ function buildMcpClientOptions(mcpAppsEnabled: boolean): ClientOptions {
285280 return { capabilities : buildMcpClientCapabilities ( mcpAppsEnabled ) } ;
286281}
287282
288- function normalizeStringList ( value : unknown ) : string [ ] | undefined {
289- if ( ! Array . isArray ( value ) ) {
290- return undefined ;
291- }
292- const entries = value . filter ( ( entry ) : entry is string => typeof entry === "string" ) ;
293- return entries . length > 0 ? entries : undefined ;
294- }
295-
296283function normalizeToolUiVisibility ( value : unknown ) : Array < "app" | "model" > | undefined {
297284 if ( ! Array . isArray ( value ) ) {
298285 return undefined ;
@@ -303,28 +290,6 @@ function normalizeToolUiVisibility(value: unknown): Array<"app" | "model"> | und
303290 return [ ...new Set ( normalized ) ] . toSorted ( ) ;
304291}
305292
306- function getMcpToolSelection ( rawServer : unknown ) : McpToolSelection {
307- if ( ! isRecord ( rawServer ) || ! isRecord ( rawServer . toolFilter ) ) {
308- return { } ;
309- }
310- return {
311- include : normalizeStringList ( rawServer . toolFilter . include ) ,
312- exclude : normalizeStringList ( rawServer . toolFilter . exclude ) ,
313- } ;
314- }
315-
316- function shouldExposeMcpTool ( selection : McpToolSelection , toolName : string ) : boolean {
317- const include = selection . include ?? [ ] ;
318- const exclude = selection . exclude ?? [ ] ;
319- if (
320- include . length > 0 &&
321- ! include . some ( ( pattern ) => matchesMcpToolFilterPattern ( pattern , toolName ) )
322- ) {
323- return false ;
324- }
325- return ! exclude . some ( ( pattern ) => matchesMcpToolFilterPattern ( pattern , toolName ) ) ;
326- }
327-
328293function summarizeServerCapabilities ( capabilities : ServerCapabilities | undefined ) {
329294 return {
330295 resources : capabilities ?. resources
@@ -891,13 +856,15 @@ export function createSessionMcpRuntime(params: {
891856 ) ,
892857 } ) ;
893858 failIfDisposed ( ) ;
894- const selection = getMcpToolSelection ( rawServer ) ;
859+ const toolFilter = normalizeMcpToolFilter (
860+ isRecord ( rawServer ) ? rawServer . toolFilter : undefined ,
861+ ) ;
895862 const denialMap = params . toolOverrides ?. mcpToolsDeny ;
896863 const deniedToolNames = new Set (
897864 denialMap && Object . hasOwn ( denialMap , serverName ) ? denialMap [ serverName ] : [ ] ,
898865 ) ;
899866 const policyEligibleTools = listedTools . filter ( ( tool ) =>
900- shouldExposeMcpTool ( selection , tool . name . trim ( ) ) ,
867+ isMcpToolAllowed ( toolFilter , tool . name . trim ( ) ) ,
901868 ) ;
902869 const exposedTools = policyEligibleTools . filter ( ( tool ) => {
903870 const toolName = tool . name . trim ( ) ;
@@ -922,14 +889,7 @@ export function createSessionMcpRuntime(params: {
922889 } ,
923890 }
924891 : { } ) ,
925- ...( selection . include || selection . exclude
926- ? {
927- toolFilter : {
928- ...( selection . include ? { include : [ ...selection . include ] } : { } ) ,
929- ...( selection . exclude ? { exclude : [ ...selection . exclude ] } : { } ) ,
930- } ,
931- }
932- : { } ) ,
892+ ...( toolFilter ? { toolFilter } : { } ) ,
933893 ...( deniedToolNames . size > 0
934894 ? { deniedToolNames : [ ...deniedToolNames ] . toSorted ( ) }
935895 : { } ) ,
0 commit comments