ExMCP.Client.InteractiveHandler (ex_mcp v0.10.0)

View Source

Interactive terminal handler for MCP client events.

Presents elicitation requests, sampling requests, and permission prompts to the user via stdin/stdout. Useful for CLI applications that need human-in-the-loop interaction with MCP servers.

Usage

{:ok, client} = ExMCP.Client.start_link(
  transport: :http,
  url: "http://localhost:3000/mcp",
  handler: ExMCP.Client.InteractiveHandler,
  capabilities: %{"elicitation" => %{}, "sampling" => %{}}
)

When the server sends elicitation/create, the handler will:

  1. Display the message and schema to the user
  2. Prompt for each field in the schema
  3. Apply defaults when the user presses Enter without input
  4. Return the collected data or allow cancellation

Schema Rendering

Supports all JSON Schema types:

  • string → text prompt (with default, minLength, maxLength)
  • integer / number → numeric prompt (with minimum, maximum)
  • boolean → yes/no prompt
  • enum → numbered selection list
  • array → comma-separated values
  • object → nested prompts (one level)