Skip to content

feat(mcp): implement sampling/createMessage capability - #207

Merged
im10furry merged 2 commits into
mainfrom
feat/mcp-sampling
Jul 25, 2026
Merged

feat(mcp): implement sampling/createMessage capability#207
im10furry merged 2 commits into
mainfrom
feat/mcp-sampling

Conversation

@im10furry

Copy link
Copy Markdown
Contributor

Summary

Implement MCP sampling capability, allowing MCP servers to request LLM completions through the client via the sampling/createMessage protocol method.

Changes

  • Add sampling.ts with CreateMessage request handler routing through queryLLM for multi-provider LLM support
  • Declare sampling capability in getMcpClientCapabilities() so MCP servers know the client supports sampling
  • Register/unregister sampling handler in MCP client lifecycle (createMcpClient / closeMcpClient)
  • Convert between MCP SamplingMessage and internal Anthropic message format
  • Resolve model from server's modelPreferences hints (speed→quick, intelligence→main)
  • Map stop_reason between internal (end_turn) and MCP spec (endTurn) formats
  • Export sampling control APIs (isMcpSamplingEnabled, setMcpSamplingEnabled) and test helpers
  • Update capability tests for sampling enabled/disabled states

Design Decisions

  • Uses quick model pointer by default for fast, low-cost sampling responses
  • Supports modelPreferences.hints to match against configured models
  • Sampling is enabled by default; can be disabled via setMcpSamplingEnabled(false)
  • Basic text content support (images pass through as base64)

- Add sampling.ts with CreateMessage request handler that routes
  through queryLLM for multi-provider LLM support
- Declare sampling capability in getMcpClientCapabilities() so
  MCP servers know the client supports sampling
- Register/unregister sampling handler in client lifecycle
- Convert between MCP SamplingMessage and internal Anthropic format
- Resolve model from server's modelPreferences hints
- Map stop_reason between internal and MCP spec formats
- Export sampling control APIs (enable/disable/test helpers)
- Update capability tests for sampling enabled/disabled states
@im10furry
im10furry merged commit 48f4f7a into main Jul 25, 2026
1 of 4 checks passed
@im10furry
im10furry deleted the feat/mcp-sampling branch July 25, 2026 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant