SDK Contents
Java MCP Overview [Java MCP Client] Java MCP ServerClient Features
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:- Protocol version negotiation to ensure compatibility with servers
- Capability negotiation to determine available features
- Message transport and JSON-RPC communication
- Tool discovery and execution
- Resource access and management
- Prompt system interactions
- Optional features like roots management and sampling support
The core
io.modelcontextprotocol.sdk:mcp
module provides STDIO, Streamable-HTTP 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.
Client Transport
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
Client Capabilities
The client can be configured with various capabilities:Roots Support
Roots define the boundaries of where servers can operate within the filesystem:- Request the list of accessible filesystem roots
- Receive notifications when the roots list changes
- Understand which directories and files they have access to
Sampling Support
Sampling enables servers to request LLM interactions (“completions” or “generations”) through the client:- Servers to leverage AI capabilities without requiring API keys
- Clients to maintain control over model access and permissions
- Support for both text and image-based interactions
- Optional inclusion of MCP server context in prompts
Elicitation Support
Elicitation enables servers to request specific information or clarification from the client:Logging Support
The client can register a logging consumer to receive log messages from the server and set the minimum logging level to filter messages: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)
Progress Support
The client can register a progress consumer to receive progress updates from the server:Change Notifications
The client can register a change consumer to receive change notifications from the server about tools, resources, or prompts updates:Using MCP Clients
Tool Execution
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.Resource Access
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.Prompt System
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.Using Completion
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:Adding context information
HTTP request sent through SSE or Streamable HTTP transport can be customized with dedicated APIs (see client transport). These customizers may need additional context-specific information that must be injected at the client level.The This
McpSyncClient
is used in a blocking environment, and may rely on thread-locals to share information.
For example, some frameworks store the current server request or security tokens in a thread-local.
To make this type of information available to underlying transports, use SyncSpec#transportContextProvider
:McpTransportContext
will be available in HttpClient-based McpSyncHttpClientRequestCustomizer
and WebClient-based ExchangeFilterFunction
.