Skip to content

Commit 2e92922

Browse files
authored
fix(tag): no such tool available mcp__github_* (#556)
Signed-off-by: Kevin Cui <bh@bugs.cc> # Conflicts: # src/mcp/install-mcp-server.ts # src/modes/tag/index.ts # test/modes/agent.test.ts
1 parent a5528ee commit 2e92922

File tree

4 files changed

+36
-27
lines changed

4 files changed

+36
-27
lines changed

src/mcp/install-mcp-server.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { GITHUB_API_URL, GITHUB_SERVER_URL } from "../github/api/config";
33
import type { GitHubContext } from "../github/context";
44
import { isEntityContext } from "../github/context";
55
import { Octokit } from "@octokit/rest";
6+
import type { AutoDetectedMode } from "../modes/detector";
67

78
type PrepareConfigParams = {
89
githubToken: string;
@@ -12,8 +13,8 @@ type PrepareConfigParams = {
1213
baseBranch: string;
1314
claudeCommentId?: string;
1415
allowedTools: string[];
16+
mode: AutoDetectedMode;
1517
context: GitHubContext;
16-
mode: "tag" | "agent";
1718
};
1819

1920
async function checkActionsReadPermission(
@@ -65,8 +66,13 @@ export async function prepareMcpConfig(
6566
try {
6667
const allowedToolsList = allowedTools || [];
6768

69+
// Detect if we're in agent mode (explicit prompt provided)
6870
const isAgentMode = mode === "agent";
6971

72+
const hasGitHubCommentTools = allowedToolsList.some((tool) =>
73+
tool.startsWith("mcp__github_comment__"),
74+
);
75+
7076
const hasGitHubMcpTools = allowedToolsList.some((tool) =>
7177
tool.startsWith("mcp__github__"),
7278
);
@@ -86,7 +92,7 @@ export async function prepareMcpConfig(
8692
// Include comment server:
8793
// - Always in tag mode (for updating Claude comments)
8894
// - Only with explicit tools in agent mode
89-
const shouldIncludeCommentServer = !isAgentMode;
95+
const shouldIncludeCommentServer = !isAgentMode || hasGitHubCommentTools;
9096

9197
if (shouldIncludeCommentServer) {
9298
baseMcpConfig.mcpServers.github_comment = {

src/modes/agent/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ export const agentMode: Mode = {
135135
baseBranch: baseBranch,
136136
claudeCommentId: undefined, // No tracking comment in agent mode
137137
allowedTools,
138-
context,
139138
mode: "agent",
139+
context,
140140
});
141141

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

src/modes/tag/index.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { createPrompt, generateDefaultPrompt } from "../../create-prompt";
1414
import { isEntityContext } from "../../github/context";
1515
import type { PreparedContext } from "../../create-prompt/types";
1616
import type { FetchDataResult } from "../../github/data/fetcher";
17+
import { parseAllowedTools } from "../agent/parse-tools";
1718

1819
/**
1920
* Tag mode implementation.
@@ -112,20 +113,10 @@ export const tagMode: Mode = {
112113

113114
await createPrompt(tagMode, modeContext, githubData, context);
114115

115-
// Get our GitHub MCP servers configuration
116-
const ourMcpConfig = await prepareMcpConfig({
117-
githubToken,
118-
owner: context.repository.owner,
119-
repo: context.repository.repo,
120-
branch: branchInfo.claudeBranch || branchInfo.currentBranch,
121-
baseBranch: branchInfo.baseBranch,
122-
claudeCommentId: commentId.toString(),
123-
allowedTools: [],
124-
context,
125-
mode: "tag",
126-
});
127-
128-
// Don't output mcp_config separately anymore - include in claude_args
116+
const userClaudeArgs = process.env.CLAUDE_ARGS || "";
117+
const userAllowedMCPTools = parseAllowedTools(userClaudeArgs).filter(
118+
(tool) => tool.startsWith("mcp__github_"),
119+
);
129120

130121
// Build claude_args for tag mode with required tools
131122
// Tag mode REQUIRES these tools to function properly
@@ -141,6 +132,7 @@ export const tagMode: Mode = {
141132
"mcp__github_ci__get_ci_status",
142133
"mcp__github_ci__get_workflow_run_details",
143134
"mcp__github_ci__download_job_log",
135+
...userAllowedMCPTools,
144136
];
145137

146138
// Add git commands when not using commit signing
@@ -162,7 +154,18 @@ export const tagMode: Mode = {
162154
);
163155
}
164156

165-
const userClaudeArgs = process.env.CLAUDE_ARGS || "";
157+
// Get our GitHub MCP servers configuration
158+
const ourMcpConfig = await prepareMcpConfig({
159+
githubToken,
160+
owner: context.repository.owner,
161+
repo: context.repository.repo,
162+
branch: branchInfo.claudeBranch || branchInfo.currentBranch,
163+
baseBranch: branchInfo.baseBranch,
164+
claudeCommentId: commentId.toString(),
165+
allowedTools: Array.from(new Set(tagModeTools)),
166+
mode: "tag",
167+
context,
168+
});
166169

167170
// Build complete claude_args with multiple --mcp-config flags
168171
let claudeArgs = "";

test/install-mcp-server.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ describe("prepareMcpConfig", () => {
106106
branch: "test-branch",
107107
baseBranch: "main",
108108
allowedTools: [],
109-
context: mockContextWithSigning,
110109
mode: "tag",
110+
context: mockContextWithSigning,
111111
});
112112

113113
const parsed = JSON.parse(result);
@@ -130,8 +130,8 @@ describe("prepareMcpConfig", () => {
130130
branch: "test-branch",
131131
baseBranch: "main",
132132
allowedTools: ["mcp__github__create_issue", "mcp__github__create_pr"],
133-
context: mockContext,
134133
mode: "tag",
134+
context: mockContext,
135135
});
136136

137137
const parsed = JSON.parse(result);
@@ -151,8 +151,8 @@ describe("prepareMcpConfig", () => {
151151
branch: "test-branch",
152152
baseBranch: "main",
153153
allowedTools: ["mcp__github_inline_comment__create_inline_comment"],
154-
context: mockPRContext,
155154
mode: "tag",
155+
context: mockPRContext,
156156
});
157157

158158
const parsed = JSON.parse(result);
@@ -172,8 +172,8 @@ describe("prepareMcpConfig", () => {
172172
branch: "test-branch",
173173
baseBranch: "main",
174174
allowedTools: [],
175-
context: mockContext,
176175
mode: "tag",
176+
context: mockContext,
177177
});
178178

179179
const parsed = JSON.parse(result);
@@ -193,8 +193,8 @@ describe("prepareMcpConfig", () => {
193193
branch: "test-branch",
194194
baseBranch: "main",
195195
allowedTools: [],
196-
context: mockContextWithSigning,
197196
mode: "tag",
197+
context: mockContextWithSigning,
198198
});
199199

200200
const parsed = JSON.parse(result);
@@ -213,8 +213,8 @@ describe("prepareMcpConfig", () => {
213213
branch: "test-branch",
214214
baseBranch: "main",
215215
allowedTools: [],
216-
context: mockContextWithSigning,
217216
mode: "tag",
217+
context: mockContextWithSigning,
218218
});
219219

220220
const parsed = JSON.parse(result);
@@ -231,8 +231,8 @@ describe("prepareMcpConfig", () => {
231231
branch: "test-branch",
232232
baseBranch: "main",
233233
allowedTools: [],
234-
context: mockPRContext,
235234
mode: "tag",
235+
context: mockPRContext,
236236
});
237237

238238
const parsed = JSON.parse(result);
@@ -251,8 +251,8 @@ describe("prepareMcpConfig", () => {
251251
branch: "test-branch",
252252
baseBranch: "main",
253253
allowedTools: [],
254-
context: mockContext,
255254
mode: "tag",
255+
context: mockContext,
256256
});
257257

258258
const parsed = JSON.parse(result);
@@ -269,8 +269,8 @@ describe("prepareMcpConfig", () => {
269269
branch: "test-branch",
270270
baseBranch: "main",
271271
allowedTools: [],
272-
context: mockPRContext,
273272
mode: "tag",
273+
context: mockPRContext,
274274
});
275275

276276
const parsed = JSON.parse(result);

0 commit comments

Comments
 (0)