Skip to content

refactor: Make prompt and resource services protocol-neutral - #1150

Merged
jirispilka merged 4 commits into
masterfrom
claude/protocol-neutral-services-afh68p
Jul 24, 2026
Merged

refactor: Make prompt and resource services protocol-neutral#1150
jirispilka merged 4 commits into
masterfrom
claude/protocol-neutral-services-afh68p

Conversation

@jirispilka

Copy link
Copy Markdown
Collaborator

Why

Closes #1146. Part of #1128.

The prompt and resource services were welded to the v1 MCP SDK: resource_service.ts and api_resources.ts threw McpError, and prompt list/get lived private inside ActorsMcpServer and threw McpError too. The 2026-07-28 stateless-server spike (#1143) therefore had to duplicate the prompt handlers verbatim and hand-translate v1 errors into v2 ProtocolError — the wrong dependency direction. This is the second protocol-neutral prerequisite after #1145 (client context; this PR is stacked on refactor/client-context).

What changed

The services stop knowing about any protocol error class. They throw plain domain errors (InvalidParamsError / InternalError, new src/mcp/errors.ts, zero SDK imports) and return plain MCP-shaped data. A single seam — toMcpError in server.ts — projects each domain error 1:1 back to McpError in the resources/read and prompts/get handler bodies, copying message and data unchanged, so the wire output (code, message, presence of data) is byte-identical. Prompt list/get moved into createPromptService(prompts), mirroring the existing createResourceService factory. api_resources.ts's existing 3xx/4xx-except-429 vs 429/5xx/network-drop split now selects the domain-error class instead of an ErrorCode.

No public/./internals surface change, no v2 SDK dependency. A future v2 adapter reuses the same services with its own ProtocolError projection.

Base: stacked on refactor/client-context (#1145 work, not yet merged). Retarget to master once that lands.

Follow-up: #1149 (live mcpc smoke test for the prompts/get success/invalid-args paths — test-infra, empty prompt registry blocks it today; unit-covered).

Notes for reviewers (human-written)

Proof it works

  • Unit: added tests/unit/prompts.service.test.ts (list / render / unknown-name / invalid-args, isolated from ActorsMcpServer); added an InternalError-class case at the resource-service layer and one through the real resources/read handler asserting -32603 is 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.
  • Live mcpc probe (stdio + HTTP): resources/read of file://missing.md, https://example.com/x, and a real 404 dataset all return JSON-RPC -32602 with data:{uri}; a successful dataset read still returns normal content; resources/list / resources/templates/list / prompts/list unchanged; prompts/get unknown-name returns -32602 naming the available prompts; tools/list, ping, search-actors, call-actor all work post-refactor.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SiMgojbYtbycioTzKyeV4R


Generated by Claude Code

jirispilka and others added 3 commits July 23, 2026 23:11
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

This comment was marked as low quality.

@MQ37 MQ37 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Base automatically changed from refactor/client-context to master July 24, 2026 09:11
# Conflicts:
#	src/dev_server.ts
#	src/mcp/AGENTS.md
#	src/mcp/client_context.ts
#	src/mcp/server.ts
@github-actions github-actions Bot added t-ai Issues owned by the AI team. tested Temporary label used only programatically for some analytics. labels Jul 24, 2026
@jirispilka
jirispilka merged commit 646fce8 into master Jul 24, 2026
15 checks passed
@jirispilka
jirispilka deleted the claude/protocol-neutral-services-afh68p branch July 24, 2026 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-ai Issues owned by the AI team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: Make prompt and resource services protocol-neutral

5 participants