fix(mcp): return structured error responses when tool handlers throw#11
Draft
fix(mcp): return structured error responses when tool handlers throw#11
Conversation
…esponses Co-authored-by: connortessaro <116526628+connortessaro@users.noreply.github.com> Agent-Logs-Url: https://github.com/connortessaro/shopify-web-replicator/sessions/dc37d7b8-17c9-436f-b649-c9be7676151c
Copilot
AI
changed the title
[WIP] Run full check for code runnable status and explore issues
fix(mcp): return structured error responses when tool handlers throw
Mar 26, 2026
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.
When tool handlers threw (e.g.,
RuntimePreflightErrorfrom a failed preflight like missing Shopify CLI), the MCP SDK's internalcreateToolErrorwas called — which returns{ isError: true }with nostructuredContent. The stdio smoke test expectsstructuredContent.errorto always be defined whenisErroristrue, causing aTypeErrorcrash.Summary
toToolError(error)helper inserver.tsthat converts any thrown exception into a proper structured result:replicate_site_to_theme,replicate_site_to_hydrogen,get_replication_job,list_replication_jobs) intry/catchusing this helper —list_destination_storesis synchronous and not at risklist_destination_storesis unaffected (no preflight, no async throws)server.test.ts: "returns a structured runtime preflight error when replication cannot start" → "re-throws runtime preflight errors from the orchestrator without wrapping" — the test exercises the handler layer, not the server wrapperVerification
pnpm buildpnpm testpnpm typecheckpnpm theme:checkRisk
No API or contract changes. Error structure (
structuredContent.error.code) is new surface area on the failure path only — previously clients received undefined structured content on throw, which was a bug.Original prompt
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.