Skip to content

feat(mcp): MCP Sampling — server-side LLM reasoning via connected client #262

Description

@pgroene

Summary

Enable Kyber's MCP server to use MCP Sampling to delegate LLM reasoning to the connected client (Claude, ChatGPT, Cursor), rather than always calling Kyber's own configured LLM API.

What is MCP Sampling?

The MCP Sampling primitive allows a server to ask the client to perform an LLM completion on its behalf. The client sends the request to its own LLM and returns the result — so the server gets AI reasoning without making an independent LLM API call.

Why it matters for Kyber

Scenario Today With Sampling
Summarize last night's motion events Kyber calls its own LLM Client LLM does it — no extra token cost to Kyber
Anomaly detection on sensor history Requires Kyber-side AI config Server pushes raw data, client reasons about it
Classify intent from ambiguous user input Always through kyber_ask pipeline Server asks client to pre-classify, then routes
Explain a complex automation Kyber LLM prompt Delegated to the already-connected Claude/GPT

Proposed implementation

  • Add /sampling/createMessage\ handler to Kyber's MCP server
  • Expose a \kyber_analyze\ capability that accepts raw HA context + a question and returns the client LLM's reasoning
  • Use sampling for lightweight summarization tasks to reduce Kyber's own LLM call volume
  • Add sampling request/response to the MCP call log debug UI

Acceptance criteria

  • Kyber MCP server correctly sends \sampling/createMessage\ requests per the MCP spec
  • Connected client (Claude Desktop tested) responds and result is used by Kyber
  • Sampling calls appear in the MCP debug call log
  • Feature is gated behind \enable_mcp\ flag / only active when MCP is enabled
  • Works without sampling gracefully (clients that don't support it fall back silently)

Notes

  • Neither HA's MCP nor Kyber currently supports this — implementing it would be a differentiator
  • MCP SDK (\mcp\ package) already has sampling types; implementation is on the server handler side
  • Sampling is human-in-the-loop by default in most clients (Claude asks permission) — document this behaviour

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestfeature-requestNew feature or requestseverity: highHigh — significant breakage, no workaroundtimeline: long-termLong-term — requires significant design or multiple PRs

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions