@@ -184,6 +184,20 @@ fn custom_agent_to_agent_info(agent: &CustomAgentConfig) -> AgentInfo {
184184 }
185185 }
186186
187+ for tool in & allowed {
188+ if tool. to_ascii_lowercase ( ) . starts_with ( "mcp__" ) {
189+ info = info. enable_tool ( tool) ;
190+ }
191+ }
192+
193+ if !matches ! (
194+ agent. tools,
195+ ToolsConfig :: Category ( ToolCategory :: Mcp | ToolCategory :: All )
196+ ) && !allowed. iter ( ) . any ( |t| t. eq_ignore_ascii_case ( "mcp" ) )
197+ {
198+ info = info. disable_tool ( "mcp" ) ;
199+ }
200+
187201 info
188202}
189203
@@ -378,6 +392,63 @@ mod tests {
378392 assert ! ( info. model. is_none( ) ) ; // Should not have a model set
379393 }
380394
395+ #[ test]
396+ fn test_read_only_agent_disables_mcp_tools ( ) {
397+ let mut registry = CustomAgentRegistry :: new ( ) ;
398+ registry. register ( CustomAgentConfig :: new ( "readonly" ) . with_tools ( ToolsConfig :: read_only ( ) ) ) ;
399+
400+ let info = registry. to_agent_info ( "readonly" ) . unwrap ( ) ;
401+
402+ assert ! ( !info. is_tool_enabled( "mcp" ) ) ;
403+ assert ! ( !info. is_tool_enabled( "mcp__postgres__query" ) ) ;
404+ assert ! ( !info. is_tool_enabled( "MCP__postgres__query" ) ) ;
405+ assert ! ( info. is_tool_enabled( "read" ) ) ;
406+ }
407+
408+ #[ test]
409+ fn test_mcp_and_all_tool_configs_allow_mcp_tools ( ) {
410+ let mut registry = CustomAgentRegistry :: new ( ) ;
411+ registry. register (
412+ CustomAgentConfig :: new ( "mcp-agent" )
413+ . with_tools ( ToolsConfig :: Category ( ToolCategory :: Mcp ) ) ,
414+ ) ;
415+ registry. register ( CustomAgentConfig :: new ( "all-agent" ) . with_tools ( ToolsConfig :: all ( ) ) ) ;
416+
417+ let mcp_info = registry. to_agent_info ( "mcp-agent" ) . unwrap ( ) ;
418+ assert ! ( mcp_info. is_tool_enabled( "mcp__postgres__query" ) ) ;
419+
420+ let all_info = registry. to_agent_info ( "all-agent" ) . unwrap ( ) ;
421+ assert ! ( all_info. is_tool_enabled( "mcp__postgres__query" ) ) ;
422+ }
423+
424+ #[ test]
425+ fn test_custom_tools_list_can_allow_mcp_tools ( ) {
426+ let mut registry = CustomAgentRegistry :: new ( ) ;
427+ registry. register (
428+ CustomAgentConfig :: new ( "custom-mcp" ) . with_tools ( ToolsConfig :: custom ( [ "Read" , "mcp" ] ) ) ,
429+ ) ;
430+
431+ let info = registry. to_agent_info ( "custom-mcp" ) . unwrap ( ) ;
432+
433+ assert ! ( info. is_tool_enabled( "mcp__postgres__query" ) ) ;
434+ assert ! ( info. is_tool_enabled( "Read" ) ) ;
435+ assert ! ( !info. is_tool_enabled( "Execute" ) ) ;
436+ }
437+
438+ #[ test]
439+ fn test_custom_tools_list_can_allow_single_mcp_tool ( ) {
440+ let mut registry = CustomAgentRegistry :: new ( ) ;
441+ registry. register (
442+ CustomAgentConfig :: new ( "single-mcp" )
443+ . with_tools ( ToolsConfig :: custom ( [ "Read" , "mcp__postgres__query" ] ) ) ,
444+ ) ;
445+
446+ let info = registry. to_agent_info ( "single-mcp" ) . unwrap ( ) ;
447+
448+ assert ! ( info. is_tool_enabled( "mcp__postgres__query" ) ) ;
449+ assert ! ( !info. is_tool_enabled( "mcp__postgres__write" ) ) ;
450+ }
451+
381452 #[ test]
382453 fn test_tools_to_permission ( ) {
383454 // Read-only should have read_only permission
0 commit comments