refactor: Make prompt and resource services protocol-neutral - #1150
Merged
Conversation
The prompt and resource services threw the v1 SDK McpError, forcing the 2026-07-28 stateless server spike (#1143) to duplicate prompt handling and hand-translate errors. They now throw plain domain errors (InvalidParamsError and InternalError); a single toMcpError seam in server.ts projects them to McpError at the legacy resources/read and prompts/get handler boundary, so the wire output stays byte-identical. A future v2 adapter reuses the same services with its own projection. Closes #1146 Part of #1128 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SiMgojbYtbycioTzKyeV4R
# Conflicts: # src/dev_server.ts # src/mcp/AGENTS.md # src/mcp/client_context.ts # src/mcp/server.ts
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.
Why
Closes #1146. Part of #1128.
The prompt and resource services were welded to the v1 MCP SDK:
resource_service.tsandapi_resources.tsthrewMcpError, and prompt list/get lived private insideActorsMcpServerand threwMcpErrortoo. The 2026-07-28 stateless-server spike (#1143) therefore had to duplicate the prompt handlers verbatim and hand-translate v1 errors into v2ProtocolError— the wrong dependency direction. This is the second protocol-neutral prerequisite after #1145 (client context; this PR is stacked onrefactor/client-context).What changed
The services stop knowing about any protocol error class. They throw plain domain errors (
InvalidParamsError/InternalError, newsrc/mcp/errors.ts, zero SDK imports) and return plain MCP-shaped data. A single seam —toMcpErrorinserver.ts— projects each domain error 1:1 back toMcpErrorin theresources/readandprompts/gethandler bodies, copyingmessageanddataunchanged, so the wire output (code, message, presence ofdata) is byte-identical. Prompt list/get moved intocreatePromptService(prompts), mirroring the existingcreateResourceServicefactory.api_resources.ts's existing 3xx/4xx-except-429 vs 429/5xx/network-drop split now selects the domain-error class instead of anErrorCode.No public/
./internalssurface change, no v2 SDK dependency. A future v2 adapter reuses the same services with its ownProtocolErrorprojection.Base: stacked on
refactor/client-context(#1145 work, not yet merged). Retarget tomasteronce that lands.Follow-up: #1149 (live mcpc smoke test for the
prompts/getsuccess/invalid-args paths — test-infra, empty prompt registry blocks it today; unit-covered).Notes for reviewers (human-written)
Proof it works
tests/unit/prompts.service.test.ts(list / render / unknown-name / invalid-args, isolated fromActorsMcpServer); added anInternalError-class case at the resource-service layer and one through the realresources/readhandler asserting-32603is not downgraded to-32602; existing resource assertions swapped 1:1 to the domain classes with no scenario loss.pnpm run test:unit— 1179 passed / 1 skipped.resources/readoffile://missing.md,https://example.com/x, and a real 404 dataset all return JSON-RPC-32602withdata:{uri}; a successful dataset read still returns normal content;resources/list/resources/templates/list/prompts/listunchanged;prompts/getunknown-name returns-32602naming the available prompts;tools/list,ping,search-actors,call-actorall work post-refactor.🤖 Generated with Claude Code
https://claude.ai/code/session_01SiMgojbYtbycioTzKyeV4R
Generated by Claude Code