Skip to content

Commit dcbe295

Browse files
authored
fix(mcp): disable MCP_SKILLS feature flag — source not mirrored (Gitlawb#872)
Closes Gitlawb#856. MCP servers that expose resources (e.g. RepoPrompt) failed to load their tools in the open build with: Error fetching tools/commands/resources: fetchMcpSkillsForClient is not a function Root cause: scripts/build.ts set MCP_SKILLS: true, which made feature('MCP_SKILLS') evaluate to true at build time. The guards around the dynamic skill discovery path therefore stayed live. The underlying source file src/skills/mcpSkills.ts is not mirrored into the open tree, so the bundler fell back to its generic missing-module stub — which only exports `default` for require()-style imports, not the named `fetchMcpSkillsForClient` binding. At runtime the require returned an object without that property, and calling it threw. `openclaude mcp doctor` reported RepoPrompt as healthy because doctor does not exercise the skills-fetch path. Fix: flip MCP_SKILLS to false and move it into the "Disabled: missing source" group. With the flag off, every `if (feature('MCP_SKILLS'))` guard becomes a no-op at build time, the require() branch is dead code, and MCP servers with resources load normally via the existing `Promise.resolve([])` fallbacks already present at each call site. Also adds scripts/feature-flags-source-guard.test.ts to fail fast if MCP_SKILLS (or any future flag in the same category) is re-enabled without the corresponding source file being mirrored first. Verification: - Test fails on main, passes with this fix - `bun run build` produces a bundle with no `missing-module-stub:../../skills/mcpSkills.js` reference - Full `bun test` — 1222 pass / 12 fail (same pre-existing 12 as main; new test adds the +1 pass)
1 parent a4c6757 commit dcbe295

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

scripts/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const featureFlags: Record<string, boolean> = {
3434
WEB_BROWSER_TOOL: false, // Built-in browser automation (source not mirrored)
3535
CHICAGO_MCP: false, // Computer-use MCP (native Swift modules stubbed)
3636
COWORKER_TYPE_TELEMETRY: false, // Telemetry for agent/coworker type classification
37+
MCP_SKILLS: false, // Dynamic MCP skill discovery (src/skills/mcpSkills.ts not mirrored; enabling this causes "fetchMcpSkillsForClient is not a function" when MCP servers with resources connect — see #856)
3738

3839
// ── Enabled: upstream defaults ──────────────────────────────────────
3940
COORDINATOR_MODE: true, // Multi-agent coordinator with worker delegation
@@ -56,7 +57,6 @@ const featureFlags: Record<string, boolean> = {
5657
EXTRACT_MEMORIES: true, // Auto-extract durable memories from conversations
5758
FORK_SUBAGENT: true, // Implicit context-forking when omitting subagent_type
5859
VERIFICATION_AGENT: true, // Built-in read-only agent for test/verification
59-
MCP_SKILLS: true, // Discover skills dynamically from MCP server resources
6060
PROMPT_CACHE_BREAK_DETECTION: true, // Detect & log unexpected prompt cache invalidations
6161
HOOK_PROMPTS: true, // Allow tools to request interactive user prompts
6262
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { existsSync, readFileSync } from 'fs'
2+
import { join } from 'path'
3+
import { expect, test } from 'bun:test'
4+
5+
// Regression guard for #856. Several build feature flags require source files
6+
// that are not mirrored into the open build. When such a flag is set to `true`
7+
// without the source present, the bundler falls back to a missing-module stub
8+
// that only exports `default`, which causes runtime errors like
9+
// `fetchMcpSkillsForClient is not a function` when downstream code reaches
10+
// through the `require()` to a named export.
11+
//
12+
// This test fails fast at test-time if someone re-enables one of these flags
13+
// without first mirroring the corresponding source file.
14+
15+
const BUILD_SCRIPT = join(import.meta.dir, 'build.ts')
16+
const REPO_ROOT = join(import.meta.dir, '..')
17+
18+
type FlagGuard = {
19+
flag: string
20+
source: string // path relative to repo root
21+
}
22+
23+
const FLAG_REQUIRES_SOURCE: FlagGuard[] = [
24+
{ flag: 'MCP_SKILLS', source: 'src/skills/mcpSkills.ts' },
25+
]
26+
27+
test('build feature flags are not enabled without their source files', () => {
28+
const buildScript = readFileSync(BUILD_SCRIPT, 'utf-8')
29+
30+
for (const { flag, source } of FLAG_REQUIRES_SOURCE) {
31+
const enabledRe = new RegExp(`^\\s*${flag}\\s*:\\s*true\\b`, 'm')
32+
const isEnabled = enabledRe.test(buildScript)
33+
const sourceExists = existsSync(join(REPO_ROOT, source))
34+
35+
if (isEnabled && !sourceExists) {
36+
throw new Error(
37+
`Feature flag ${flag} is enabled in scripts/build.ts, but its required source file "${source}" does not exist. ` +
38+
`Enabling this flag without the source will cause runtime errors (missing named exports from the missing-module stub). ` +
39+
`Either mirror the source file or set ${flag}: false.`,
40+
)
41+
}
42+
43+
// When the source IS present, the flag can be either true or false; either
44+
// is fine. We only care about the "enabled but missing" combination.
45+
expect(true).toBe(true)
46+
}
47+
})

0 commit comments

Comments
 (0)