McpProtocol

MCP protocol constants and response builders.

All methods are pure functions that produce Gson JsonObject structures conforming to the MCP JSON-RPC protocol.

Properties

Link copied to clipboard

Latest supported MCP protocol version.

Link copied to clipboard

Older supported MCP protocol version for backward compatibility.

Link copied to clipboard

Server version string reported in the initialize response.

Functions

Link copied to clipboard
fun buildInitializeResult(serverName: String, clientProtocolVersion: String?): JsonObject

Builds the initialize result object including protocol version, capabilities, and server info.

Link copied to clipboard
fun buildPingResult(): JsonObject

Builds the ping result.

Link copied to clipboard
fun buildToolsList(tools: List<McpTool>): JsonArray

Builds the tools array for a tools/list response from the given tool registry.

Link copied to clipboard
fun createErrorContent(message: String, meta: JsonObject? = null): JsonObject

Wraps an error tool result into the MCP content envelope.

Link copied to clipboard
fun createSuccessContent(message: String): JsonObject

Wraps a successful tool result into the MCP content envelope.

Link copied to clipboard
fun jsonRpcError(message: String, requestId: Int?): JsonObject

Creates a JSON-RPC error response with the given message.

Link copied to clipboard
fun jsonRpcSuccess(result: JsonObject, requestId: Int?): JsonObject

Wraps a result payload into a JSON-RPC success response.