Working with Tools
The tool system in AJ MCP provides a structured way to define callable functions that clients can discover and invoke. Each tool has a name, description, and a JSON Schema that defines its expected input parameters. The tool system is designed to make it easy for LLMs to understand what tools are available and how to use them.
Listing Tools
To list available tools:
List<ToolItem> tools = mcpClient.listTools();
assertEquals(7,tools.size());
listTools() requests the first/default page. It does not automatically follow nextCursor. Use
listTools(int pageNo) to request another page.
List<ToolItem> tools = mcpClient.listTools(1);
assertEquals(3, tools.size());
Calling Tools
To call a tool:
String toolExecutionResultString = mcpClient.callTool("echoString", "{\"input\": \"hi\"}");
assertEquals("hi",toolExecutionResultString);
The current callTool() convenience API returns a String assembled from text content. It does not expose image
content through this method. Tool-level errors are returned as an error message string; transport and timeout failures
follow the client exception/timeout behavior.
Handling Notifications
Register callbacks with onNotification(method, handler) for progress, logging, resource updates, and list-change
notifications. Use onServerRequest(method, handler) to answer server-initiated requests; setRoots(...),
setSamplingHandler(...), and setElicitationHandler(...) configure the standard handlers before initialize().
See Handling Notifications for lifecycle and error behavior.