Record Class McpServerFeatures.SyncToolSpecification

java.lang.Object
java.lang.Record
io.modelcontextprotocol.server.McpServerFeatures.SyncToolSpecification
Record Components:
tool - The tool definition including name, description, and parameter schema
call - (Deprected) The function that implements the tool's logic, receiving arguments and returning results. The function's first argument is an McpSyncServerExchange upon which the server can interact with the connected
callHandler - The function that implements the tool's logic, receiving a McpSyncServerExchange and a McpSchema.CallToolRequest and returning results. The function's first argument is an McpSyncServerExchange upon which the server can interact with the client. The second arguments is a map of arguments passed to the tool.
Enclosing class:
McpServerFeatures

Specification of a tool with its synchronous handler function. Tools are the primary way for MCP servers to expose functionality to AI models.

Example tool specification:


 McpServerFeatures.SyncToolSpecification.builder()
 		.tool(new Tool(
 				"calculator",
 				"Performs mathematical calculations",
 				new JsonSchemaObject()
 						.required("expression")
 						.property("expression", JsonSchemaType.STRING)))
 		.toolHandler((exchange, req) -> {
 			String expr = (String) req.arguments().get("expression");
 			return new CallToolResult("Result: " + evaluate(expr));
 		}))
      .build();