fix: prevent _buildNativeTools crash when MCP tools are in toolImplementations#470
fix: prevent _buildNativeTools crash when MCP tools are in toolImplementations#470
Conversation
…entations (#469) After initializeMCP() merges MCP tools into toolImplementations, _buildNativeTools iterates all entries and calls _getToolSchemaAndDescription which returns null for MCP tools. Destructuring null throws a TypeError. Fix: check for null return before destructuring. MCP tools in toolImplementations are safely skipped since they're already handled separately via mcpBridge.getVercelTools(). Closes #469 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
PR Overview: Fix
|
| File | Status | Additions | Deletions |
|---|---|---|---|
npm/src/agent/ProbeAgent.js |
Modified | 5 | 1 |
npm/tests/unit/mcp-message-history.test.js |
Modified | 53 | 0 |
Total: 58 additions, 1 deletion across 2 files.
Architecture & Impact Assessment
What This PR Accomplishes
- Prevents a runtime crash when
_buildNativeTools()iterates overtoolImplementationscontaining MCP tools - MCP tools (with names like
__tools___slack-send-dm) are merged intotoolImplementationsduringinitializeMCP()but have no schema available via_getToolSchemaAndDescription()
Root Cause
The crash occurred because:
- After
initializeMCP(), MCP tools are merged intothis.toolImplementations(line ~714) _buildNativeTools()iterates ALL entries intoolImplementations(line ~1839)_getToolSchemaAndDescription(toolName)returnsnullfor MCP tool names- The destructuring
const { schema, description } = nullthrowsTypeErrorbefore theif (schema && description)guard can execute
Key Technical Change
// Before (crashes):
const { schema, description } = this._getToolSchemaAndDescription(toolName);
// After (safe):
const toolInfo = this._getToolSchemaAndDescription(toolName);
if (!toolInfo) continue;
const { schema, description } = toolInfo;MCP tools are correctly handled separately via mcpBridge.getVercelTools() later in the same method, so skipping them in the toolImplementations loop is the correct behavior.
Affected System Components
flowchart TD
A[initializeMCP] -->|merges MCP tools| B[toolImplementations]
B -->|iterates all entries| C[_buildNativeTools]
C -->|calls| D[_getToolSchemaAndDescription]
D -->|returns null for MCP tools| E{null check}
E -->|skip| F[Continue loop]
C -->|later| G[mcpBridge.getVercelTools]
G -->|provides| H[MCP tools in Vercel format]
Scope Discovery & Context Expansion
Related Code Paths
ProbeAgent.initialize()(~line 704-724): Merges MCP tools intotoolImplementationsProbeAgent.getSystemMessage()(~line 2916-2922): Also merges MCP tools (lazy init path)ProbeAgent._buildNativeTools()(~line 1637-1947): The fixed methodmcpBridge.getVercelTools(): Provides properly formatted MCP tools
Test Coverage
- 2 new regression tests in
mcp-message-history.test.js:- Single MCP tool in
toolImplementations(reproduces exact crash scenario) - Multiple MCP tools in
toolImplementations
- Single MCP tool in
- All 106 test suites pass (2621 tests)
Potential Related Areas to Verify
- DSL runtime MCP integration (
npm/src/agent/dsl/) createExecutePlanToolMCP handling (npm/src/tools/executePlan.js)- MCP bridge implementations (
npm/src/agent/mcp/)
Labels
tags.review-effort: 1 (trivial - single null check fix with clear tests)tags.label: bug
Metadata
- Review Effort: 1 / 5
- Primary Label: bug
Powered by Visor from Probelabs
Last updated: 2026-03-03T21:29:24.669Z | Triggered by: pr_opened | Commit: 5706d02
💡 TIP: You can chat with Visor using /visor ask <your question>
✅ Security Check PassedNo security issues found – changes LGTM. ✅ Architecture Check PassedNo architecture issues found – changes LGTM. ✅ Security Check PassedNo security issues found – changes LGTM. \n\n✅ Architecture Check PassedNo architecture issues found – changes LGTM. \n\n✅ Performance Check PassedNo performance issues found – changes LGTM. Powered by Visor from Probelabs Last updated: 2026-03-03T21:22:53.910Z | Triggered by: pr_opened | Commit: 5706d02 💡 TIP: You can chat with Visor using |
Summary
TypeError: Cannot destructure property 'schema' of nullwhen MCP tools are present intoolImplementations_getToolSchemaAndDescription()return valuetoolImplementationsCloses #469
Root cause
After
initializeMCP(), MCP tools get merged intothis.toolImplementations. When_buildNativeTools()iterates all entries, it calls_getToolSchemaAndDescription(toolName)which returnsnullfor MCP tool names (e.g.__tools___slack-send-dm). The destructuringconst { schema, description } = nullthrows a TypeError before theif (schema && description)guard can execute.Fix
MCP tools are already handled separately via
mcpBridge.getVercelTools()further down in the same method, so skipping them in thetoolImplementationsloop is correct.Test plan
mcp-message-history.test.jsreproducing the exact crash scenario🤖 Generated with Claude Code