Skip to main content

Overview

The ACP TypeScript SDK uses JSON-RPC 2.0 for message exchange between clients and agents. This page documents the internal JSON-RPC types used by the SDK.
These types are primarily for internal use by the SDK. Most applications will use the higher-level APIs provided by AgentSideConnection and ClientSideConnection rather than working with these types directly.

Message Types

AnyMessage

A union type representing any valid JSON-RPC 2.0 message that can be sent or received over an ACP connection.

Request Types

AnyRequest

Represents a JSON-RPC 2.0 request message. Properties:
  • jsonrpc (“2.0”) - JSON-RPC version identifier (always “2.0”)
  • id (string | number | null) - Unique identifier for matching requests with responses
  • method (string) - The method name to invoke (e.g., “session/prompt”)
  • params (unknown, optional) - Method parameters
Example:

Response Types

AnyResponse

Represents a JSON-RPC 2.0 response message, which can contain either a successful result or an error. Properties:
  • jsonrpc (“2.0”) - JSON-RPC version identifier
  • id (string | number | null) - ID matching the original request
  • Either result or error (from Result<unknown>)
Success Example:
Error Example:

Result

A discriminated union representing either a successful result or an error. Success Variant:
  • result (T) - The successful response data
Error Variant:
  • error (ErrorResponse) - The error information

ErrorResponse

Represents a JSON-RPC 2.0 error object. Properties:
  • code (number) - Numeric error code (see Error Codes)
  • message (string) - Human-readable error message
  • data (unknown, optional) - Additional error information
Example:

Notification Types

AnyNotification

Represents a JSON-RPC 2.0 notification message. Notifications are like requests but do not expect a response (no id field). Properties:
  • jsonrpc (“2.0”) - JSON-RPC version identifier
  • method (string) - The notification method name
  • params (unknown, optional) - Notification parameters
Example:

Handler Types

RequestHandler

A function type for handling incoming JSON-RPC requests. Parameters:
  • method (string) - The method being invoked
  • params (unknown) - The method parameters
Returns: Promise resolving to the result value Throws: Should throw RequestError for application errors Example:

NotificationHandler

A function type for handling incoming JSON-RPC notifications. Parameters:
  • method (string) - The notification method
  • params (unknown) - The notification parameters
Returns: Promise resolving when the notification is handled Example:

Internal Types

PendingResponse

An internal type used to track pending requests waiting for responses. Properties:
  • resolve (function) - Called when a successful response is received
  • reject (function) - Called when an error response is received
This type is used internally by the Connection class to manage the request/response lifecycle. You typically won’t interact with it directly.

Message Flow

Request-Response Flow

Notification Flow

Type Guards

Checking Message Types

You can use type guards to determine which kind of message you’re dealing with:

Usage Example

Best Practices

1. Use Type-Safe Wrappers

Rather than working with unknown params, use type-safe wrappers:

2. Always Return Proper Errors

Throw RequestError instances for application errors:

3. Don’t Block Notification Handlers

Notifications should be handled asynchronously without blocking:

See Also