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
Request Types
AnyRequest
jsonrpc(“2.0”) - JSON-RPC version identifier (always “2.0”)id(string | number | null) - Unique identifier for matching requests with responsesmethod(string) - The method name to invoke (e.g., “session/prompt”)params(unknown, optional) - Method parameters
Response Types
AnyResponse
jsonrpc(“2.0”) - JSON-RPC version identifierid(string | number | null) - ID matching the original request- Either
resultorerror(fromResult<unknown>)
Result
result(T) - The successful response data
error(ErrorResponse) - The error information
ErrorResponse
code(number) - Numeric error code (see Error Codes)message(string) - Human-readable error messagedata(unknown, optional) - Additional error information
Notification Types
AnyNotification
id field).
Properties:
jsonrpc(“2.0”) - JSON-RPC version identifiermethod(string) - The notification method nameparams(unknown, optional) - Notification parameters
Handler Types
RequestHandler
method(string) - The method being invokedparams(unknown) - The method parameters
RequestError for application errors
Example:
NotificationHandler
method(string) - The notification methodparams(unknown) - The notification parameters
Internal Types
PendingResponse
resolve(function) - Called when a successful response is receivedreject(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 withunknown params, use type-safe wrappers:
2. Always Return Proper Errors
ThrowRequestError instances for application errors:
3. Don’t Block Notification Handlers
Notifications should be handled asynchronously without blocking:See Also
- RequestError Class - Error handling
- Error Codes - Complete error code reference
- Stream Utilities - Message transport
- JSON-RPC 2.0 Specification - Official specification