Skip to content

feat(tools): add MCP sampling support for server-initiated LLM requests#69

Merged
Tuanzi1015 merged 1 commit into
MLT-OSS:mainfrom
lml2468:feat/tools-mcp-sampling
Apr 11, 2026
Merged

feat(tools): add MCP sampling support for server-initiated LLM requests#69
Tuanzi1015 merged 1 commit into
MLT-OSS:mainfrom
lml2468:feat/tools-mcp-sampling

Conversation

@lml2468
Copy link
Copy Markdown
Contributor

@lml2468 lml2468 commented Apr 11, 2026

What does this PR do?

Add MCP sampling capability so MCP servers can initiate LLM requests through the agent. This enables sophisticated MCP servers that need LLM completion capabilities (e.g., for agentic workflows within server tools).

Related Issue

Fixes #56

Type of Change

  • ✨ New feature (non-breaking change that adds functionality)

Changes Made

File Change
internal/tools/mcp_sampling.go New: SamplingHandler, message conversion, rate limiting, loop prevention
internal/tools/mcp_sampling_test.go New: tests for conversion, rate limiting, loop depth
internal/tools/mcp.go Advertise sampling capability, wire handler into stdio transport
internal/tools/mcp_sse.go Wire sampling handler into SSE transport

How to Test

  1. Build: go build -o hermes ./cmd/hermes/
  2. Run tests: go test ./internal/tools/ -v -run Sampling

Build & Test Verification

  • go build ./cmd/hermes/ — compiles without errors
  • go test ./... — all tests pass
  • go vet ./... — no issues
  • New code has test coverage
  • Commit messages follow Conventional Commits

- Advertise sampling capability in MCP initialize request
- Create SamplingHandler for sampling/createMessage requests
- Add per-server RPM rate limiting and loop depth prevention
- Implement MCP ↔ LLM message format conversion
- Wire sampling into both stdio and SSE transports
- Extract shared request parsing to eliminate duplication
- Comprehensive tests for conversion, rate limiting, and loop depth

Fixes MLT-OSS#56
@Tuanzi1015 Tuanzi1015 merged commit 0402e2f into MLT-OSS:main Apr 11, 2026
7 of 8 checks passed
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.

[Feature]: MCP sampling support for server-initiated LLM requests

3 participants