Documentation
¶
Overview ¶
Package appmcp is the stdio side of the harnessly-app MCP server: a child of the agent that passes its JSON-RPC to the runtime over HTTP and outlives the runtime's restarts.
An agent that talks to the runtime's Streamable HTTP endpoint itself loses the server at a release. Claude Code reopens the GET stream once the runtime is gone; a runtime that is still starting answers 405 (it cannot place the caller in a chat yet), which the client takes for "this server has no stream" and never asks again, so tools/list_changed stops for the rest of the chat; and a runtime that stays down past the client's few attempts is dropped altogether. A stdio server stays connected for as long as its process lives, so the waiting is done here: the stream is reopened with pauses for ever, the client is told to ask tools/list again after every reopening, and a call made while the runtime is away waits for it.
Index ¶
Constants ¶
const ( EnvURL = "HARNESSLY_APP_MCP_URL" EnvHeaders = "HARNESSLY_APP_MCP_HEADERS" )
The environment the launch's MCP config gives the proxy (internal/apps launch.go). The token travels there and not on the command line, which every process of the machine can read.
const ( KeyHeader = "X-Harnessly-Call-Key" RepeatHeader = "X-Harnessly-Call-Repeat" KeysHeader = "X-Harnessly-Call-Keys" )
The headers of a tool call's idempotency. The proxy gives every tools/call a key of its own (KeyHeader). The runtime keeps a window's command under that key, so the same call made again finds its command and its answer and makes no second one. A call is made again only when its answer was lost with the connection (the runtime restarted), only to a runtime that says it knows the keys (KeysHeader on its answers), and marked RepeatHeader: the runtime then runs nothing a second time, it answers from its journal or says the answer is lost.
const ( // DefaultWait is how long a request waits for a runtime that does not answer before the agent is told so. DefaultWait = 20 * time.Second // DefaultRetry is the pause between two tries of a request, and the first pause before the stream is reopened. DefaultRetry = 300 * time.Millisecond // DefaultMaxPause is the longest pause before the stream is reopened. DefaultMaxPause = 5 * time.Second )
const Command = "app-mcp"
Command is the harnessly subcommand that runs the proxy.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Proxy ¶
type Proxy struct {
// URL is the runtime's MCP endpoint of the server, Headers what every request carries (the token).
URL string
Headers map[string]string
In io.Reader
Out io.Writer
// Client makes the requests; nil is one without a deadline (a tool may wait for the person) that gives up a dial
// after three seconds.
Client *http.Client
// Wait, Retry, MaxPause: zero is the default of each.
Wait, Retry, MaxPause time.Duration
// contains filtered or unexported fields
}
Proxy passes the JSON-RPC lines of In to the runtime at URL and writes the answers, and what the runtime's stream says, as lines to Out.