Skip to content

Commit febb45a

Browse files
committed
Copy docs over to request/notif enums
1 parent 8a1109f commit febb45a

2 files changed

Lines changed: 187 additions & 0 deletions

File tree

rust/agent.rs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,14 +640,90 @@ pub(crate) const SESSION_SET_MODEL_METHOD_NAME: &str = "session/set_model";
640640
#[serde(untagged)]
641641
#[schemars(extend("x-docs-ignore" = true))]
642642
pub enum ClientRequest {
643+
/// Establishes the connection with a client and negotiates protocol capabilities.
644+
///
645+
/// This method is called once at the beginning of the connection to:
646+
/// - Negotiate the protocol version to use
647+
/// - Exchange capability information between client and agent
648+
/// - Determine available authentication methods
649+
///
650+
/// The agent should respond with its supported protocol version and capabilities.
651+
///
652+
/// See protocol docs: [Initialization](https://agentclientprotocol.com/protocol/initialization)
643653
InitializeRequest(InitializeRequest),
654+
/// Authenticates the client using the specified authentication method.
655+
///
656+
/// Called when the agent requires authentication before allowing session creation.
657+
/// The client provides the authentication method ID that was advertised during initialization.
658+
///
659+
/// After successful authentication, the client can proceed to create sessions with
660+
/// `new_session` without receiving an `auth_required` error.
661+
///
662+
/// See protocol docs: [Initialization](https://agentclientprotocol.com/protocol/initialization)
644663
AuthenticateRequest(AuthenticateRequest),
664+
/// Creates a new conversation session with the agent.
665+
///
666+
/// Sessions represent independent conversation contexts with their own history and state.
667+
///
668+
/// The agent should:
669+
/// - Create a new session context
670+
/// - Connect to any specified MCP servers
671+
/// - Return a unique session ID for future requests
672+
///
673+
/// May return an `auth_required` error if the agent requires authentication.
674+
///
675+
/// See protocol docs: [Session Setup](https://agentclientprotocol.com/protocol/session-setup)
645676
NewSessionRequest(NewSessionRequest),
677+
/// Loads an existing session to resume a previous conversation.
678+
///
679+
/// This method is only available if the agent advertises the `loadSession` capability.
680+
///
681+
/// The agent should:
682+
/// - Restore the session context and conversation history
683+
/// - Connect to the specified MCP servers
684+
/// - Stream the entire conversation history back to the client via notifications
685+
///
686+
/// See protocol docs: [Loading Sessions](https://agentclientprotocol.com/protocol/session-setup#loading-sessions)
646687
LoadSessionRequest(LoadSessionRequest),
688+
/// Sets the current mode for a session.
689+
///
690+
/// Allows switching between different agent modes (e.g., "ask", "architect", "code")
691+
/// that affect system prompts, tool availability, and permission behaviors.
692+
///
693+
/// The mode must be one of the modes advertised in `availableModes` during session
694+
/// creation or loading. Agents may also change modes autonomously and notify the
695+
/// client via `current_mode_update` notifications.
696+
///
697+
/// This method can be called at any time during a session, whether the Agent is
698+
/// idle or actively generating a response.
699+
///
700+
/// See protocol docs: [Session Modes](https://agentclientprotocol.com/protocol/session-modes)
647701
SetSessionModeRequest(SetSessionModeRequest),
702+
/// Processes a user prompt within a session.
703+
///
704+
/// This method handles the whole lifecycle of a prompt:
705+
/// - Receives user messages with optional context (files, images, etc.)
706+
/// - Processes the prompt using language models
707+
/// - Reports language model content and tool calls to the Clients
708+
/// - Requests permission to run tools
709+
/// - Executes any requested tool calls
710+
/// - Returns when the turn is complete with a stop reason
711+
///
712+
/// See protocol docs: [Prompt Turn](https://agentclientprotocol.com/protocol/prompt-turn)
648713
PromptRequest(PromptRequest),
649714
#[cfg(feature = "unstable")]
715+
/// **UNSTABLE**
716+
///
717+
/// This capability is not part of the spec yet, and may be removed or changed at any point.
718+
///
719+
/// Select a model for a given session.
650720
SetSessionModelRequest(SetSessionModelRequest),
721+
/// Handles extension method requests from the client.
722+
///
723+
/// Extension methods provide a way to add custom functionality while maintaining
724+
/// protocol compatibility.
725+
///
726+
/// See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)
651727
ExtMethodRequest(ExtRequest),
652728
}
653729

@@ -682,7 +758,24 @@ pub enum AgentResponse {
682758
#[serde(untagged)]
683759
#[schemars(extend("x-docs-ignore" = true))]
684760
pub enum ClientNotification {
761+
/// Cancels ongoing operations for a session.
762+
///
763+
/// This is a notification sent by the client to cancel an ongoing prompt turn.
764+
///
765+
/// Upon receiving this notification, the Agent SHOULD:
766+
/// - Stop all language model requests as soon as possible
767+
/// - Abort all tool call invocations in progress
768+
/// - Send any pending `session/update` notifications
769+
/// - Respond to the original `session/prompt` request with `StopReason::Cancelled`
770+
///
771+
/// See protocol docs: [Cancellation](https://agentclientprotocol.com/protocol/prompt-turn#cancellation)
685772
CancelNotification(CancelNotification),
773+
/// Handles extension notifications from the client.
774+
///
775+
/// Extension notifications provide a way to send one-way messages for custom functionality
776+
/// while maintaining protocol compatibility.
777+
///
778+
/// See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)
686779
ExtNotification(ExtNotification),
687780
}
688781

rust/client.rs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,14 +541,90 @@ pub(crate) const TERMINAL_KILL_METHOD_NAME: &str = "terminal/kill";
541541
#[serde(untagged)]
542542
#[schemars(extend("x-docs-ignore" = true))]
543543
pub enum AgentRequest {
544+
/// Writes content to a text file in the client's file system.
545+
///
546+
/// Only available if the client advertises the `fs.writeTextFile` capability.
547+
/// Allows the agent to create or modify files within the client's environment.
548+
///
549+
/// See protocol docs: [Client](https://agentclientprotocol.com/protocol/overview#client)
544550
WriteTextFileRequest(WriteTextFileRequest),
551+
/// Reads content from a text file in the client's file system.
552+
///
553+
/// Only available if the client advertises the `fs.readTextFile` capability.
554+
/// Allows the agent to access file contents within the client's environment.
555+
///
556+
/// See protocol docs: [Client](https://agentclientprotocol.com/protocol/overview#client)
545557
ReadTextFileRequest(ReadTextFileRequest),
558+
/// Requests permission from the user for a tool call operation.
559+
///
560+
/// Called by the agent when it needs user authorization before executing
561+
/// a potentially sensitive operation. The client should present the options
562+
/// to the user and return their decision.
563+
///
564+
/// If the client cancels the prompt turn via `session/cancel`, it MUST
565+
/// respond to this request with `RequestPermissionOutcome::Cancelled`.
566+
///
567+
/// See protocol docs: [Requesting Permission](https://agentclientprotocol.com/protocol/tool-calls#requesting-permission)
546568
RequestPermissionRequest(RequestPermissionRequest),
569+
/// Executes a command in a new terminal
570+
///
571+
/// Only available if the `terminal` Client capability is set to `true`.
572+
///
573+
/// Returns a `TerminalId` that can be used with other terminal methods
574+
/// to get the current output, wait for exit, and kill the command.
575+
///
576+
/// The `TerminalId` can also be used to embed the terminal in a tool call
577+
/// by using the `ToolCallContent::Terminal` variant.
578+
///
579+
/// The Agent is responsible for releasing the terminal by using the `terminal/release`
580+
/// method.
581+
///
582+
/// See protocol docs: [Terminals](https://agentclientprotocol.com/protocol/terminals)
547583
CreateTerminalRequest(CreateTerminalRequest),
584+
/// Gets the terminal output and exit status
585+
///
586+
/// Returns the current content in the terminal without waiting for the command to exit.
587+
/// If the command has already exited, the exit status is included.
588+
///
589+
/// See protocol docs: [Terminals](https://agentclientprotocol.com/protocol/terminals)
548590
TerminalOutputRequest(TerminalOutputRequest),
591+
/// Releases a terminal
592+
///
593+
/// The command is killed if it hasn't exited yet. Use `terminal/wait_for_exit`
594+
/// to wait for the command to exit before releasing the terminal.
595+
///
596+
/// After release, the `TerminalId` can no longer be used with other `terminal/*` methods,
597+
/// but tool calls that already contain it, continue to display its output.
598+
///
599+
/// The `terminal/kill` method can be used to terminate the command without releasing
600+
/// the terminal, allowing the Agent to call `terminal/output` and other methods.
601+
///
602+
/// See protocol docs: [Terminals](https://agentclientprotocol.com/protocol/terminals)
549603
ReleaseTerminalRequest(ReleaseTerminalRequest),
604+
/// Waits for the terminal command to exit and return its exit status
605+
///
606+
/// See protocol docs: [Terminals](https://agentclientprotocol.com/protocol/terminals)
550607
WaitForTerminalExitRequest(WaitForTerminalExitRequest),
608+
/// Kills the terminal command without releasing the terminal
609+
///
610+
/// While `terminal/release` will also kill the command, this method will keep
611+
/// the `TerminalId` valid so it can be used with other methods.
612+
///
613+
/// This method can be helpful when implementing command timeouts which terminate
614+
/// the command as soon as elapsed, and then get the final output so it can be sent
615+
/// to the model.
616+
///
617+
/// Note: `terminal/release` when `TerminalId` is no longer needed.
618+
///
619+
/// See protocol docs: [Terminals](https://agentclientprotocol.com/protocol/terminals)
551620
KillTerminalCommandRequest(KillTerminalCommandRequest),
621+
/// Handles extension method requests from the agent.
622+
///
623+
/// Allows the Agent to send an arbitrary request that is not part of the ACP spec.
624+
/// Extension methods provide a way to add custom functionality while maintaining
625+
/// protocol compatibility.
626+
///
627+
/// See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)
552628
ExtMethodRequest(ExtRequest),
553629
}
554630

@@ -584,6 +660,24 @@ pub enum ClientResponse {
584660
#[allow(clippy::large_enum_variant)]
585661
#[schemars(extend("x-docs-ignore" = true))]
586662
pub enum AgentNotification {
663+
/// Handles session update notifications from the agent.
664+
///
665+
/// This is a notification endpoint (no response expected) that receives
666+
/// real-time updates about session progress, including message chunks,
667+
/// tool calls, and execution plans.
668+
///
669+
/// Note: Clients SHOULD continue accepting tool call updates even after
670+
/// sending a `session/cancel` notification, as the agent may send final
671+
/// updates before responding with the cancelled stop reason.
672+
///
673+
/// See protocol docs: [Agent Reports Output](https://agentclientprotocol.com/protocol/prompt-turn#3-agent-reports-output)
587674
SessionNotification(SessionNotification),
675+
/// Handles extension notifications from the agent.
676+
///
677+
/// Allows the Agent to send an arbitrary notification that is not part of the ACP spec.
678+
/// Extension notifications provide a way to send one-way messages for custom functionality
679+
/// while maintaining protocol compatibility.
680+
///
681+
/// See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)
588682
ExtNotification(ExtNotification),
589683
}

0 commit comments

Comments
 (0)