Commit fb5185f
fix(mcp): resolve MCP tool name prefix misalignment across all subagents
## Issue
The securities-researcher subagent hung for 57 minutes because it called
`mcp__sec__search_sec_filings` — a tool that does not exist at runtime.
Root cause: `MCP_FALLBACK_INSTRUCTIONS` (injected into 20 research agents)
taught agents to construct tool names as `mcp__<domain>__<tool>` (scoped
prefix). But with `SCOPED_MCP_SERVERS=false` (production default), all
tools are registered under the monolithic server as
`mcp__super-legal-tools__<tool>`. Agents called nonexistent tools, silently
failed, then fell back to raw WebFetch — bypassing the hybrid client's
automatic Exa fallback entirely. SEC's aggressive 403-blocking made this
visible; other agents survived only because their targets don't block
scrapers.
Scope: 147 tools across 29 domains were implicitly misaligned via the
prefix instruction. 12 explicit hardcoded wrong-prefix references existed
across 2 agent files. 1 inverse mismatch existed in risk-aggregator.js.
A related isError gap in the CodeExecBridge adapter masked failures.
## Remediation (6 edits across 5 files)
1. **mcpToolRef() utility** (`domainMcpServers.js`): Single source of
truth for constructing MCP tool names in either server mode. Returns
`mcp__super-legal-tools__<tool>` when SCOPED=false, or
`mcp__<domain>__<tool>` when SCOPED=true.
2. **MCP_PREFIX_INSTRUCTION** (`_promptConstants.js`): Flag-aware prefix
instruction interpolated into MCP_FALLBACK_INSTRUCTIONS. Fixes all 20
research agents in a single edit: securities-researcher, patent-analyst,
pharma-regulatory-analyst, case-law-analyst, antitrust-competition-analyst,
environmental-compliance-analyst, statutory-law-analyst, tax-structure-analyst,
regulatory-rulemaking-analyst, privacy-data-protection-analyst,
employment-labor-analyst, cybersecurity-compliance-analyst,
insurance-coverage-analyst, ai-governance-analyst, financial-analyst,
government-contracts-researcher, data-analyst, product-safety-analyst,
cfius-national-security-analyst, commercial-contracts-analyst.
3. **Legacy MCP_FALLBACK_INSTRUCTIONS** (`legalSubagents.js`): Same fix
for the MODULAR_SUBAGENTS=false code path (dead code in production,
fixed for correctness).
4. **citation-websearch-verifier.js**: Replaced 10 hardcoded
mcp__courtlistener__ / mcp__sec__ references with mcpToolRef() calls.
5. **risk-aggregator.js**: Fixed inverse bug — was hardcoding
mcp__super-legal-tools__run_python_analysis (only correct when
SCOPED=false) instead of using mcpToolRef().
6. **agentSdkToolAdapter.js**: Added `isError: true` when
runPythonAnalysis returns `{success: false}` without throwing, so
hooks/server properly report it as a failed tool call.
## Verification
- 28/28 domain MCP server tests pass (no import breakage)
- mcpToolRef('sec', 'search_sec_filings') → mcp__super-legal-tools__search_sec_filings (production)
- MCP_FALLBACK_INSTRUCTIONS prefix → "prefixed with mcp__super-legal-tools__" (production)
- Zero hardcoded wrong-prefix refs remaining in src/
- Full audit: 41/41 agent files clean, no circular dependency risk
- Live diagnostic test confirmed SEC hybrid fallback pipeline functions correctly
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent 6c15bcc commit fb5185f
6 files changed
Lines changed: 41 additions & 14 deletions
File tree
- super-legal-mcp-refactored/src
- config
- legalSubagents
- agents
- utils
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
335 | 336 | | |
336 | 337 | | |
337 | 338 | | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
892 | 892 | | |
893 | 893 | | |
894 | 894 | | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
895 | 899 | | |
896 | 900 | | |
897 | 901 | | |
| |||
923 | 927 | | |
924 | 928 | | |
925 | 929 | | |
926 | | - | |
| 930 | + | |
927 | 931 | | |
928 | 932 | | |
929 | 933 | | |
| |||
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
640 | 640 | | |
641 | 641 | | |
642 | 642 | | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
643 | 647 | | |
644 | 648 | | |
645 | 649 | | |
| |||
671 | 675 | | |
672 | 676 | | |
673 | 677 | | |
674 | | - | |
| 678 | + | |
675 | 679 | | |
676 | 680 | | |
677 | 681 | | |
| |||
Lines changed: 11 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
72 | | - | |
| 73 | + | |
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
79 | | - | |
| 80 | + | |
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
| |||
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
88 | | - | |
| 89 | + | |
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
| |||
134 | 135 | | |
135 | 136 | | |
136 | 137 | | |
137 | | - | |
| 138 | + | |
138 | 139 | | |
139 | 140 | | |
140 | 141 | | |
| |||
189 | 190 | | |
190 | 191 | | |
191 | 192 | | |
192 | | - | |
| 193 | + | |
193 | 194 | | |
194 | 195 | | |
195 | 196 | | |
196 | 197 | | |
197 | 198 | | |
198 | 199 | | |
199 | 200 | | |
200 | | - | |
| 201 | + | |
201 | 202 | | |
202 | 203 | | |
203 | 204 | | |
| |||
206 | 207 | | |
207 | 208 | | |
208 | 209 | | |
209 | | - | |
| 210 | + | |
210 | 211 | | |
211 | 212 | | |
212 | 213 | | |
| |||
259 | 260 | | |
260 | 261 | | |
261 | 262 | | |
262 | | - | |
| 263 | + | |
263 | 264 | | |
264 | 265 | | |
265 | 266 | | |
| |||
651 | 652 | | |
652 | 653 | | |
653 | 654 | | |
654 | | - | |
655 | | - | |
| 655 | + | |
| 656 | + | |
656 | 657 | | |
657 | 658 | | |
658 | 659 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
530 | 531 | | |
531 | 532 | | |
532 | 533 | | |
533 | | - | |
| 534 | + | |
534 | 535 | | |
535 | 536 | | |
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
238 | | - | |
| 238 | + | |
| 239 | + | |
239 | 240 | | |
240 | 241 | | |
241 | 242 | | |
| |||
0 commit comments