MCPcopy Create free account
hub / github.com/Noumena-Network/code / toolMatchesRule

Function toolMatchesRule

src/utils/permissions/permissions.ts:242–273  ·  view source on GitHub ↗

* Check if the entire tool matches a rule * For example, this matches "Bash" but not "Bash(prefix:*)" for BashTool * This also matches MCP tools with a server name, e.g. the rule "mcp__server1"

(
  tool: Pick<Tool, 'name' | 'mcpInfo'>,
  rule: PermissionRule,
)

Source from the content-addressed store, hash-verified

240 * This also matches MCP tools with a server name, e.g. the rule "mcp__server1"
241 */
242function toolMatchesRule(
243 tool: Pick<Tool, 'name' | 'mcpInfo'>,
244 rule: PermissionRule,
245): boolean {
246 // Rule must not have content to match the entire tool
247 if (rule.ruleValue.ruleContent !== undefined) {
248 return false
249 }
250
251 // MCP tools are matched by their fully qualified mcp__server__tool name. In
252 // skip-prefix mode (NCODE_AGENT_SDK_MCP_NO_PREFIX), MCP tools have unprefixed
253 // display names (e.g., "Write") that collide with builtin names; rules targeting
254 // builtins should not match their MCP replacements.
255 const nameForRuleMatch = getToolNameForPermissionCheck(tool)
256
257 // Direct tool name match
258 if (rule.ruleValue.toolName === nameForRuleMatch) {
259 return true
260 }
261
262 // MCP server-level permission: rule "mcp__server1" matches tool "mcp__server1__tool1"
263 // Also supports wildcard: rule "mcp__server1__*" matches all tools from server1
264 const ruleInfo = mcpInfoFromString(rule.ruleValue.toolName)
265 const toolInfo = mcpInfoFromString(nameForRuleMatch)
266
267 return (
268 ruleInfo !== null &&
269 toolInfo !== null &&
270 (ruleInfo.toolName === undefined || ruleInfo.toolName === '*') &&
271 ruleInfo.serverName === toolInfo.serverName
272 )
273}
274
275/**
276 * Check if the entire tool is listed in the always allow rules

Callers 3

toolAlwaysAllowedRuleFunction · 0.85
getDenyRuleForToolFunction · 0.85
getAskRuleForToolFunction · 0.85

Calls 2

mcpInfoFromStringFunction · 0.85

Tested by

no test coverage detected