public interface PromptContext
This interface provides prompt handlers with everything they need to:
This follows the MCP SDK's "Exchange" pattern where handlers receive a context object with all necessary capabilities, eliminating the need for external references to the agent instance.
Example usage:
agent.promptHandler((request, context) -> {
// Send an update
context.sendUpdate(sessionId, update);
// Read a file (if client supports it)
if (context.getClientCapabilities().supportsReadTextFile()) {
var content = context.readTextFile(new ReadTextFileRequest(...)).block();
}
// Request permission
var permission = context.requestPermission(new RequestPermissionRequest(...));
return Mono.just(new PromptResponse(StopReason.END_TURN));
});
AcpAgent.PromptHandler,
SyncPromptContext| 限定符和类型 | 方法和说明 |
|---|---|
reactor.core.publisher.Mono<java.lang.String> |
askChoice(java.lang.String question,
java.lang.String... options)
Asks the client to choose from multiple options.
|
reactor.core.publisher.Mono<java.lang.Boolean> |
askPermission(java.lang.String action)
Asks the client for permission to perform an action.
|
reactor.core.publisher.Mono<AcpSchema.CreateTerminalResponse> |
createTerminal(AcpSchema.CreateTerminalRequest request)
Requests the client to create a terminal.
|
reactor.core.publisher.Mono<CommandResult> |
execute(Command command)
Executes a command with options and waits for completion.
|
reactor.core.publisher.Mono<CommandResult> |
execute(java.lang.String... commandAndArgs)
Executes a command in a terminal and waits for completion.
|
NegotiatedCapabilities |
getClientCapabilities()
Returns the capabilities negotiated with the client during initialization.
|
java.lang.String |
getSessionId()
Returns the session ID for this prompt invocation.
|
reactor.core.publisher.Mono<AcpSchema.TerminalOutputResponse> |
getTerminalOutput(AcpSchema.TerminalOutputRequest request)
Requests terminal output from the client.
|
reactor.core.publisher.Mono<AcpSchema.KillTerminalCommandResponse> |
killTerminal(AcpSchema.KillTerminalCommandRequest request)
Requests the client to kill a terminal.
|
reactor.core.publisher.Mono<java.lang.String> |
readFile(java.lang.String path)
Reads a text file from the client's file system.
|
reactor.core.publisher.Mono<java.lang.String> |
readFile(java.lang.String path,
java.lang.Integer startLine,
java.lang.Integer lineCount)
Reads a portion of a text file from the client's file system.
|
reactor.core.publisher.Mono<AcpSchema.ReadTextFileResponse> |
readTextFile(AcpSchema.ReadTextFileRequest request)
Requests the client to read a text file.
|
reactor.core.publisher.Mono<AcpSchema.ReleaseTerminalResponse> |
releaseTerminal(AcpSchema.ReleaseTerminalRequest request)
Requests the client to release a terminal.
|
reactor.core.publisher.Mono<AcpSchema.RequestPermissionResponse> |
requestPermission(AcpSchema.RequestPermissionRequest request)
Requests permission from the client for a sensitive operation.
|
reactor.core.publisher.Mono<java.lang.Void> |
sendMessage(java.lang.String text)
Sends a message to the client as an agent message chunk.
|
reactor.core.publisher.Mono<java.lang.Void> |
sendThought(java.lang.String text)
Sends a thought to the client as an agent thought chunk.
|
reactor.core.publisher.Mono<java.lang.Void> |
sendUpdate(java.lang.String sessionId,
AcpSchema.SessionUpdate update)
Sends a session update notification to the client.
|
reactor.core.publisher.Mono<AcpSchema.WaitForTerminalExitResponse> |
waitForTerminalExit(AcpSchema.WaitForTerminalExitRequest request)
Waits for a terminal to exit.
|
reactor.core.publisher.Mono<java.lang.Void> |
writeFile(java.lang.String path,
java.lang.String content)
Writes content to a text file on the client's file system.
|
reactor.core.publisher.Mono<AcpSchema.WriteTextFileResponse> |
writeTextFile(AcpSchema.WriteTextFileRequest request)
Requests the client to write a text file.
|
reactor.core.publisher.Mono<java.lang.Void> sendUpdate(java.lang.String sessionId,
AcpSchema.SessionUpdate update)
sessionId - The session IDupdate - The session update to sendreactor.core.publisher.Mono<AcpSchema.ReadTextFileResponse> readTextFile(AcpSchema.ReadTextFileRequest request)
request - The read file requestAcpCapabilityException - if client doesn't support file readingreactor.core.publisher.Mono<AcpSchema.WriteTextFileResponse> writeTextFile(AcpSchema.WriteTextFileRequest request)
request - The write file requestAcpCapabilityException - if client doesn't support file writingreactor.core.publisher.Mono<AcpSchema.RequestPermissionResponse> requestPermission(AcpSchema.RequestPermissionRequest request)
request - The permission requestreactor.core.publisher.Mono<AcpSchema.CreateTerminalResponse> createTerminal(AcpSchema.CreateTerminalRequest request)
request - The create terminal requestAcpCapabilityException - if client doesn't support terminalsreactor.core.publisher.Mono<AcpSchema.TerminalOutputResponse> getTerminalOutput(AcpSchema.TerminalOutputRequest request)
request - The terminal output requestreactor.core.publisher.Mono<AcpSchema.ReleaseTerminalResponse> releaseTerminal(AcpSchema.ReleaseTerminalRequest request)
request - The release terminal requestreactor.core.publisher.Mono<AcpSchema.WaitForTerminalExitResponse> waitForTerminalExit(AcpSchema.WaitForTerminalExitRequest request)
request - The wait for exit requestreactor.core.publisher.Mono<AcpSchema.KillTerminalCommandResponse> killTerminal(AcpSchema.KillTerminalCommandRequest request)
request - The kill terminal requestNegotiatedCapabilities getClientCapabilities()
Use this to check what features the client supports before calling
methods like readTextFile(com.agentclientprotocol.sdk.spec.AcpSchema.ReadTextFileRequest) or createTerminal(com.agentclientprotocol.sdk.spec.AcpSchema.CreateTerminalRequest).
java.lang.String getSessionId()
reactor.core.publisher.Mono<java.lang.Void> sendMessage(java.lang.String text)
text - The message text to sendreactor.core.publisher.Mono<java.lang.Void> sendThought(java.lang.String text)
text - The thought text to sendreactor.core.publisher.Mono<java.lang.String> readFile(java.lang.String path)
path - The path to the fileAcpCapabilityException - if client doesn't support file readingreactor.core.publisher.Mono<java.lang.String> readFile(java.lang.String path,
java.lang.Integer startLine,
java.lang.Integer lineCount)
path - The path to the filestartLine - The line number to start reading from (0-indexed, null for beginning)lineCount - The number of lines to read (null for all remaining)AcpCapabilityException - if client doesn't support file readingreactor.core.publisher.Mono<java.lang.Void> writeFile(java.lang.String path,
java.lang.String content)
path - The path to the filecontent - The content to writeAcpCapabilityException - if client doesn't support file writingreactor.core.publisher.Mono<java.lang.Boolean> askPermission(java.lang.String action)
action - A description of the action to request permission forreactor.core.publisher.Mono<java.lang.String> askChoice(java.lang.String question,
java.lang.String... options)
question - The question to askoptions - The available options (at least 2)reactor.core.publisher.Mono<CommandResult> execute(java.lang.String... commandAndArgs)
commandAndArgs - The command and arguments to executeAcpCapabilityException - if client doesn't support terminalsreactor.core.publisher.Mono<CommandResult> execute(Command command)
command - The command configurationAcpCapabilityException - if client doesn't support terminals