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 clientMcpPayload, JsonRpcPayload serverMcpPayload, McpVersion mcpVersion, String sessionId)
      Create a McpContext.
      Parameters:
      parent - the parent Context.
      clientMcpPayload - the JSON-RPC message received from the MCP Client.
      serverMcpPayload - the JSON-RPC message received from the MCP Server.
      mcpVersion - the MCP 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
    • clientMcpPayload

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

      public McpVersion mcpVersion()
      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
    • serverMcpPayload

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