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- 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 connected 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)
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. 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.SyncToolSpecification(
new Tool(
"calculator",
"Performs mathematical calculations",
new JsonSchemaObject()
.required("expression")
.property("expression", JsonSchemaType.STRING)
),
(exchange, args) -> {
String expr = (String) args.get("expression");
return new CallToolResult("Result: " + evaluate(expr));
}
)
-
Constructor Summary
ConstructorsConstructorDescriptionSyncToolSpecification(McpSchema.Tool tool, BiFunction<McpSyncServerExchange, Map<String, Object>, McpSchema.CallToolResult> call) Creates an instance of aSyncToolSpecificationrecord class. -
Method Summary
Modifier and TypeMethodDescriptioncall()Returns the value of thecallrecord 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
public SyncToolSpecification(McpSchema.Tool tool, BiFunction<McpSyncServerExchange, Map<String, Object>, McpSchema.CallToolResult> call) Creates an instance of aSyncToolSpecificationrecord class.
-
-
Method Details
-
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
Returns the value of thecallrecord component.- Returns:
- the value of the
callrecord component
-