Skip to content

Commit a3ff61d

Browse files
ashwin-antclaude
andauthored
enable track_progress for comments, fix mcp config (#558)
* enable track_progress for comments * refactor: pass mode explicitly to prepareMcpConfig Update prepareMcpConfig to receive the mode parameter from its callers instead of detecting agent mode by checking context.inputs.prompt. This makes mode determination explicit and controlled by the caller. Also update all test cases to include the required mode parameter and fix agent mode test expectations to match new behavior where MCP config is only included when tools are explicitly allowed. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix test --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1b7eb92 commit a3ff61d

File tree

7 files changed

+34
-9
lines changed

7 files changed

+34
-9
lines changed

src/mcp/install-mcp-server.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type PrepareConfigParams = {
1313
claudeCommentId?: string;
1414
allowedTools: string[];
1515
context: GitHubContext;
16+
mode: "tag" | "agent";
1617
};
1718

1819
async function checkActionsReadPermission(
@@ -59,12 +60,12 @@ export async function prepareMcpConfig(
5960
claudeCommentId,
6061
allowedTools,
6162
context,
63+
mode,
6264
} = params;
6365
try {
6466
const allowedToolsList = allowedTools || [];
6567

66-
// Detect if we're in agent mode (explicit prompt provided)
67-
const isAgentMode = !!context.inputs?.prompt;
68+
const isAgentMode = mode === "agent";
6869

6970
const hasGitHubMcpTools = allowedToolsList.some((tool) =>
7071
tool.startsWith("mcp__github__"),

src/modes/agent/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export const agentMode: Mode = {
136136
claudeCommentId: undefined, // No tracking comment in agent mode
137137
allowedTools,
138138
context,
139+
mode: "agent",
139140
});
140141

141142
// Build final claude_args with multiple --mcp-config flags

src/modes/detector.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ export function detectMode(context: GitHubContext): AutoDetectedMode {
1919

2020
// If track_progress is set for PR/issue events, force tag mode
2121
if (context.inputs.trackProgress && isEntityContext(context)) {
22-
if (isPullRequestEvent(context) || isIssuesEvent(context)) {
22+
if (
23+
isPullRequestEvent(context) ||
24+
isIssuesEvent(context) ||
25+
isIssueCommentEvent(context) ||
26+
isPullRequestReviewCommentEvent(context) ||
27+
isPullRequestReviewEvent(context)
28+
) {
2329
return "tag";
2430
}
2531
}
@@ -87,10 +93,16 @@ export function getModeDescription(mode: AutoDetectedMode): string {
8793

8894
function validateTrackProgressEvent(context: GitHubContext): void {
8995
// track_progress is only valid for pull_request and issue events
90-
const validEvents = ["pull_request", "issues"];
96+
const validEvents = [
97+
"pull_request",
98+
"issues",
99+
"issue_comment",
100+
"pull_request_review_comment",
101+
"pull_request_review",
102+
];
91103
if (!validEvents.includes(context.eventName)) {
92104
throw new Error(
93-
`track_progress is only supported for pull_request and issue events. ` +
105+
`track_progress is only supported for events: ${validEvents.join(", ")}. ` +
94106
`Current event: ${context.eventName}`,
95107
);
96108
}

src/modes/tag/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export const tagMode: Mode = {
122122
claudeCommentId: commentId.toString(),
123123
allowedTools: [],
124124
context,
125+
mode: "tag",
125126
});
126127

127128
// Don't output mcp_config separately anymore - include in claude_args

test/install-mcp-server.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ describe("prepareMcpConfig", () => {
8585
baseBranch: "main",
8686
allowedTools: [],
8787
context: mockContext,
88+
mode: "tag",
8889
});
8990

9091
const parsed = JSON.parse(result);
@@ -106,6 +107,7 @@ describe("prepareMcpConfig", () => {
106107
baseBranch: "main",
107108
allowedTools: [],
108109
context: mockContextWithSigning,
110+
mode: "tag",
109111
});
110112

111113
const parsed = JSON.parse(result);
@@ -129,6 +131,7 @@ describe("prepareMcpConfig", () => {
129131
baseBranch: "main",
130132
allowedTools: ["mcp__github__create_issue", "mcp__github__create_pr"],
131133
context: mockContext,
134+
mode: "tag",
132135
});
133136

134137
const parsed = JSON.parse(result);
@@ -149,6 +152,7 @@ describe("prepareMcpConfig", () => {
149152
baseBranch: "main",
150153
allowedTools: ["mcp__github_inline_comment__create_inline_comment"],
151154
context: mockPRContext,
155+
mode: "tag",
152156
});
153157

154158
const parsed = JSON.parse(result);
@@ -169,6 +173,7 @@ describe("prepareMcpConfig", () => {
169173
baseBranch: "main",
170174
allowedTools: [],
171175
context: mockContext,
176+
mode: "tag",
172177
});
173178

174179
const parsed = JSON.parse(result);
@@ -189,6 +194,7 @@ describe("prepareMcpConfig", () => {
189194
baseBranch: "main",
190195
allowedTools: [],
191196
context: mockContextWithSigning,
197+
mode: "tag",
192198
});
193199

194200
const parsed = JSON.parse(result);
@@ -208,6 +214,7 @@ describe("prepareMcpConfig", () => {
208214
baseBranch: "main",
209215
allowedTools: [],
210216
context: mockContextWithSigning,
217+
mode: "tag",
211218
});
212219

213220
const parsed = JSON.parse(result);
@@ -225,6 +232,7 @@ describe("prepareMcpConfig", () => {
225232
baseBranch: "main",
226233
allowedTools: [],
227234
context: mockPRContext,
235+
mode: "tag",
228236
});
229237

230238
const parsed = JSON.parse(result);
@@ -244,6 +252,7 @@ describe("prepareMcpConfig", () => {
244252
baseBranch: "main",
245253
allowedTools: [],
246254
context: mockContext,
255+
mode: "tag",
247256
});
248257

249258
const parsed = JSON.parse(result);
@@ -261,6 +270,7 @@ describe("prepareMcpConfig", () => {
261270
baseBranch: "main",
262271
allowedTools: [],
263272
context: mockPRContext,
273+
mode: "tag",
264274
});
265275

266276
const parsed = JSON.parse(result);

test/modes/agent.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ describe("Agent Mode", () => {
162162
githubToken: "test-token",
163163
});
164164

165-
// Verify claude_args includes MCP config and user args
165+
// Verify claude_args includes user args (no MCP config in agent mode without allowed tools)
166166
const callArgs = setOutputSpy.mock.calls[0];
167167
expect(callArgs[0]).toBe("claude_args");
168-
expect(callArgs[1]).toContain("--mcp-config");
169-
expect(callArgs[1]).toContain("--model claude-sonnet-4 --max-turns 10");
168+
expect(callArgs[1]).toBe("--model claude-sonnet-4 --max-turns 10");
169+
expect(callArgs[1]).not.toContain("--mcp-config");
170170

171171
// Verify return structure - should use "main" as fallback when no env vars set
172172
expect(result).toEqual({

tests/modes/detector.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ describe("detectMode with enhanced routing", () => {
200200
};
201201

202202
expect(() => detectMode(context)).toThrow(
203-
/track_progress is only supported for pull_request and issue events/,
203+
/track_progress is only supported /,
204204
);
205205
});
206206

0 commit comments

Comments
 (0)