Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions crates/forge_app/src/tool_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,16 @@ impl ToolResolver {

pub fn is_allowed(agent: &Agent, tool_name: &ToolName) -> bool {
let aliases = deprecated_tool_aliases();
// Normalize the incoming tool name using aliases
let normalized_tool_name = aliases.get(tool_name.as_str()).unwrap_or(tool_name);
Self::is_allowed_pattern(&Self::build_patterns(agent), normalized_tool_name)
let legacy_mcp_tool_name = normalized_tool_name.to_legacy_mcp_name();
let patterns = Self::build_patterns(agent);

Self::is_allowed_pattern(&patterns, normalized_tool_name)
|| legacy_mcp_tool_name
.as_ref()
.is_some_and(|legacy_tool_name| {
Self::is_allowed_pattern(&patterns, legacy_tool_name)
})
}

/// Builds glob patterns from the agent's tool patterns, deduplicating
Expand Down Expand Up @@ -336,6 +343,36 @@ mod tests {
assert_eq!(actual, expected);
}

#[test]
fn test_exact_legacy_mcp_tool_allows_claude_code_name() {
let fixture = Agent::new(
AgentId::new("test-agent"),
ProviderId::ANTHROPIC,
ModelId::new("claude-3-5-sonnet-20241022"),
)
.tools(vec![ToolName::new("mcp_github_tool_create_issue")]);

assert!(ToolResolver::is_allowed(
&fixture,
&ToolName::new("mcp__github__create_issue"),
));
}

#[test]
fn test_glob_legacy_mcp_tool_allows_claude_code_name() {
let fixture = Agent::new(
AgentId::new("test-agent"),
ProviderId::ANTHROPIC,
ModelId::new("claude-3-5-sonnet-20241022"),
)
.tools(vec![ToolName::new("mcp_github_tool_*")]);

assert!(ToolResolver::is_allowed(
&fixture,
&ToolName::new("mcp__github__create_issue"),
));
}

#[test]
fn test_backward_compatibility_search_alias() {
// Test that deprecated "search" name resolves to "fs_search"
Expand Down
Loading