Package io.modelcontextprotocol.server
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 schemacall- (Deprected) The function that implements the tool's logic, receiving arguments and returning results. The function's first argument is anMcpSyncServerExchangeupon which the server can interact with the connectedcallHandler- The function that implements the tool's logic, receiving aMcpSyncServerExchangeand aMcpSchema.CallToolRequestand returning results. The function's first argument is anMcpSyncServerExchangeupon which the server can interact with the client. The second arguments is a map of arguments passed to the tool.
- Enclosing class:
- McpServerFeatures
public static record McpServerFeatures.SyncToolSpecification(McpSchema.Tool tool, BiFunction<McpSyncServerExchange,Map<String,Object>,McpSchema.CallToolResult> call, BiFunction<McpSyncServerExchange,McpSchema.CallToolRequest,McpSchema.CallToolResult> callHandler)
extends Record
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();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for creating SyncToolSpecification instances. -
Constructor Summary
ConstructorsConstructorDescriptionSyncToolSpecification(McpSchema.Tool tool, BiFunction<McpSyncServerExchange, Map<String, Object>, McpSchema.CallToolResult> call) Deprecated.SyncToolSpecification(McpSchema.Tool tool, BiFunction<McpSyncServerExchange, Map<String, Object>, McpSchema.CallToolResult> call, BiFunction<McpSyncServerExchange, McpSchema.CallToolRequest, McpSchema.CallToolResult> callHandler) Creates an instance of aSyncToolSpecificationrecord class. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Creates a new builder instance.call()Deprecated.Returns the value of thecallHandlerrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.tool()Returns the value of thetoolrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
SyncToolSpecification
@Deprecated public SyncToolSpecification(McpSchema.Tool tool, BiFunction<McpSyncServerExchange, Map<String, Object>, McpSchema.CallToolResult> call) Deprecated. -
SyncToolSpecification
public SyncToolSpecification(McpSchema.Tool tool, @Deprecated BiFunction<McpSyncServerExchange, Map<String, Object>, McpSchema.CallToolResult> call, BiFunction<McpSyncServerExchange, McpSchema.CallToolRequest, McpSchema.CallToolResult> callHandler) Creates an instance of aSyncToolSpecificationrecord class.- Parameters:
tool- the value for thetoolrecord componentcall- the value for thecallrecord componentcallHandler- the value for thecallHandlerrecord component
-
-
Method Details
-
builder
Creates a new builder instance.- Returns:
- a new Builder instance
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
tool
Returns the value of thetoolrecord component.- Returns:
- the value of the
toolrecord component
-
call
@Deprecated public BiFunction<McpSyncServerExchange,Map<String, call()Object>, McpSchema.CallToolResult> Deprecated.Returns the value of thecallrecord component.- Returns:
- the value of the
callrecord component
-
callHandler
public BiFunction<McpSyncServerExchange,McpSchema.CallToolRequest, callHandler()McpSchema.CallToolResult> Returns the value of thecallHandlerrecord component.- Returns:
- the value of the
callHandlerrecord component
-