Documentation
¶
Overview ¶
Package brmcp carries Model Context Protocol sessions over Bison Relay private messages. It binds the MCP go-sdk's Transport contract to an abstract PM send/receive pair, so the same code serves both a bisonbotkit-backed bot process and an embedded Bison Relay client.
This package holds the protocol surface both ends share: the session Router and Conn over the wire envelope codec, the envelope predicate IsEnvelope, and the payment metadata (PriceMetaKey, PricingMetaKey, CallKeyMetaKey, PaymentRequired). The roles build on it:
- wire holds the byte-level envelope codec (see WIRE.md).
- server is the serving harness: default-deny authorization, rate limiting, priced tools, the prepaid ledger, and bisonbotkit glue.
- bridge is the client bridge: local MCP endpoints that mirror remote bots' tools and settle payments under the user's spending policy.
- brmcptest is an in-memory PM fabric for tests and examples.
Index ¶
Constants ¶
const CallKeyMetaKey = "brmcp/callKey"
CallKeyMetaKey is the caller-supplied idempotency key in a tools/call _meta. A transport retry of the same logical call reuses the key; the harness executes and charges once and replays the recorded outcome to duplicates, so a lost reply can never double-bill.
const PriceMetaKey = "brmcp/priceAtoms"
PriceMetaKey is the tool _meta key advertising the per-call price in atoms, visible to clients in tools/list.
const PricingMetaKey = "brmcp/pricing"
PricingMetaKey marks tools whose price is computed per call from the arguments; the authoritative quote arrives in the payment_required error.
const SampleEnvelope = `--mcp[v=1,sid=0123456789abcdef,mid=0123456789abcdef,seq=1/1,exp=1783000000]--eyJqc29ucnBjIjoiMi4wIn0=`
SampleEnvelope is a representative v1 wire frame. Hosts that let users define content filters on private messages should refuse any rule that matches it: filtering envelope frames severs MCP sessions at the receive path.
Variables ¶
This section is empty.
Functions ¶
func IsEnvelope ¶
IsEnvelope reports whether a PM body is brmcp traffic. Hosts that also parse chat commands on the same identity use this to keep MCP parts out of their command dispatch.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is one MCP session carried over Bison Relay PMs. It implements the go-sdk Connection contract.
func (*Conn) AsTransport ¶
AsTransport adapts the connection to the go-sdk Transport contract for Server.Connect / Client.Connect, which expect to dial themselves.
type PMSender ¶
PMSender delivers one private message body to a Bison Relay peer, identified by its lowercase 64-hex user id.
type PaymentRequired ¶
type PaymentRequired struct {
Error string `json:"error"` // always "payment_required"
Tool string `json:"tool"`
PriceAtoms int64 `json:"priceAtoms"`
BalanceAtoms int64 `json:"balanceAtoms"`
ShortfallAtoms int64 `json:"shortfallAtoms"`
AcceptedRails []string `json:"acceptedRails"`
}
PaymentRequired is the machine-readable body of the tool error returned when a paid call lacks balance. It is JSON in the result's text content so non-Go clients can parse it without extensions. Settlement is a Bison Relay tip: the payer's client requests an invoice from this bot's client over the relay (RMGetInvoice/RMInvoice) and pays it; the bot only sees the resulting tip credit.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router demuxes envelope parts arriving on the host's single PM stream into per-(peer, sid) MCP connections.
func NewRouter ¶
func NewRouter(cfg RouterConfig) *Router
type RouterConfig ¶
type RouterConfig struct {
// Sender delivers outgoing parts.
Sender PMSender
// Accept, when non-nil, is invoked for each NEW inbound session
// (server role). A nil Accept drops unknown inbound sessions, which
// is the client role: only sessions created via Dial exist.
Accept func(conn *Conn)
// Allow gates peers before any state is allocated for them. nil
// allows everyone; servers should install their allowlist here so
// unknown peers cannot even fill reassembly buffers.
Allow func(peer string) bool
// TTL is stamped as the deadline on outgoing messages. Bison Relay
// stores and forwards, so without a deadline a request could execute
// long after the caller gave up. Zero selects 10 minutes.
TTL time.Duration
// ChunkSize overrides wire.DefaultChunkSize (tests use small values).
ChunkSize int
// Assembler bounds reassembly state.
Assembler wire.AssemblerConfig
// InboxSize is the per-session queue of decoded inbound messages.
// A session that overflows it is closed. Zero selects 128.
InboxSize int
// IdleTimeout closes sessions with no traffic in either direction for
// this long. Zero selects 10 minutes in the server role (Accept set)
// and no expiry in the client role; negative disables expiry.
IdleTimeout time.Duration
// MaxSessionsPerPeer bounds how many concurrent inbound sessions one
// peer can hold open (server role); further session attempts are
// dropped. Zero selects 8; negative removes the bound. Locally dialed
// sessions are not bounded.
MaxSessionsPerPeer int
// Logf, when non-nil, receives diagnostic lines.
Logf func(format string, args ...any)
}
RouterConfig wires a Router to its host.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package bridge is the client bridge: it exposes a local streamable-HTTP MCP endpoint per allowed Bison Relay bot (/mcp/<bot-uid>, bearer gated, disabled by default) that mirrors the remote bot's tools verbatim and relays every call over the relay.
|
Package bridge is the client bridge: it exposes a local streamable-HTTP MCP endpoint per allowed Bison Relay bot (/mcp/<bot-uid>, bearer gated, disabled by default) that mirrors the remote bot's tools verbatim and relays every call over the relay. |
|
Package brmcptest provides an in-memory private message fabric so brmcp endpoints (routers, harnesses, bridges) can be exercised end to end without a relay.
|
Package brmcptest provides an in-memory private message fabric so brmcp endpoints (routers, harnesses, bridges) can be exercised end to end without a relay. |
|
cmd
|
|
|
brmcp-serve
command
brmcp-serve is an example MCP service offered over Bison Relay DMs.
|
brmcp-serve is an example MCP service offered over Bison Relay DMs. |
|
Package server is the serving harness: it publishes MCP tools over Bison Relay private messages with default-deny authorization, per-caller rate limiting, and paid tools settled by Bison Relay tips against a prepaid per-caller balance (the built-in Ledger, or any store implementing Billing).
|
Package server is the serving harness: it publishes MCP tools over Bison Relay private messages with default-deny authorization, per-caller rate limiting, and paid tools settled by Bison Relay tips against a prepaid per-caller balance (the built-in Ledger, or any store implementing Billing). |
|
Package wire frames opaque payloads (JSON-RPC messages in practice) into Bison Relay private messages.
|
Package wire frames opaque payloads (JSON-RPC messages in practice) into Bison Relay private messages. |