Skip to content

parseAllowedTools() only parses first --allowed-tools flag, breaking GitHub MCP server initialization #800

@AlexanderBartash

Description

@AlexanderBartash

Summary

The parseAllowedTools() function in src/modes/agent/parse-tools.ts only extracts tools from the first --allowed-tools flag, ignoring any subsequent flags. This causes GitHub MCP servers (like github_inline_comment) to not initialize when users specify multiple --allowed-tools flags in their claude_args.

Reproduction

  1. Configure a workflow with multiple --allowed-tools flags:
claude_args: |
  --allowed-tools 'mcp__context7__*'
  --allowed-tools 'Read,Glob,Grep,LS'
  --allowed-tools 'mcp__github_inline_comment__create_inline_comment'
  1. Trigger Claude via a PR comment

  2. Observe that:

    • mcp__github_inline_comment__create_inline_comment appears in final allowedTools array ✅
    • But github_inline_comment MCP server is NOT initialized ❌

Root Cause

In src/modes/agent/parse-tools.ts:

export function parseAllowedTools(claudeArgs: string): string[] {
  const patterns = [
    /--(?:allowedTools|allowed-tools)\s+"([^"]+)"/,
    /--(?:allowedTools|allowed-tools)\s+'([^']+)'/,
    /--(?:allowedTools|allowed-tools)\s+([^\s]+)/,
  ];

  for (const pattern of patterns) {
    const match = claudeArgs.match(pattern);  // ← Only finds FIRST match
    if (match && match[1]) {
      return match[1].split(",")...;  // ← Returns immediately
    }
  }
  return [];
}

The regex patterns don't use the /g flag, and .match() only returns the first match. The function returns immediately after finding one match.

Impact

In Tag Mode, this parsed list is filtered for mcp__github_* tools to determine which MCP servers to start:

const userAllowedMCPTools = parseAllowedTools(userClaudeArgs).filter(
  (tool) => tool.startsWith("mcp__github_"),
);

If the first --allowed-tools flag doesn't contain mcp__github_* tools, no GitHub MCP servers get initialized from user config.

Suggested Fix

Use matchAll() with /g flag to find ALL occurrences:

export function parseAllowedTools(claudeArgs: string): string[] {
  const patterns = [
    /--(?:allowedTools|allowed-tools)\s+"([^"]+)"/g,
    /--(?:allowedTools|allowed-tools)\s+'([^']+)'/g,
    /--(?:allowedTools|allowed-tools)\s+([^\s]+)/g,
  ];

  const tools: string[] = [];
  for (const pattern of patterns) {
    for (const match of claudeArgs.matchAll(pattern)) {
      if (match[1] && !match[1].startsWith("--")) {
        tools.push(...match[1].split(",").map((t) => t.trim()));
      }
    }
  }
  return [...new Set(tools)]; // Deduplicate
}

Workaround

Put mcp__github_* tools in the first --allowed-tools flag:

claude_args: |
  --allowed-tools 'mcp__github_inline_comment__create_inline_comment'  # Must be first!
  --allowed-tools 'mcp__context7__*'
  --allowed-tools 'Read,Glob,Grep,LS'

Environment

  • claude-code-action version: v1.0.28 (c9ec2b0)
  • Event type: issue_comment on PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmcpp1Showstopper bug preventing substantial subset of users from using the product, or incorrect docs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions