rpc

package
v0.147.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2026 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Overview

Package rpc provides a minimal JSON-RPC client tailored to the Codex app-server. Notification subscriptions have a hard caller-selected capacity. A slow consumer is closed with NotificationOverflowError without blocking responses or other subscribers. The package intentionally implements only the subset needed for Codex. For general-purpose JSON-RPC support, consider using a dedicated library.

Index

Constants

View Source
const (
	// ServerRequestMethodNotFoundCode is the JSON-RPC code for an unknown method.
	ServerRequestMethodNotFoundCode int64 = -32601
	// ServerRequestInvalidParamsCode is the JSON-RPC code for malformed parameters.
	ServerRequestInvalidParamsCode int64 = -32602
	// ServerRequestInternalErrorCode is the JSON-RPC code for an internal failure.
	ServerRequestInternalErrorCode int64 = -32603
	// ServerRequestHandlerErrorCode is used when an application handler fails.
	ServerRequestHandlerErrorCode int64 = -32000
	// ServerRequestBusyCode is used when the bounded handler queue is full.
	ServerRequestBusyCode int64 = -32001
)
View Source
const DefaultMaxMessageBytes = 8 << 20

DefaultMaxMessageBytes is the maximum JSON payload accepted from a built-in line-oriented transport. The trailing newline is not counted.

Variables

View Source
var ErrClientClosed = errors.New("rpc client closed")

ErrClientClosed identifies a client closed by its caller.

View Source
var ErrConnectionClosed = errors.New("rpc connection closed")

ErrConnectionClosed identifies a client whose connection closed without a more specific transport error.

View Source
var ErrMessageTooLarge = errors.New("rpc message exceeds size limit")

ErrMessageTooLarge identifies an inbound JSON-RPC line over the configured client or built-in transport limit.

View Source
var ErrNotificationOverflow = errors.New("notification subscription overflow")

ErrNotificationOverflow identifies a notification subscription that was closed because its configured capacity was exhausted.

View Source
var ErrNotificationSubscriptionClosed = errors.New("notification subscription closed")

ErrNotificationSubscriptionClosed identifies an iterator closed by its caller.

View Source
var ErrOutboundQueueFull = errors.New("rpc outbound write queue is full")

ErrOutboundQueueFull identifies a client whose bounded outbound write queue could not accept an asynchronous protocol reply.

View Source
var ErrServerRequestUnsupported = errors.New("server request is unsupported")

ErrServerRequestUnsupported is returned by default handler methods that an application has not overridden.

Functions

func DefaultStderr

func DefaultStderr() io.Writer

DefaultStderr returns a safe default for spawned processes.

func ReadLineLimited added in v0.147.0

func ReadLineLimited(reader *bufio.Reader, maxBytes int) (string, error)

ReadLineLimited reads one newline-delimited payload and rejects it before the assembled payload exceeds maxBytes plus the delimiter. maxBytes must be positive.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client manages JSON-RPC requests over a Transport.

func NewClient

func NewClient(transport Transport, options ClientOptions) *Client

NewClient creates a JSON-RPC client over a Transport. It panics if transport is nil. Use NewClientChecked when the dependency is not statically known.

func NewClientChecked added in v0.147.0

func NewClientChecked(transport Transport, options ClientOptions) (*Client, error)

NewClientChecked creates a JSON-RPC client over a validated Transport.

func (*Client) AccountLoginCancel

Client implements ClientRequests using JSON-RPC.

func (*Client) AccountLoginStart

func (c *Client) AccountLoginStart(ctx context.Context, params protocol.LoginAccountParams) (*protocol.LoginAccountResponse, error)

func (*Client) AccountLogout

func (c *Client) AccountLogout(ctx context.Context) (*protocol.LogoutAccountResponse, error)

func (*Client) AccountRateLimitsRead

func (c *Client) AccountRateLimitsRead(ctx context.Context) (*protocol.GetAccountRateLimitsResponse, error)

func (*Client) AccountRead

func (*Client) AccountUsageRead

func (c *Client) AccountUsageRead(ctx context.Context) (*protocol.GetAccountTokenUsageResponse, error)

func (*Client) AccountWorkspaceMessagesRead

func (c *Client) AccountWorkspaceMessagesRead(ctx context.Context) (*protocol.GetWorkspaceMessagesResponse, error)

func (*Client) AppInstalled added in v0.147.0

func (*Client) AppList

func (*Client) AppRead added in v0.147.0

func (*Client) Call

func (c *Client) Call(ctx context.Context, method string, params any, result any) error

Call sends a JSON-RPC request and decodes the response into result.

func (*Client) Close

func (c *Client) Close() error

Close shuts down the client and transport.

func (*Client) CommandExec

func (*Client) CommandExecWrite

func (*Client) ConfigBatchWrite

func (*Client) ConfigMCPServerReload added in v0.147.0

func (c *Client) ConfigMCPServerReload(ctx context.Context) (*protocol.MCPServerRefreshResponse, error)

func (*Client) ConfigMcpServerReload deprecated

func (c *Client) ConfigMcpServerReload(ctx context.Context) (*protocol.MCPServerRefreshResponse, error)

ConfigMcpServerReload is the former spelling of ConfigMCPServerReload.

Deprecated: use ConfigMCPServerReload.

func (*Client) ConfigRead

func (*Client) ConfigRequirementsRead

func (c *Client) ConfigRequirementsRead(ctx context.Context) (*protocol.ConfigRequirementsReadResponse, error)

func (*Client) ConfigValueWrite

func (*Client) ExternalAgentConfigImportReadHistories

func (c *Client) ExternalAgentConfigImportReadHistories(ctx context.Context) (*protocol.ExternalAgentConfigImportHistoriesReadResponse, error)

func (*Client) FeedbackUpload

func (*Client) FsCopy

func (*Client) FsGetMetadata

func (*Client) FsReadDirectory

func (*Client) FsReadFile

func (*Client) FsRemove

func (*Client) FsUnwatch

func (*Client) FsWatch

func (*Client) FsWriteFile

func (*Client) FuzzyFileSearch

func (*Client) HooksList

func (*Client) Initialize

func (*Client) MCPServerOAuthLogin added in v0.147.0

func (*Client) MCPServerResourceRead added in v0.147.0

func (c *Client) MCPServerResourceRead(ctx context.Context, params protocol.MCPResourceReadParams) (*protocol.MCPResourceReadResponse, error)

func (*Client) MCPServerStatusList added in v0.147.0

func (*Client) MCPServerToolCall added in v0.147.0

func (*Client) MarketplaceAdd

func (*Client) McpServerOauthLogin deprecated

McpServerOauthLogin is the former spelling of MCPServerOAuthLogin.

Deprecated: use MCPServerOAuthLogin.

func (*Client) McpServerResourceRead deprecated

func (c *Client) McpServerResourceRead(ctx context.Context, params protocol.MCPResourceReadParams) (*protocol.MCPResourceReadResponse, error)

McpServerResourceRead is the former spelling of MCPServerResourceRead.

Deprecated: use MCPServerResourceRead.

func (*Client) McpServerStatusList deprecated

McpServerStatusList is the former spelling of MCPServerStatusList.

Deprecated: use MCPServerStatusList.

func (*Client) McpServerToolCall deprecated

McpServerToolCall is the former spelling of MCPServerToolCall.

Deprecated: use MCPServerToolCall.

func (*Client) ModelList

func (*Client) Notify

func (c *Client) Notify(ctx context.Context, method string, params any) error

Notify sends a JSON-RPC notification.

func (*Client) PluginInstall

func (*Client) PluginInstalled

func (*Client) PluginList

func (*Client) PluginRead

func (*Client) PluginShareList

func (*Client) PluginShareSave

func (*Client) PluginSkillRead

func (*Client) PluginUninstall

func (*Client) ReviewStart

func (*Client) SetRequestHandler

func (c *Client) SetRequestHandler(handler ServerRequestHandler)

SetRequestHandler replaces the server request handler.

func (*Client) SkillsList

func (*Client) SubscribeNotifications

func (c *Client) SubscribeNotifications(buffer int) *NotificationIterator

SubscribeNotifications creates an iterator over server notifications. Buffer is a hard pending-notification capacity. A non-positive value uses the default capacity of 64. If a consumer falls behind, only that iterator is closed and Next returns a NotificationOverflowError.

func (*Client) ThreadArchive

func (*Client) ThreadDelete

func (*Client) ThreadFork

func (*Client) ThreadGoalClear

func (*Client) ThreadGoalGet

func (*Client) ThreadGoalSet

func (*Client) ThreadList

func (*Client) ThreadLoadedList

func (*Client) ThreadNameSet

func (*Client) ThreadRead

func (*Client) ThreadResume

func (*Client) ThreadRollback

func (*Client) ThreadSectionCreate added in v0.147.0

func (*Client) ThreadSectionDelete added in v0.147.0

func (*Client) ThreadSectionList added in v0.147.0

func (*Client) ThreadSectionMove added in v0.147.0

func (*Client) ThreadSectionUpdate added in v0.147.0

func (*Client) ThreadStart

func (*Client) ThreadUnarchive

func (*Client) TurnInterrupt

func (*Client) TurnStart

func (*Client) TurnSteer

func (*Client) WindowsSandboxReadiness

func (c *Client) WindowsSandboxReadiness(ctx context.Context) (*protocol.WindowsSandboxReadinessResponse, error)

type ClientOptions

type ClientOptions struct {
	Logger *slog.Logger
	// RequestHandler handles app-server initiated requests. A typed-nil handler
	// is treated as nil.
	RequestHandler ServerRequestHandler
	// ServerRequestWorkers bounds concurrent app-server request handlers. Zero
	// uses the default of four.
	ServerRequestWorkers int
	// ServerRequestQueueCapacity bounds queued app-server requests. Zero uses
	// the default of 64. A full queue receives JSON-RPC code -32001.
	ServerRequestQueueCapacity int
	// MaxMessageBytes bounds each inbound JSON-RPC payload. Zero uses
	// DefaultMaxMessageBytes. This client-side check covers custom transports;
	// built-in transports always retain DefaultMaxMessageBytes as a safety
	// ceiling, so a larger value does not raise their limit. Custom transports
	// must bound allocation inside ReadLine before returning the payload.
	MaxMessageBytes int
}

ClientOptions configures a low-level JSON-RPC client.

type ClientRequests deprecated

type ClientRequests interface {
	AccountLoginCancel(ctx context.Context, params protocol.CancelLoginAccountParams) (*protocol.CancelLoginAccountResponse, error)
	AccountLoginStart(ctx context.Context, params protocol.LoginAccountParams) (*protocol.LoginAccountResponse, error)
	AccountLogout(ctx context.Context) (*protocol.LogoutAccountResponse, error)
	AccountRateLimitResetCreditConsume(ctx context.Context, params protocol.ConsumeAccountRateLimitResetCreditParams) (*protocol.ConsumeAccountRateLimitResetCreditResponse, error)
	AccountRateLimitsRead(ctx context.Context) (*protocol.GetAccountRateLimitsResponse, error)
	AccountRead(ctx context.Context, params protocol.GetAccountParams) (*protocol.GetAccountResponse, error)
	AccountSendAddCreditsNudgeEmail(ctx context.Context, params protocol.SendAddCreditsNudgeEmailParams) (*protocol.SendAddCreditsNudgeEmailResponse, error)
	AccountUsageRead(ctx context.Context) (*protocol.GetAccountTokenUsageResponse, error)
	AccountWorkspaceMessagesRead(ctx context.Context) (*protocol.GetWorkspaceMessagesResponse, error)
	AppInstalled(ctx context.Context, params protocol.AppsInstalledParams) (*protocol.AppsInstalledResponse, error)
	AppList(ctx context.Context, params protocol.AppsListParams) (*protocol.AppsListResponse, error)
	AppRead(ctx context.Context, params protocol.AppsReadParams) (*protocol.AppsReadResponse, error)
	CommandExec(ctx context.Context, params protocol.CommandExecParams) (*protocol.CommandExecResponse, error)
	CommandExecResize(ctx context.Context, params protocol.CommandExecResizeParams) (*protocol.CommandExecResizeResponse, error)
	CommandExecTerminate(ctx context.Context, params protocol.CommandExecTerminateParams) (*protocol.CommandExecTerminateResponse, error)
	CommandExecWrite(ctx context.Context, params protocol.CommandExecWriteParams) (*protocol.CommandExecWriteResponse, error)
	ConfigBatchWrite(ctx context.Context, params protocol.ConfigBatchWriteParams) (*protocol.ConfigWriteResponse, error)
	ConfigMCPServerReload(ctx context.Context) (*protocol.MCPServerRefreshResponse, error)
	ConfigRead(ctx context.Context, params protocol.ConfigReadParams) (*protocol.ConfigReadResponse, error)
	ConfigValueWrite(ctx context.Context, params protocol.ConfigValueWriteParams) (*protocol.ConfigWriteResponse, error)
	ConfigRequirementsRead(ctx context.Context) (*protocol.ConfigRequirementsReadResponse, error)
	ExperimentalFeatureEnablementSet(ctx context.Context, params protocol.ExperimentalFeatureEnablementSetParams) (*protocol.ExperimentalFeatureEnablementSetResponse, error)
	ExperimentalFeatureList(ctx context.Context, params protocol.ExperimentalFeatureListParams) (*protocol.ExperimentalFeatureListResponse, error)
	ExternalAgentConfigDetect(ctx context.Context, params protocol.ExternalAgentConfigDetectParams) (*protocol.ExternalAgentConfigDetectResponse, error)
	ExternalAgentConfigImport(ctx context.Context, params protocol.ExternalAgentConfigImportParams) (*protocol.ExternalAgentConfigImportResponse, error)
	ExternalAgentConfigImportReadHistories(ctx context.Context) (*protocol.ExternalAgentConfigImportHistoriesReadResponse, error)
	ExternalAgentConfigImportRecordHistory(ctx context.Context, params protocol.ExternalAgentConfigImportHistoryRecordParams) (*protocol.ExternalAgentConfigImportHistoryRecordResponse, error)
	FeedbackUpload(ctx context.Context, params protocol.FeedbackUploadParams) (*protocol.FeedbackUploadResponse, error)
	FsCopy(ctx context.Context, params protocol.FsCopyParams) (*protocol.FsCopyResponse, error)
	FsCreateDirectory(ctx context.Context, params protocol.FsCreateDirectoryParams) (*protocol.FsCreateDirectoryResponse, error)
	FsGetMetadata(ctx context.Context, params protocol.FsGetMetadataParams) (*protocol.FsGetMetadataResponse, error)
	FsReadDirectory(ctx context.Context, params protocol.FsReadDirectoryParams) (*protocol.FsReadDirectoryResponse, error)
	FsReadFile(ctx context.Context, params protocol.FsReadFileParams) (*protocol.FsReadFileResponse, error)
	FsRemove(ctx context.Context, params protocol.FsRemoveParams) (*protocol.FsRemoveResponse, error)
	FsUnwatch(ctx context.Context, params protocol.FsUnwatchParams) (*protocol.FsUnwatchResponse, error)
	FsWatch(ctx context.Context, params protocol.FsWatchParams) (*protocol.FsWatchResponse, error)
	FsWriteFile(ctx context.Context, params protocol.FsWriteFileParams) (*protocol.FsWriteFileResponse, error)
	FuzzyFileSearch(ctx context.Context, params protocol.FuzzyFileSearchParams) (*protocol.FuzzyFileSearchResponse, error)
	HooksList(ctx context.Context, params protocol.HooksListParams) (*protocol.HooksListResponse, error)
	Initialize(ctx context.Context, params protocol.InitializeParams) (*protocol.InitializeResponse, error)
	MarketplaceAdd(ctx context.Context, params protocol.MarketplaceAddParams) (*protocol.MarketplaceAddResponse, error)
	MarketplaceRemove(ctx context.Context, params protocol.MarketplaceRemoveParams) (*protocol.MarketplaceRemoveResponse, error)
	MarketplaceUpgrade(ctx context.Context, params protocol.MarketplaceUpgradeParams) (*protocol.MarketplaceUpgradeResponse, error)
	MCPServerOAuthLogin(ctx context.Context, params protocol.MCPServerOAuthLoginParams) (*protocol.MCPServerOAuthLoginResponse, error)
	MCPServerResourceRead(ctx context.Context, params protocol.MCPResourceReadParams) (*protocol.MCPResourceReadResponse, error)
	MCPServerToolCall(ctx context.Context, params protocol.MCPServerToolCallParams) (*protocol.MCPServerToolCallResponse, error)
	MCPServerStatusList(ctx context.Context, params protocol.ListMCPServerStatusParams) (*protocol.ListMCPServerStatusResponse, error)
	ModelList(ctx context.Context, params protocol.ModelListParams) (*protocol.ModelListResponse, error)
	ModelProviderCapabilitiesRead(ctx context.Context, params protocol.ModelProviderCapabilitiesReadParams) (*protocol.ModelProviderCapabilitiesReadResponse, error)
	PermissionProfileList(ctx context.Context, params protocol.PermissionProfileListParams) (*protocol.PermissionProfileListResponse, error)
	PluginInstall(ctx context.Context, params protocol.PluginInstallParams) (*protocol.PluginInstallResponse, error)
	PluginInstalled(ctx context.Context, params protocol.PluginInstalledParams) (*protocol.PluginInstalledResponse, error)
	PluginList(ctx context.Context, params protocol.PluginListParams) (*protocol.PluginListResponse, error)
	PluginRead(ctx context.Context, params protocol.PluginReadParams) (*protocol.PluginReadResponse, error)
	PluginShareCheckout(ctx context.Context, params protocol.PluginShareCheckoutParams) (*protocol.PluginShareCheckoutResponse, error)
	PluginShareDelete(ctx context.Context, params protocol.PluginShareDeleteParams) (*protocol.PluginShareDeleteResponse, error)
	PluginShareList(ctx context.Context, params protocol.PluginShareListParams) (*protocol.PluginShareListResponse, error)
	PluginShareSave(ctx context.Context, params protocol.PluginShareSaveParams) (*protocol.PluginShareSaveResponse, error)
	PluginShareUpdateTargets(ctx context.Context, params protocol.PluginShareUpdateTargetsParams) (*protocol.PluginShareUpdateTargetsResponse, error)
	PluginSkillRead(ctx context.Context, params protocol.PluginSkillReadParams) (*protocol.PluginSkillReadResponse, error)
	PluginUninstall(ctx context.Context, params protocol.PluginUninstallParams) (*protocol.PluginUninstallResponse, error)
	ReviewStart(ctx context.Context, params protocol.ReviewStartParams) (*protocol.ReviewStartResponse, error)
	SkillsConfigWrite(ctx context.Context, params protocol.SkillsConfigWriteParams) (*protocol.SkillsConfigWriteResponse, error)
	SkillsExtraRootsSet(ctx context.Context, params protocol.SkillsExtraRootsSetParams) (*protocol.SkillsExtraRootsSetResponse, error)
	SkillsList(ctx context.Context, params protocol.SkillsListParams) (*protocol.SkillsListResponse, error)
	ThreadApproveGuardianDeniedAction(ctx context.Context, params protocol.ThreadApproveGuardianDeniedActionParams) (*protocol.ThreadApproveGuardianDeniedActionResponse, error)
	ThreadArchive(ctx context.Context, params protocol.ThreadArchiveParams) (*protocol.ThreadArchiveResponse, error)
	ThreadCompactStart(ctx context.Context, params protocol.ThreadCompactStartParams) (*protocol.ThreadCompactStartResponse, error)
	ThreadDelete(ctx context.Context, params protocol.ThreadDeleteParams) (*protocol.ThreadDeleteResponse, error)
	ThreadFork(ctx context.Context, params protocol.ThreadForkParams) (*protocol.ThreadForkResponse, error)
	ThreadGoalClear(ctx context.Context, params protocol.ThreadGoalClearParams) (*protocol.ThreadGoalClearResponse, error)
	ThreadGoalGet(ctx context.Context, params protocol.ThreadGoalGetParams) (*protocol.ThreadGoalGetResponse, error)
	ThreadGoalSet(ctx context.Context, params protocol.ThreadGoalSetParams) (*protocol.ThreadGoalSetResponse, error)
	ThreadInjectItems(ctx context.Context, params protocol.ThreadInjectItemsParams) (*protocol.ThreadInjectItemsResponse, error)
	ThreadList(ctx context.Context, params protocol.ThreadListParams) (*protocol.ThreadListResponse, error)
	ThreadLoadedList(ctx context.Context, params protocol.ThreadLoadedListParams) (*protocol.ThreadLoadedListResponse, error)
	ThreadMetadataUpdate(ctx context.Context, params protocol.ThreadMetadataUpdateParams) (*protocol.ThreadMetadataUpdateResponse, error)
	ThreadNameSet(ctx context.Context, params protocol.ThreadSetNameParams) (*protocol.ThreadSetNameResponse, error)
	ThreadRead(ctx context.Context, params protocol.ThreadReadParams) (*protocol.ThreadReadResponse, error)
	ThreadResume(ctx context.Context, params protocol.ThreadResumeParams) (*protocol.ThreadResumeResponse, error)
	ThreadRollback(ctx context.Context, params protocol.ThreadRollbackParams) (*protocol.ThreadRollbackResponse, error)
	ThreadSectionMove(ctx context.Context, params protocol.ThreadSectionMoveParams) (*protocol.ThreadSectionMoveResponse, error)
	ThreadShellCommand(ctx context.Context, params protocol.ThreadShellCommandParams) (*protocol.ThreadShellCommandResponse, error)
	ThreadStart(ctx context.Context, params protocol.ThreadStartParams) (*protocol.ThreadStartResponse, error)
	ThreadUnarchive(ctx context.Context, params protocol.ThreadUnarchiveParams) (*protocol.ThreadUnarchiveResponse, error)
	ThreadUnsubscribe(ctx context.Context, params protocol.ThreadUnsubscribeParams) (*protocol.ThreadUnsubscribeResponse, error)
	ThreadSectionCreate(ctx context.Context, params protocol.ThreadSectionCreateParams) (*protocol.ThreadSectionCreateResponse, error)
	ThreadSectionDelete(ctx context.Context, params protocol.ThreadSectionDeleteParams) (*protocol.ThreadSectionDeleteResponse, error)
	ThreadSectionList(ctx context.Context, params protocol.ThreadSectionListParams) (*protocol.ThreadSectionListResponse, error)
	ThreadSectionUpdate(ctx context.Context, params protocol.ThreadSectionUpdateParams) (*protocol.ThreadSectionUpdateResponse, error)
	TurnInterrupt(ctx context.Context, params protocol.TurnInterruptParams) (*protocol.TurnInterruptResponse, error)
	TurnStart(ctx context.Context, params protocol.TurnStartParams) (*protocol.TurnStartResponse, error)
	TurnSteer(ctx context.Context, params protocol.TurnSteerParams) (*protocol.TurnSteerResponse, error)
	WindowsSandboxReadiness(ctx context.Context) (*protocol.WindowsSandboxReadinessResponse, error)
	WindowsSandboxSetupStart(ctx context.Context, params protocol.WindowsSandboxSetupStartParams) (*protocol.WindowsSandboxSetupStartResponse, error)
}

ClientRequests exposes every generated JSON-RPC call supported by the app-server.

Deprecated: define a narrow interface containing only the methods your code consumes.

type ConnTransport

type ConnTransport struct {
	// contains filtered or unexported fields
}

ConnTransport wraps an io.ReadWriteCloser.

func NewConnTransport

func NewConnTransport(conn io.ReadWriteCloser) *ConnTransport

NewConnTransport wraps the connection in a Transport. It panics if conn is nil. Use NewConnTransportChecked when the dependency is not statically known.

func NewConnTransportChecked added in v0.147.0

func NewConnTransportChecked(conn io.ReadWriteCloser) (*ConnTransport, error)

NewConnTransportChecked wraps the connection in a Transport.

func (*ConnTransport) Close

func (t *ConnTransport) Close() error

Close closes the connection.

func (*ConnTransport) ReadLine

func (t *ConnTransport) ReadLine() (string, error)

ReadLine reads a line from the connection.

func (*ConnTransport) WriteLine

func (t *ConnTransport) WriteLine(line string) error

WriteLine writes a line to the connection.

type ContextTransport added in v0.147.0

type ContextTransport interface {
	Transport
	WriteLineContext(ctx context.Context, line string) error
}

ContextTransport is an optional Transport capability for writes that can be interrupted when their request context ends. Client also bounds callers that use a legacy Transport, but the underlying legacy write can remain blocked until Transport.Close unblocks it.

type JSONRPCError

type JSONRPCError struct {
	ID    RequestID          `json:"id"`
	Error JSONRPCErrorDetail `json:"error"`
}

JSONRPCError represents a JSON-RPC error response.

type JSONRPCErrorDetail added in v0.147.0

type JSONRPCErrorDetail struct {
	Code    int64           `json:"code"`
	Message string          `json:"message"`
	Data    json.RawMessage `json:"data,omitempty"`
}

JSONRPCErrorDetail describes the error payload.

type JSONRPCErrorError deprecated

type JSONRPCErrorError = JSONRPCErrorDetail

JSONRPCErrorError is the former name of JSONRPCErrorDetail.

Deprecated: use JSONRPCErrorDetail.

type JSONRPCNotification

type JSONRPCNotification struct {
	Method string          `json:"method"`
	Params json.RawMessage `json:"params,omitempty"`
}

JSONRPCNotification represents a JSON-RPC notification.

type JSONRPCRequest

type JSONRPCRequest struct {
	ID     RequestID       `json:"id"`
	Method string          `json:"method"`
	Params json.RawMessage `json:"params,omitempty"`
}

JSONRPCRequest represents a JSON-RPC request.

func BuildClientRequest

func BuildClientRequest(method string, params any, id RequestID) (JSONRPCRequest, error)

BuildClientRequest builds a JSON-RPC request for a client method.

type JSONRPCResponse

type JSONRPCResponse struct {
	ID     RequestID       `json:"id"`
	Result json.RawMessage `json:"result"`
}

JSONRPCResponse represents a JSON-RPC response.

type MCPServerElicitationRequestHandler added in v0.147.0

type MCPServerElicitationRequestHandler interface {
	MCPServerElicitationRequest(ctx context.Context, params protocol.MCPServerElicitationRequestParams) (*protocol.MCPServerElicitationRequestResponse, error)
}

MCPServerElicitationRequestHandler handles mcpServer/elicitation/request using canonical Go initialisms.

type Notification

type Notification struct {
	Method string
	Params any
	Raw    json.RawMessage
}

Notification represents a typed server notification.

func (Notification) UnmarshalParams

func (n Notification) UnmarshalParams(v any) error

UnmarshalParams decodes the raw notification params into v.

type NotificationIterator

type NotificationIterator struct {
	// contains filtered or unexported fields
}

NotificationIterator iterates notifications from the server.

func (*NotificationIterator) Close

func (it *NotificationIterator) Close()

Close unsubscribes the iterator.

func (*NotificationIterator) Next

Next returns the next notification or an error.

type NotificationOverflowError added in v0.145.0

type NotificationOverflowError struct {
	Capacity int
}

NotificationOverflowError reports the hard capacity of an overflowing notification subscription.

func (*NotificationOverflowError) Error added in v0.145.0

func (e *NotificationOverflowError) Error() string

func (*NotificationOverflowError) Is added in v0.145.0

func (e *NotificationOverflowError) Is(target error) bool

Is allows errors.Is(err, ErrNotificationOverflow).

type RecordTransport

type RecordTransport struct {
	// contains filtered or unexported fields
}

RecordTransport records all JSON-RPC traffic to a transcript.

func NewRecordTransport

func NewRecordTransport(transport Transport) *RecordTransport

NewRecordTransport wraps a transport and records traffic. It panics if transport is nil. Use NewRecordTransportChecked when the dependency is not statically known.

func NewRecordTransportChecked added in v0.147.0

func NewRecordTransportChecked(transport Transport) (*RecordTransport, error)

NewRecordTransportChecked wraps a validated transport and records traffic.

func NewRercordTransport deprecated

func NewRercordTransport(transport Transport) *RecordTransport

NewRercordTransport wraps a transport and records traffic.

Deprecated: use NewRecordTransport.

func (*RecordTransport) Close

func (t *RecordTransport) Close() error

Close closes the underlying transport.

func (*RecordTransport) ReadLine

func (t *RecordTransport) ReadLine() (string, error)

ReadLine reads from the underlying transport and records the line.

func (*RecordTransport) Transcript

func (t *RecordTransport) Transcript() []TranscriptEntry

Transcript returns a copy of the recorded transcript.

func (*RecordTransport) WriteLine

func (t *RecordTransport) WriteLine(line string) error

WriteLine writes to the underlying transport and records the line.

type ReplayTransport

type ReplayTransport struct {
	// contains filtered or unexported fields
}

ReplayTransport replays a transcript of line-delimited JSON-RPC payloads. JSON writes are compared by value (after normalization) to tolerate key ordering differences.

func NewReplayTransport

func NewReplayTransport(transcript []TranscriptEntry) *ReplayTransport

NewReplayTransport creates a ReplayTransport for a transcript. It panics if the transcript contains an unsupported direction.

func NewReplayTransportChecked added in v0.147.0

func NewReplayTransportChecked(transcript []TranscriptEntry) (*ReplayTransport, error)

NewReplayTransportChecked creates a ReplayTransport after validating every transcript entry.

func (*ReplayTransport) Close

func (t *ReplayTransport) Close() error

Close stops the replay transport.

func (*ReplayTransport) ReadLine

func (t *ReplayTransport) ReadLine() (string, error)

ReadLine returns the next recorded read line.

func (*ReplayTransport) WriteLine

func (t *ReplayTransport) WriteLine(line string) error

WriteLine validates the next recorded write line.

type RequestID

type RequestID struct {
	// contains filtered or unexported fields
}

RequestID represents a JSON-RPC request id (string or integer).

func NewIntRequestID

func NewIntRequestID(value int64) RequestID

NewIntRequestID creates an integer request id.

func NewStringRequestID

func NewStringRequestID(value string) RequestID

NewStringRequestID creates a string request id.

func (RequestID) IsZero

func (id RequestID) IsZero() bool

IsZero reports whether the id is unset.

func (RequestID) Key

func (id RequestID) Key() string

Key returns a stable string key for map usage.

func (RequestID) MarshalJSON

func (id RequestID) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (RequestID) String

func (id RequestID) String() string

String returns a printable representation.

func (*RequestID) UnmarshalJSON

func (id *RequestID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type RercordTransport deprecated

type RercordTransport = RecordTransport

RercordTransport is a misspelled alias for RecordTransport.

Deprecated: use RecordTransport.

type ResponseError

type ResponseError struct {
	ID     RequestID
	Detail JSONRPCErrorDetail
}

ResponseError wraps a JSON-RPC error as a Go error.

func (*ResponseError) Error

func (err *ResponseError) Error() string

type ServerRequestHandler deprecated

ServerRequestHandler handles requests initiated by the app-server. Embed UnimplementedServerRequestHandler so newly added methods do not break implementations. Canonical-initialism capability interfaces take precedence over legacy method spellings.

Deprecated: embed UnimplementedServerRequestHandler and override only required methods.

type ServerRequestHandlerError added in v0.147.0

type ServerRequestHandlerError struct {
	Method string
	Err    error
}

ServerRequestHandlerError reports an error returned by an application handler.

func (*ServerRequestHandlerError) Error added in v0.147.0

func (e *ServerRequestHandlerError) Error() string

func (*ServerRequestHandlerError) Unwrap added in v0.147.0

func (e *ServerRequestHandlerError) Unwrap() error

type ServerRequestMethodError added in v0.147.0

type ServerRequestMethodError struct{ Method string }

ServerRequestMethodError reports an unsupported server-request method.

func (*ServerRequestMethodError) Error added in v0.147.0

func (e *ServerRequestMethodError) Error() string

type ServerRequestParamsError added in v0.147.0

type ServerRequestParamsError struct {
	Method string
	Err    error
}

ServerRequestParamsError reports parameters that could not be decoded.

func (*ServerRequestParamsError) Error added in v0.147.0

func (e *ServerRequestParamsError) Error() string

func (*ServerRequestParamsError) Unwrap added in v0.147.0

func (e *ServerRequestParamsError) Unwrap() error

type StdioTransport

type StdioTransport struct {
	// contains filtered or unexported fields
}

StdioTransport wraps a spawned process using stdin/stdout JSONL.

func SpawnStdio

func SpawnStdio(ctx context.Context, binary string, args []string, stderr io.Writer) (*StdioTransport, error)

SpawnStdio starts a command and uses its stdin/stdout for JSON-RPC.

func (*StdioTransport) Close

func (t *StdioTransport) Close() error

Close shuts down the process.

func (*StdioTransport) ReadLine

func (t *StdioTransport) ReadLine() (string, error)

ReadLine reads a single line from stdout.

func (*StdioTransport) WriteLine

func (t *StdioTransport) WriteLine(line string) error

WriteLine writes a single line to stdin.

type TranscriptDirection

type TranscriptDirection string

TranscriptDirection describes the direction of a recorded line.

const (
	TranscriptRead  TranscriptDirection = "read"
	TranscriptWrite TranscriptDirection = "write"
)

type TranscriptEntry

type TranscriptEntry struct {
	Direction TranscriptDirection `json:"direction"`
	Line      string              `json:"line"`
}

TranscriptEntry stores a single JSON-RPC line and its direction.

type Transport

type Transport interface {
	ReadLine() (string, error)
	WriteLine(line string) error
	Close() error
}

Transport reads and writes JSON-RPC lines. ReadLine implementations must enforce a finite allocation limit and should return ErrMessageTooLarge when it is exceeded; implementations backed by bufio.Reader can use ReadLineLimited. Implementations should not block WriteLine indefinitely, and Close must unblock in-flight reads and writes so bounded SDK cleanup cannot leave transport goroutines running.

type UnimplementedServerRequestHandler added in v0.147.0

type UnimplementedServerRequestHandler struct{}

UnimplementedServerRequestHandler provides forward-compatible default methods.

func (UnimplementedServerRequestHandler) AccountChatgptAuthTokensRefresh added in v0.147.0

func (UnimplementedServerRequestHandler) ApplyPatchApproval added in v0.147.0

func (UnimplementedServerRequestHandler) AttestationGenerate added in v0.147.0

func (UnimplementedServerRequestHandler) ExecCommandApproval added in v0.147.0

func (UnimplementedServerRequestHandler) ItemFileChangeRequestApproval added in v0.147.0

func (UnimplementedServerRequestHandler) ItemPermissionsRequestApproval added in v0.147.0

func (UnimplementedServerRequestHandler) ItemToolCall added in v0.147.0

func (UnimplementedServerRequestHandler) ItemToolRequestUserInput added in v0.147.0

func (UnimplementedServerRequestHandler) McpServerElicitationRequest added in v0.147.0

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL