transport

package
v1.0.63 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// Security headers
	HeaderSource       = "X-Cli-Source"
	HeaderVersion      = "X-Cli-Version"
	HeaderExecutionId  = "X-Cli-Execution-Id"
	HeaderAgentVersion = "x-dws-agent-ver"
	HeaderAgentExt     = "x-dws-agent-ext"
	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) ListToolsPage added in v1.0.62

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

func (*Client) NotifyInitialized

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

func (*Client) ValidateTrustedEndpoint added in v1.0.62

func (c *Client) ValidateTrustedEndpoint(endpoint string) error

ValidateTrustedEndpoint rejects network destinations that are outside the configured MCP trust boundary before any request or credential is sent.

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.

func (*Client) WithHTTPTimeout added in v1.0.62

func (c *Client) WithHTTPTimeout(timeout time.Duration) *Client

WithHTTPTimeout returns a transport client with an independently cloned HTTP client. A standard transport is cloned too so its response-header deadline cannot end a caller's larger operation timeout early.

func (*Client) WithMaxRetries added in v1.0.62

func (c *Client) WithMaxRetries(maxRetries int) *Client

WithMaxRetries returns a copy of c with an independent retry limit. It is useful when a caller knows a request cannot be retried safely.

func (*Client) WithRedirectsDisabled added in v1.0.62

func (c *Client) WithRedirectsDisabled() *Client

WithRedirectsDisabled exposes 3xx responses instead of allowing net/http to replay a POST body at a redirect target.

type ContentBlock

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

func (*ContentBlock) UnmarshalJSON added in v1.0.62

func (b *ContentBlock) UnmarshalJSON(data []byte) error

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"`
}

func (*RPCError) UnmarshalJSON added in v1.0.62

func (e *RPCError) UnmarshalJSON(data []byte) error

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) EnsureInitialized added in v1.0.52

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

EnsureInitialized lazily starts the subprocess and performs the MCP initialize handshake exactly once for the current process lifecycle.

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. A non-zero exit code after Kill is expected and not treated as an error.

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"`
	RawResult         json.RawMessage `json:"-"`
}

func (ToolCallResult) MarshalJSON added in v1.0.62

func (r ToolCallResult) MarshalJSON() ([]byte, error)

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"`
}

func (*ToolDescriptor) UnmarshalJSON added in v1.0.62

func (t *ToolDescriptor) UnmarshalJSON(data []byte) error

type ToolsListResult

type ToolsListResult struct {
	Tools            []ToolDescriptor `json:"tools"`
	NextCursor       string           `json:"nextCursor,omitempty"`
	RawResultBytes   int              `json:"-"`
	RawResponseBytes int              `json:"-"`
}

func (*ToolsListResult) UnmarshalJSON added in v1.0.62

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

Jump to

Keyboard shortcuts

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