@@ -14,11 +14,7 @@ import {
14
14
JsonObjectSchemaStrict ,
15
15
UnknownContext ,
16
16
} from './types' ;
17
- import type {
18
- ToolFilterCallable ,
19
- ToolFilterStatic ,
20
- ToolFilterContext ,
21
- } from './mcpUtil' ;
17
+ import type { ToolFilterCallable , ToolFilterStatic } from './mcpUtil' ;
22
18
import type { RunContext } from './runContext' ;
23
19
import type { Agent } from './agent' ;
24
20
@@ -34,7 +30,6 @@ export const DEFAULT_STREAMABLE_HTTP_MCP_CLIENT_LOGGER_NAME =
34
30
*/
35
31
export interface MCPServer {
36
32
cacheToolsList : boolean ;
37
- toolFilter ?: ToolFilterCallable | ToolFilterStatic ;
38
33
connect ( ) : Promise < void > ;
39
34
readonly name : string ;
40
35
close ( ) : Promise < void > ;
@@ -51,7 +46,7 @@ export interface MCPServer {
51
46
export abstract class BaseMCPServerStdio implements MCPServer {
52
47
public cacheToolsList : boolean ;
53
48
protected _cachedTools : any [ ] | undefined = undefined ;
54
- public toolFilter ?: ToolFilterCallable | ToolFilterStatic ;
49
+ protected toolFilter ?: ToolFilterCallable | ToolFilterStatic ;
55
50
56
51
protected logger : Logger ;
57
52
constructor ( options : MCPServerStdioOptions ) {
@@ -88,7 +83,7 @@ export abstract class BaseMCPServerStdio implements MCPServer {
88
83
export abstract class BaseMCPServerStreamableHttp implements MCPServer {
89
84
public cacheToolsList : boolean ;
90
85
protected _cachedTools : any [ ] | undefined = undefined ;
91
- public toolFilter ?: ToolFilterCallable | ToolFilterStatic ;
86
+ protected toolFilter ?: ToolFilterCallable | ToolFilterStatic ;
92
87
93
88
protected logger : Logger ;
94
89
constructor ( options : MCPServerStreamableHttpOptions ) {
@@ -160,13 +155,13 @@ export class MCPServerStdio extends BaseMCPServerStdio {
160
155
return this . underlying . close ( ) ;
161
156
}
162
157
async listTools (
163
- _runContext ?: RunContext < any > ,
164
- _agent ?: Agent < any , any > ,
158
+ runContext ?: RunContext < any > ,
159
+ agent ?: Agent < any , any > ,
165
160
) : Promise < MCPTool [ ] > {
166
161
if ( this . cacheToolsList && this . _cachedTools ) {
167
162
return this . _cachedTools ;
168
163
}
169
- const tools = await this . underlying . listTools ( ) ;
164
+ const tools = await this . underlying . listTools ( runContext , agent ) ;
170
165
if ( this . cacheToolsList ) {
171
166
this . _cachedTools = tools ;
172
167
}
@@ -196,13 +191,13 @@ export class MCPServerStreamableHttp extends BaseMCPServerStreamableHttp {
196
191
return this . underlying . close ( ) ;
197
192
}
198
193
async listTools (
199
- _runContext ?: RunContext < any > ,
200
- _agent ?: Agent < any , any > ,
194
+ runContext ?: RunContext < any > ,
195
+ agent ?: Agent < any , any > ,
201
196
) : Promise < MCPTool [ ] > {
202
197
if ( this . cacheToolsList && this . _cachedTools ) {
203
198
return this . _cachedTools ;
204
199
}
205
- const tools = await this . underlying . listTools ( ) ;
200
+ const tools = await this . underlying . listTools ( runContext , agent ) ;
206
201
if ( this . cacheToolsList ) {
207
202
this . _cachedTools = tools ;
208
203
}
@@ -273,16 +268,7 @@ async function getFunctionToolsFromServer<TContext = UnknownContext>(
273
268
}
274
269
return withMCPListToolsSpan (
275
270
async ( span ) => {
276
- let mcpTools = await server . listTools ( runContext , agent ) ;
277
- if ( server . toolFilter ) {
278
- mcpTools = await filterMcpTools (
279
- mcpTools ,
280
- server . toolFilter as ToolFilterCallable < TContext > | ToolFilterStatic ,
281
- runContext ,
282
- agent ,
283
- server . name ,
284
- ) ;
285
- }
271
+ const mcpTools = await server . listTools ( runContext , agent ) ;
286
272
span . spanData . result = mcpTools . map ( ( t ) => t . name ) ;
287
273
const tools : FunctionTool < TContext , any , string > [ ] = mcpTools . map ( ( t ) =>
288
274
mcpToFunctionTool ( t , server , convertSchemasToStrict ) ,
@@ -385,41 +371,6 @@ function ensureStrictJsonSchema(
385
371
return out ;
386
372
}
387
373
388
- async function filterMcpTools < TContext = UnknownContext > (
389
- tools : MCPTool [ ] ,
390
- filter : ToolFilterCallable < TContext > | ToolFilterStatic ,
391
- runContext : RunContext < TContext > | undefined ,
392
- agent : Agent < TContext , any > | undefined ,
393
- serverName : string ,
394
- ) : Promise < MCPTool [ ] > {
395
- if ( typeof filter === 'function' ) {
396
- if ( ! runContext || ! agent ) {
397
- return tools ;
398
- }
399
- const ctx = {
400
- runContext,
401
- agent,
402
- serverName,
403
- } as ToolFilterContext < TContext > ;
404
- const result : MCPTool [ ] = [ ] ;
405
- for ( const tool of tools ) {
406
- if ( await filter ( ctx , tool ) ) {
407
- result . push ( tool ) ;
408
- }
409
- }
410
- return result ;
411
- }
412
- return tools . filter ( ( t ) => {
413
- if ( filter . allowedToolNames && ! filter . allowedToolNames . includes ( t . name ) ) {
414
- return false ;
415
- }
416
- if ( filter . blockedToolNames && filter . blockedToolNames . includes ( t . name ) ) {
417
- return false ;
418
- }
419
- return true ;
420
- } ) ;
421
- }
422
-
423
374
/**
424
375
* Abstract base class for MCP servers that use a ClientSession for communication.
425
376
* Handles session management, tool listing, tool calling, and cleanup.
0 commit comments