MCP¶
The Model Context Protocol client in ai-elements-core gives an
agent tools, resources and prompts from MCP servers. It speaks the 2026-07-28 revision over
Streamable HTTP and falls back to the 2025-xx session revisions for older servers.
val mcp = McpClient("https://mcp.example.com/mcp") // 2026-07-28, falls back to 2025-xx sessions
val tools = mcp.listTools()
val result = mcp.callTool(
"book_table",
buildJsonObject { put("restaurant", "Noma") },
onInput = { request -> InputResponse.Accept(buildJsonObject { put("guests", 2) }) }, // elicitation
onProgress = { progress -> println("${progress.fraction}") }, // notifications/progress
)
In an agent¶
McpServerStore keeps the servers the user configured, with credentials encrypted, and turns the
enabled ones into a capability:
McpToolset lists the servers' tools in parallel with a timeout per server. A server that fails is
skipped for that turn and reported in status, instead of failing the turn. Tool lists are cached.
MCP tools render with the server's name as their source. Tools that are not read-only ask the user
before they run. Tool annotations are treated as untrusted hints: only readOnlyHint relaxes the
default.
Features¶
- Tools (
tools/list,tools/call), resources, prompts, pagination. notifications/progress, shown live on the tool call.-
Elicitation, where the server asks the user something:
- 2026-07-28:
InputRequiredResult(resultType: "input_required") is answered by retrying the call withinputResponsesandrequestState(up to 10 rounds); - legacy sessions:
elicitation/createon the stream.
Form and URL modes are declared. In a chat, the question shows as a form; see Human in the loop. - OAuth for protected servers: protected resource metadata (RFC 9728), authorization server metadata (RFC 8414), dynamic client registration (RFC 7591), resource indicators (RFC 8707), PKCE
S256. A server that needs sign-in is reported asNeedsSignIn. - MCP Apps views of tools; see MCP Apps. - 2026-07-28:
Sampling and roots are not declared.