Package io.modelcontextprotocol.server
Record Class McpServerFeatures.SyncPromptSpecification
java.lang.Object
java.lang.Record
io.modelcontextprotocol.server.McpServerFeatures.SyncPromptSpecification
- Record Components:
prompt- The prompt definition including name and descriptionpromptHandler- The function that processes prompt requests and returns formatted templates. The function's first argument is anMcpSyncServerExchangeupon which the server can interact with the connected client. The second arguments is aMcpSchema.GetPromptRequest.
- Enclosing class:
- McpServerFeatures
public static record McpServerFeatures.SyncPromptSpecification(McpSchema.Prompt prompt, BiFunction<McpSyncServerExchange,McpSchema.GetPromptRequest,McpSchema.GetPromptResult> promptHandler)
extends Record
Specification of a prompt template with its synchronous handler function. Prompts
provide structured templates for AI model interactions, supporting:
- Consistent message formatting
- Parameter substitution
- Context injection
- Response formatting
- Instruction templating
Example prompt specification:
new McpServerFeatures.SyncPromptSpecification(
new Prompt("analyze", "Code analysis template"),
(exchange, request) -> {
String code = request.getArguments().get("code");
return new GetPromptResult(
"Analyze this code:\n\n" + code + "\n\nProvide feedback on:");
})
-
Constructor Summary
ConstructorsConstructorDescriptionSyncPromptSpecification(McpSchema.Prompt prompt, BiFunction<McpSyncServerExchange, McpSchema.GetPromptRequest, McpSchema.GetPromptResult> promptHandler) Creates an instance of aSyncPromptSpecificationrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.prompt()Returns the value of thepromptrecord component.Returns the value of thepromptHandlerrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
SyncPromptSpecification
public SyncPromptSpecification(McpSchema.Prompt prompt, BiFunction<McpSyncServerExchange, McpSchema.GetPromptRequest, McpSchema.GetPromptResult> promptHandler) Creates an instance of aSyncPromptSpecificationrecord class.- Parameters:
prompt- the value for thepromptrecord componentpromptHandler- the value for thepromptHandlerrecord component
-
-
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). -
prompt
Returns the value of thepromptrecord component.- Returns:
- the value of the
promptrecord component
-
promptHandler
public BiFunction<McpSyncServerExchange,McpSchema.GetPromptRequest, promptHandler()McpSchema.GetPromptResult> Returns the value of thepromptHandlerrecord component.- Returns:
- the value of the
promptHandlerrecord component
-