Class McpContext

All Implemented Interfaces:
Context

public final class McpContext extends AbstractContext
A context holding MCP request and response information. Note that:
  • an MCP client can send an MCP response to the server in response to a request from the MCP server sent as a Server Sent Event (SSE).
  • An MCP server can only acknowledge the Client's request, without request's body.
  • Constructor Details

    • McpContext

      public McpContext(Context parent)
      Create a McpContext.
      Parameters:
      parent - the parent Context.
    • McpContext

      public McpContext(Context parent, JsonRpcPayload clientPayload, JsonRpcPayload serverPayload, String protocolVersion, String sessionId)
      Create a McpContext.
      Parameters:
      parent - the parent Context.
      clientPayload - the JSON-RPC message received from the MCP Client.
      serverPayload - the JSON-RPC message received from the MCP Server.
      protocolVersion - the MCP protocol version
      sessionId - the MCP sessionId
  • Method Details

    • clientMessageType

      public McpContext.ClientMessageType clientMessageType()
      Returns the MCP Client message type.
      Returns:
      the MCP Client message type
    • serverMessageType

      public McpContext.ServerMessageType serverMessageType()
      Returns the MCP Server message type.
      Returns:
      the MCP Server message type
    • clientPayload

      public JsonRpcPayload clientPayload()
      Returns the JSON-RPC message received from the MCP client.
      Returns:
      the JSON-RPC message received from the MCP client
    • protocolVersion

      public String protocolVersion()
      Returns the MCP version being used.
      Returns:
      the MCP version being used
    • sessionId

      public String sessionId()
      Returns the MCP sessionId, if set.
      Returns:
      the MCP sessionId, if set
    • serverPayload

      public JsonRpcPayload serverPayload()
      Returns the JSON-RPC message received from the MCP server, if any.
      Returns:
      the JSON-RPC message received from the MCP server, if any