Documentation
¶
Overview ¶
Package upstream turns a tool call into an HTTP request to the API behind writgate, and the HTTP response back into an MCP tool result (docs/SPEC.md section 3).
A call happens in three steps so the audit log can sit between them: Prepare validates the arguments and builds the request without sending it (the audit "intent" is written from it), Send performs it, and Result maps the response (the audit "outcome" is written alongside).
Index ¶
Constants ¶
const IdempotencyHeader = "Idempotency-Key"
IdempotencyHeader is the header recovery uses to find a call's result.
const MaxResponseBytes = 10 << 20
MaxResponseBytes caps how much of an upstream response is read.
const Redacted = "[redacted]"
Redacted stands in for a sensitive value wherever a request or response is written down.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client sends tool calls to one upstream API.
func New ¶
New returns a Client for the API at baseURL, e.g. "https://api.example.com/v1".
func (*Client) Call ¶
func (c *Client) Call(ctx context.Context, t *tools.Tool, rawArgs json.RawMessage) *mcp.CallToolResult
Call is the whole call for a server with no audit log: Prepare, Send, Result.
func (*Client) Prepare ¶
func (c *Client) Prepare(t *tools.Tool, rawArgs json.RawMessage) (*Prepared, *mcp.CallToolResult)
Prepare validates the arguments against the tool's input schema and builds the request. On invalid arguments it returns an error result and nothing is sent.
type Options ¶
type Options struct {
// APIKey is sent as "Authorization: Bearer <key>". It comes from
// writgate's environment and never from the agent.
APIKey string
// Timeout bounds each upstream request. Zero means 30 seconds.
Timeout time.Duration
// UserAgent is sent with every request.
UserAgent string
}
Options configures a Client.
type Prepared ¶
type Prepared struct {
Tool *tools.Tool
Args map[string]any
Method string
Path string // the resolved path, e.g. "/charges/ch_1/refunds"
URL string // full URL, without credentials
SafeURL string // URL with the values of sensitive arguments replaced by Redacted
Header http.Header
Body []byte // nil when there is no body
IdempotencyKey string // empty when the call has none
}
Prepared is a validated request that has not been sent. It holds no credentials. URL can still hold sensitive argument values; SafeURL is the one to write down.