Learn how to use the Model Context Protocol (MCP) client to interact with MCP servers
Go to the Java MCP Server to learn how to build MCP servers or the Java MCP Overview to understand the overall architecture.
The MCP Client is a key component in the Model Context Protocol (MCP) architecture, responsible for establishing and managing connections with MCP servers. It implements the client-side of the protocol, handling:
The core io.modelcontextprotocol.sdk:mcp
module provides STDIO and SSE client transport implementations without requiring external web frameworks.
Spring-specific transport implementations are available as an optional dependency io.modelcontextprotocol.sdk:mcp-spring-webflux
for Spring Framework users.
This quickstart demo, based on Spring AI MCP, will show you how to build an AI client that connects to MCP servers.
The client provides both synchronous and asynchronous APIs for flexibility in different application contexts.
The transport layer handles the communication between MCP clients and servers, providing different implementations for various use cases. The client transport manages message serialization, connection establishment, and protocol-specific communication patterns.
Creates transport for in-process based communication
Creates transport for in-process based communication
Creates a framework agnostic (pure Java API) SSE client transport. Included in the core mcp module.
Creates WebFlux-based SSE client transport. Requires the mcp-webflux-sse-transport dependency.
The client can be configured with various capabilities:
Roots define the boundaries of where servers can operate within the filesystem:
The roots capability allows servers to:
Sampling enables servers to request LLM interactions (“completions” or “generations”) through the client:
This capability allows:
The client can register a logging consumer to receive log messages from the server and set the minimum logging level to filter messages:
Clients can control the minimum logging level they receive through the mcpClient.setLoggingLevel(level)
request. Messages below the set level will be filtered out.
Supported logging levels (in order of increasing severity): DEBUG (0), INFO (1), NOTICE (2), WARNING (3), ERROR (4), CRITICAL (5), ALERT (6), EMERGENCY (7)
Tools are server-side functions that clients can discover and execute. The MCP client provides methods to list available tools and execute them with specific parameters. Each tool has a unique name and accepts a map of parameters.
Resources represent server-side data sources that clients can access using URI templates. The MCP client provides methods to discover available resources and retrieve their contents through a standardized interface.
The prompt system enables interaction with server-side prompt templates. These templates can be discovered and executed with custom parameters, allowing for dynamic text generation based on predefined patterns.
As part of the Completion capabilities, MCP provides a standardized way for servers to offer argument autocompletion suggestions for prompts and resource URIs.
Check the Server Completion capabilities to learn how to enable and configure completions on the server side.
On the client side, the MCP client provides methods to request auto-completions:
Learn how to use the Model Context Protocol (MCP) client to interact with MCP servers
Go to the Java MCP Server to learn how to build MCP servers or the Java MCP Overview to understand the overall architecture.
The MCP Client is a key component in the Model Context Protocol (MCP) architecture, responsible for establishing and managing connections with MCP servers. It implements the client-side of the protocol, handling:
The core io.modelcontextprotocol.sdk:mcp
module provides STDIO and SSE client transport implementations without requiring external web frameworks.
Spring-specific transport implementations are available as an optional dependency io.modelcontextprotocol.sdk:mcp-spring-webflux
for Spring Framework users.
This quickstart demo, based on Spring AI MCP, will show you how to build an AI client that connects to MCP servers.
The client provides both synchronous and asynchronous APIs for flexibility in different application contexts.
The transport layer handles the communication between MCP clients and servers, providing different implementations for various use cases. The client transport manages message serialization, connection establishment, and protocol-specific communication patterns.
Creates transport for in-process based communication
Creates transport for in-process based communication
Creates a framework agnostic (pure Java API) SSE client transport. Included in the core mcp module.
Creates WebFlux-based SSE client transport. Requires the mcp-webflux-sse-transport dependency.
The client can be configured with various capabilities:
Roots define the boundaries of where servers can operate within the filesystem:
The roots capability allows servers to:
Sampling enables servers to request LLM interactions (“completions” or “generations”) through the client:
This capability allows:
The client can register a logging consumer to receive log messages from the server and set the minimum logging level to filter messages:
Clients can control the minimum logging level they receive through the mcpClient.setLoggingLevel(level)
request. Messages below the set level will be filtered out.
Supported logging levels (in order of increasing severity): DEBUG (0), INFO (1), NOTICE (2), WARNING (3), ERROR (4), CRITICAL (5), ALERT (6), EMERGENCY (7)
Tools are server-side functions that clients can discover and execute. The MCP client provides methods to list available tools and execute them with specific parameters. Each tool has a unique name and accepts a map of parameters.
Resources represent server-side data sources that clients can access using URI templates. The MCP client provides methods to discover available resources and retrieve their contents through a standardized interface.
The prompt system enables interaction with server-side prompt templates. These templates can be discovered and executed with custom parameters, allowing for dynamic text generation based on predefined patterns.
As part of the Completion capabilities, MCP provides a standardized way for servers to offer argument autocompletion suggestions for prompts and resource URIs.
Check the Server Completion capabilities to learn how to enable and configure completions on the server side.
On the client side, the MCP client provides methods to request auto-completions: