Skip to content

MCP server cannot use sampling/createMessage to delegate work to client model #1686

Description

@Widthdom

Summary

The MCP server never uses sampling/createMessage to ask the connected client model for help. For suggest_improvement, this is a natural fit: when a user submits raw feedback, the server could ask the client model "extract a 1-line title and a structured tag set from this body" before persisting — improving downstream search/triage quality at no cost to the user. Sampling is a server→client request defined by the MCP spec and is the protocol's way to delegate model-side work without forcing the server to embed an LLM client.

Where

  • src/CodeIndex/Mcp/McpToolHandlers.cs (suggest_improvement handler, no sampling call)
  • src/CodeIndex/Mcp/McpServer.cs (no sampling capability negotiation)

Suggested approach

(1) Negotiate sampling capability in the initialize response (declare it, then check the client's capabilities.sampling before relying on it). (2) In suggest_improvement, when sampling is available, send a sampling/createMessage request to extract structured fields from the user's body, then store both raw and structured versions. (3) Fall back to the current raw-only path when client doesn't support sampling. (4) Add a feature flag so users can opt out if they don't want server→model traffic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions