transport

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// Security headers
	HeaderSource      = "X-Cli-Source"
	HeaderVersion     = "X-Cli-Version"
	HeaderExecutionId = "X-Cli-Execution-Id"
	SourceValue       = "dws-cli"
)

Variables

This section is empty.

Functions

func ExtractServerDiagnostics added in v1.0.5

func ExtractServerDiagnostics(data json.RawMessage) apperrors.ServerDiagnostics

ExtractServerDiagnostics parses server diagnostic fields from a JSON payload (typically from RPCError.Data). Returns an empty struct if the payload is empty or unparseable.

func ExtractServerDiagnosticsFromMap added in v1.0.5

func ExtractServerDiagnosticsFromMap(content map[string]any) apperrors.ServerDiagnostics

ExtractServerDiagnosticsFromMap parses server diagnostic fields from a map[string]any (typically from ToolCallResult.Content for business errors).

func ExtractTraceIDFromHeaders added in v1.0.5

func ExtractTraceIDFromHeaders(headers http.Header) string

ExtractTraceIDFromHeaders reads a trace ID from standard HTTP response headers. Returns empty string if none found.

func RedactURL

func RedactURL(raw string) string

func SupportedProtocolVersions

func SupportedProtocolVersions() []string

Types

type CallError

type CallError struct {
	Stage      CallStage
	HTTPStatus int
	RetryAfter string
	TraceID    string
	RequestID  string
	RPCCode    int
	Cause      error
}

CallError carries recoverable transport metadata without changing the repository-local structured error contract.

func (*CallError) Error

func (e *CallError) Error() string

func (*CallError) Unwrap

func (e *CallError) Unwrap() error

type CallStage

type CallStage string
const (
	CallStageRequest CallStage = "request"
	CallStageHTTP    CallStage = "http"
	CallStageJSONRPC CallStage = "jsonrpc"
)

type Client

type Client struct {
	HTTPClient       *http.Client
	MaxRetries       int
	RetryDelay       time.Duration
	RetryMaxDelay    time.Duration
	AuthToken        string
	ExtraHeaders     map[string]string
	SnapshotRecorder SnapshotRecorder
	TrustedDomains   []string
	ExecutionId      string       // Request tracing ID for debugging
	FileLogger       *slog.Logger // Structured file logger for diagnostics (nil-safe).

	// Stderr is the writer for warning messages. Defaults to os.Stderr.
	Stderr io.Writer
	// contains filtered or unexported fields
}

func NewClient

func NewClient(httpClient *http.Client) *Client

func (*Client) CallTool

func (c *Client) CallTool(ctx context.Context, endpoint, tool string, arguments map[string]any) (ToolCallResult, error)

func (*Client) Initialize

func (c *Client) Initialize(ctx context.Context, endpoint string) (InitializeResult, error)

func (*Client) ListTools

func (c *Client) ListTools(ctx context.Context, endpoint string) (ToolsListResult, error)

func (*Client) NotifyInitialized

func (c *Client) NotifyInitialized(ctx context.Context, endpoint string) error

func (*Client) WithAuth

func (c *Client) WithAuth(token string, headers map[string]string) *Client

WithAuth returns a shallow copy of c with the given auth token and extra headers. The returned client shares the underlying HTTP client but is safe to use concurrently with the original.

func (*Client) WithExecutionId

func (c *Client) WithExecutionId(executionId string) *Client

WithExecutionId returns a shallow copy of c with the given execution ID. The execution ID is included in requests for tracing and debugging.

type ContentBlock

type ContentBlock struct {
	Type string `json:"type"`
	Text string `json:"text,omitempty"`
}

type InitializeResult

type InitializeResult struct {
	RequestedProtocolVersion string         `json:"requested_protocol_version"`
	ProtocolVersion          string         `json:"protocol_version"`
	Capabilities             map[string]any `json:"capabilities"`
	ServerInfo               map[string]any `json:"server_info"`
}

type RPCError

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

type SnapshotRecorder

type SnapshotRecorder interface {
	RecordJSONRPC(method, endpoint string, requestBody, responseBody []byte) string
}

type StdioClient added in v1.0.9

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

StdioClient manages a local MCP server subprocess, communicating via stdin/stdout using JSON-RPC 2.0 (newline-delimited).

func NewStdioClient added in v1.0.9

func NewStdioClient(command string, args []string, env map[string]string) *StdioClient

NewStdioClient creates a StdioClient for the given command. The subprocess is not started until Start() is called.

func (*StdioClient) CallTool added in v1.0.9

func (s *StdioClient) CallTool(ctx context.Context, tool string, arguments map[string]any) (ToolCallResult, error)

CallTool sends the tools/call JSON-RPC request.

func (*StdioClient) Initialize added in v1.0.9

func (s *StdioClient) Initialize(ctx context.Context) (InitializeResult, error)

Initialize sends the JSON-RPC initialize request.

func (*StdioClient) ListTools added in v1.0.9

func (s *StdioClient) ListTools(ctx context.Context) (ToolsListResult, error)

ListTools sends the tools/list JSON-RPC request.

func (*StdioClient) Start added in v1.0.9

func (s *StdioClient) Start(ctx context.Context) error

Start launches the subprocess.

func (*StdioClient) Stop added in v1.0.9

func (s *StdioClient) Stop() error

Stop kills the subprocess and waits for it to exit.

type ToolCallResult

type ToolCallResult struct {
	Content           map[string]any `json:"-"`
	StructuredContent map[string]any `json:"structuredContent,omitempty"`
	Blocks            []ContentBlock `json:"content,omitempty"`
	IsError           bool           `json:"isError,omitempty"`
}

func (*ToolCallResult) UnmarshalJSON

func (r *ToolCallResult) UnmarshalJSON(data []byte) error

type ToolDescriptor

type ToolDescriptor struct {
	Name         string         `json:"name"`
	Title        string         `json:"title"`
	Description  string         `json:"description"`
	InputSchema  map[string]any `json:"inputSchema"`
	OutputSchema map[string]any `json:"outputSchema,omitempty"`
	Sensitive    bool           `json:"sensitive,omitempty"`
}

type ToolsListResult

type ToolsListResult struct {
	Tools []ToolDescriptor `json:"tools"`
}

Jump to

Keyboard shortcuts

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