fix(mcp): use request.params.name in catch block — name is out of scope#1269
Open
memosr wants to merge 1 commit into
Open
fix(mcp): use request.params.name in catch block — name is out of scope#1269memosr wants to merge 1 commit into
memosr wants to merge 1 commit into
Conversation
The error handler at typescript/framework-extensions/model-context-protocol/
README.md:58 referenced \`${name}\` inside a catch block where \`name\` is not
defined. The function uses \`async (request) =>\` and destructures \`name\` from
\`request.params\` only at the top of the try block, so it is not accessible
from the catch.
In a browser, this silently resolves to \`window.name\` (an unrelated string).
In Node.js (where MCP servers actually run), this throws ReferenceError
before the intended error message is constructed.
Changed to \`${request.params.name}\` which is in scope throughout the
handler, matching the access pattern used everywhere else in the file.
🟡 Heimdall Review Status
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A small but real bug in the MCP framework extension's primary onboarding example. Any developer copy-pasting this code hits a ReferenceError (Node.js) or silently uses
window.name(browser) when an error path triggers.The bug
In
typescript/framework-extensions/model-context-protocol/README.md, the example shows:The
namedestructured at the top of the function body lives inside thetryblock's scope (well, technically the function body, but the catch handler can't see destructured bindings that weren't hoisted). The catch block doesn't have a binding forname.In a browser,
namesilently resolves towindow.name— an unrelated string. The error message gets a useless value, not the tool name.In Node.js (where MCP servers actually run), this throws
ReferenceError: name is not definedbefore the intended error message is even constructed.The fix
requestis the handler parameter and is in scope throughout the handler, including the catch block. This matches the access pattern used elsewhere in MCP server code.Why it matters
This is the primary MCP onboarding example. Developers building their first MCP server with AgentKit copy this pattern. A broken error path means hard-to-debug failures the moment any tool throws.
Verification
request.params.nameis verified in scope at the catch site