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

Function checkPermissions

src/tools/SkillTool/SkillTool.ts:433–579  ·  view source on GitHub ↗
(
    { skill, args },
    context,
  )

Source from the content-addressed store, hash-verified

431 },
432
433 async checkPermissions(
434 { skill, args },
435 context,
436 ): Promise<PermissionDecision> {
437 // Skills are just skill names, no arguments
438 const trimmed = skill.trim()
439
440 // Remove leading slash if present (for compatibility)
441 const commandName = trimmed.startsWith('/') ? trimmed.substring(1) : trimmed
442
443 const appState = context.getAppState()
444 const permissionContext = appState.toolPermissionContext
445
446 // Look up the command object to pass as metadata
447 const commands = await getAllCommands(context)
448 const commandObj = findCommand(commandName, commands)
449
450 // Helper function to check if a rule matches the skill
451 // Normalizes both inputs by stripping leading slashes for consistent matching
452 const ruleMatches = (ruleContent: string): boolean => {
453 // Normalize rule content by stripping leading slash
454 const normalizedRule = ruleContent.startsWith('/')
455 ? ruleContent.substring(1)
456 : ruleContent
457
458 // Check exact match (using normalized commandName)
459 if (normalizedRule === commandName) {
460 return true
461 }
462 // Check prefix match (e.g., "review:*" matches "review-pr 123")
463 if (normalizedRule.endsWith(':*')) {
464 const prefix = normalizedRule.slice(0, -2) // Remove ':*'
465 return commandName.startsWith(prefix)
466 }
467 return false
468 }
469
470 // Check for deny rules
471 const denyRules = getRuleByContentsForTool(
472 permissionContext,
473 SkillTool as Tool,
474 'deny',
475 )
476 for (const [ruleContent, rule] of denyRules.entries()) {
477 if (ruleMatches(ruleContent)) {
478 return {
479 behavior: 'deny',
480 message: `Skill execution blocked by permission rules`,
481 decisionReason: {
482 type: 'rule',
483 rule,
484 },
485 }
486 }
487 }
488
489 // Remote canonical skills are ant-only experimental — auto-grant.
490 // Placed AFTER the deny loop so a user-configured Skill(_canonical_:*)

Callers

nothing calls this directly

Calls 7

findCommandFunction · 0.85
getRuleByContentsForToolFunction · 0.85
ruleMatchesFunction · 0.85
isInternalBuildFunction · 0.85
entriesMethod · 0.80
getAllCommandsFunction · 0.70

Tested by

no test coverage detected