Initializing the Protocol
After creating a client, call initialize() before sending any other protocol request. It starts the transport, negotiates the protocol version and capabilities, and sends the notifications/initialized notification.
The Initialize method:
- Sends an initialize request to the server
- Logs the server's initialization result
- Sends an "initialized" notification
After successful initialization, the client can make other requests to the server.
Call initialize() immediately after building the McpClient. Initialization uses the configured requestTimeout; zero means wait indefinitely.
McpClient mcpClient = McpClient.builder()
.clientName("my-host")
.clientVersion("1.2")
.transport(sseTransport)
.build();
mcpClient.initialize();