Class McpClient
java.lang.Object
org.apache.juneau.rest.client.mcp.AbstractMcpClient
org.apache.juneau.rest.client.mcp.v20250618.McpClient
- All Implemented Interfaces:
Closeable,AutoCloseable
Typed 2025-06-18 Model Context Protocol (MCP) client facade.
Extends AbstractMcpClient, adding one typed method per McpMethods). Every method builds the corresponding v1 request bean, wraps it in a
JsonRpcRequest, delegates to the inherited AbstractMcpClient.send(JsonRpcRequest), and then either returns the
McpException built from the
response's
- Since:
- 10.0.0
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic McpClient.Builderbuilder()Creates a new builder.Sends "tools/call".complete(CompletionReference ref, CompletionArgument argument) Sends "completion/complete".Sends "prompts/get".Sends "initialize".Sends "prompts/list".Sends "resources/list".Sends "resources/templates/list".Sends "tools/list".voidping()Sends "ping" to verify server liveness.readResource(String uri) Sends "resources/read".Methods inherited from class org.apache.juneau.rest.client.mcp.AbstractMcpClient
close, openEventStream, openEventStream, openEventStream, send, send
-
Constructor Details
-
McpClient
Constructor.- Parameters:
builder- The builder supplying this client's configuration. Must not benull .
-
-
Method Details
-
builder
Creates a new builder.- Returns:
- A new builder. Never
null .
-
initialize
Sends "initialize".- Returns:
- The initialize result. Never
null on success unless the server returns anull result. - Throws:
IOException- If a transport-level or (de)serialization error occurs.McpException- If the server returned a JSON-RPC error.
-
ping
Sends "ping" to verify server liveness.- Throws:
IOException- If a transport-level or (de)serialization error occurs.McpException- If the server returned a JSON-RPC error.
-
listTools
Sends "tools/list".- Returns:
- The tools-list result. Never
null on success unless the server returns anull result. - Throws:
IOException- If a transport-level or (de)serialization error occurs.McpException- If the server returned a JSON-RPC error.
-
callTool
Sends "tools/call".- Parameters:
name- The tool name to invoke.arguments- The tool arguments. Can benull .- Returns:
- The call-tool result. Never
null on success unless the server returns anull result. - Throws:
IOException- If a transport-level or (de)serialization error occurs.McpException- If the server returned a JSON-RPC error.
-
listPrompts
Sends "prompts/list".- Returns:
- The prompts-list result. Never
null on success unless the server returns anull result. - Throws:
IOException- If a transport-level or (de)serialization error occurs.McpException- If the server returned a JSON-RPC error.
-
getPrompt
Sends "prompts/get".- Parameters:
name- The prompt name to fetch.arguments- The prompt argument values. Can benull .- Returns:
- The get-prompt result. Never
null on success unless the server returns anull result. - Throws:
IOException- If a transport-level or (de)serialization error occurs.McpException- If the server returned a JSON-RPC error.
-
listResources
Sends "resources/list".- Returns:
- The resources-list result. Never
null on success unless the server returns anull result. - Throws:
IOException- If a transport-level or (de)serialization error occurs.McpException- If the server returned a JSON-RPC error.
-
readResource
Sends "resources/read".- Parameters:
uri- The resource URI to read.- Returns:
- The read-resource result. Never
null on success unless the server returns anull result. - Throws:
IOException- If a transport-level or (de)serialization error occurs.McpException- If the server returned a JSON-RPC error.
-
listResourceTemplates
Sends "resources/templates/list".- Returns:
- The resource-templates-list result. Never
null on success unless the server returns anull result. - Throws:
IOException- If a transport-level or (de)serialization error occurs.McpException- If the server returned a JSON-RPC error.
-
complete
public CompleteResult complete(CompletionReference ref, CompletionArgument argument) throws IOException Sends "completion/complete".- Parameters:
ref- The completion target (a declared prompt or resource template reference).argument- The prompt argument or resource-template variable being completed, and its current partial value.- Returns:
- The completion result. Never
null on success unless the server returns anull result. - Throws:
IOException- If a transport-level or (de)serialization error occurs.McpException- If the server returned a JSON-RPC error.
-