Documentation
¶
Index ¶
- Constants
- func ExtractServerDiagnostics(data json.RawMessage) apperrors.ServerDiagnostics
- func ExtractServerDiagnosticsFromMap(content map[string]any) apperrors.ServerDiagnostics
- func ExtractTraceIDFromHeaders(headers http.Header) string
- func RedactURL(raw string) string
- func SupportedProtocolVersions() []string
- type CallError
- type CallStage
- type Client
- func (c *Client) CallTool(ctx context.Context, endpoint, tool string, arguments map[string]any) (ToolCallResult, error)
- func (c *Client) Initialize(ctx context.Context, endpoint string) (InitializeResult, error)
- func (c *Client) ListTools(ctx context.Context, endpoint string) (ToolsListResult, error)
- func (c *Client) NotifyInitialized(ctx context.Context, endpoint string) error
- func (c *Client) WithAuth(token string, headers map[string]string) *Client
- func (c *Client) WithExecutionId(executionId string) *Client
- type ContentBlock
- type InitializeResult
- type RPCError
- type SnapshotRecorder
- type StdioClient
- func (s *StdioClient) CallTool(ctx context.Context, tool string, arguments map[string]any) (ToolCallResult, error)
- func (s *StdioClient) Initialize(ctx context.Context) (InitializeResult, error)
- func (s *StdioClient) ListTools(ctx context.Context) (ToolsListResult, error)
- func (s *StdioClient) Start(ctx context.Context) error
- func (s *StdioClient) Stop() error
- type ToolCallResult
- type ToolDescriptor
- type ToolsListResult
Constants ¶
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
ExtractTraceIDFromHeaders reads a trace ID from standard HTTP response headers. Returns empty string if none found.
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.
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 (*Client) Initialize ¶
func (*Client) NotifyInitialized ¶
func (*Client) WithAuth ¶
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 ¶
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 InitializeResult ¶
type RPCError ¶
type RPCError struct {
Code int `json:"code"`
Message string `json:"message"`
Data json.RawMessage `json:"data,omitempty"`
}
type SnapshotRecorder ¶
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 ToolsListResult ¶
type ToolsListResult struct {
Tools []ToolDescriptor `json:"tools"`
}