Specification of a tool with its asynchronous handler function. Tools are the
primary way for MCP servers to expose functionality to AI models. Each tool
represents a specific capability, such as:
- Performing calculations
- Accessing external APIs
- Querying databases
- Manipulating files
- Executing system commands
Example tool specification:
new McpServerFeatures.AsyncToolSpecification(
new Tool(
"calculator",
"Performs mathematical calculations",
new JsonSchemaObject()
.required("expression")
.property("expression", JsonSchemaType.STRING)
),
(exchange, args) -> {
String expr = (String) args.get("expression");
return Mono.fromSupplier(() -> evaluate(expr))
.map(result -> new CallToolResult("Result: " + result));
}
)