mcptools

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const WorkspaceParamName = "workspaceId"

WorkspaceParamName is the required workspace selector every desktop tool carries. It is not a spec path arg — it routes the call to the (client, workspace) grant that signs the request, and is substituted into any `{workspaceId}` path placeholder when present.

Variables

View Source
var DefaultEmbedAugmentors = map[string]*EmbedAugmentor{
	"balances.list": {
		Description: "Comma-separated list of resolved/calculated extras to attach under `_embedded` per balance. Supported tokens: `prices` — fetches USD price + USD value (requires one extra REST call to /dictionary/asset-market-prices); `networks` — resolves `networkId` to `isTestnet` so testnet holdings can be told apart without listing accounts (one extra REST call to /dictionary/networks).",
		Apply:       applyBalancesEmbeds,
		Injects:     map[string]string{},
	},
	"tx.list": {
		Description: "Comma-separated list of resolved entities to attach under `_embedded` per transaction. Supported tokens: `assets` — resolves `params.assetId` to the full Asset DTO (symbol, networkId, decimals, ...) via one batch /dictionary/assets call.",
		Apply:       applyTxListAssetsEmbed,
		Injects:     map[string]string{"transactions._embedded.asset": "Asset"},
	},
}

DefaultEmbedAugmentors is the shared `--embed` join surface: the augmentors every MCP consumer (bron-cli, Desktop) registers so `embed` tokens behave identically. Keyed by "<resource>.<verb>", matching Options.EmbedAugmentors.

Functions

func CoerceBodyDates

func CoerceBodyDates(payload any) error

CoerceBodyDates is a thin alias over qparam.CoerceBodyDates so the MCP path reads symmetrically alongside coerceBodyDates calls in the CLI's generated write handlers — same coercion, single source of truth.

func EmbedAssetsIntoTxs added in v0.1.1

func EmbedAssetsIntoTxs(v interface{}, assetById map[string]map[string]interface{})

EmbedAssetsIntoTxs attaches the resolved Asset under `_embedded.asset` on each transaction whose `params.assetId` is in the map. Sticks to the existing TransactionEmbedded convention (`_embedded` already carries other resolved entities like accounts, events, signing requests).

func ErrorResult

func ErrorResult(err error) *mcp.CallToolResult

func ExtractBodyBaseline

func ExtractBodyBaseline(in map[string]any) (any, error)

ExtractBodyBaseline pulls the optional `body` field out of the input map and returns it as the JSON baseline. Maps pass through (interface{} == any in Go 1.18+, no copy needed); anything else gets re-marshalled through a json.Decoder with UseNumber so big-int amount fields don't lose precision (`15000000000` would otherwise round-trip as `1.5e+10` and fail the backend's decimal parser).

func FetchAssetPrices added in v0.1.1

func FetchAssetPrices(ctx context.Context, doer Doer, assetIds []string) (map[string]assetPrice, error)

FetchAssetPrices returns a price-by-assetId map. /dictionary/asset-market-prices already echoes baseAssetId on each row, so a single call covers what used to take three (balances → assets list → symbol-market-prices) before the spec fix in libs/datamodel + platform/public-api.

func FetchAssetsById added in v0.1.1

func FetchAssetsById(ctx context.Context, doer Doer, assetIds []string) (map[string]map[string]interface{}, error)

func FetchNetworkTestnetFlags added in v0.2.0

func FetchNetworkTestnetFlags(ctx context.Context, doer Doer, networkIds []string) (map[string]bool, error)

func IsReadOnlyEndpoint

func IsReadOnlyEndpoint(resource, verb string, e catalog.HelpEntry) bool

IsReadOnlyEndpoint flags endpoints that are safe to expose under `bron mcp --read-only`. The source of truth is the OpenAPI spec's per-endpoint API-key permissions list (mined into `e.Permissions` by cligen): a tool is read-only iff its permissions include "View only". This avoids the "GET that mutates" footgun where a future endpoint like `GET /transactions/{id}/retry-broadcast` would slip through a method-only heuristic, and inverts the safety polarity to fail-closed (no permissions metadata → not read-only).

One explicit allow-list entry: `tx.dry-run` is a POST per spec but pure validation (no DB writes, no audit-log entries, no rate-counter advance — confirmed against backend). It's the only POST surfaced in read-only mode.

func MergeBalanceNetworks added in v0.2.0

func MergeBalanceNetworks(v interface{}, testnetById map[string]bool)

func MergeBalancePrices added in v0.1.1

func MergeBalancePrices(v interface{}, prices map[string]assetPrice)

MergeBalancePrices mutates the balances response in place: each item gets `usdPrice`, `usdQuoteSymbolId`, and `usdValue = totalBalance * price` placed under `_embedded` so calculated fields don't pollute the spec-defined Balance shape. Same HATEOAS-style nesting that backend uses for resolved entities (e.g. WorkspaceMemberEmbedded). Multiplication uses big.Rat so trailing precision survives.

func RegisterHelp

func RegisterHelp(server *mcp.Server)

RegisterHelp adds the read-only `bron_help` tool: static data-model help with no network access. It is not a spec endpoint, so it registers directly rather than through RegisterSpecDriven.

func RegisterPortfolioSummary added in v0.2.0

func RegisterPortfolioSummary(server *mcp.Server, doer Doer, opts Options)

func RegisterSpecDriven

func RegisterSpecDriven(server *mcp.Server, doer Doer, opts Options)

RegisterSpecDriven registers one MCP tool per catalog endpoint passing opts; new endpoints need only a catalog regen.

func SanitizeName

func SanitizeName(s string) string

func SortedKeys

func SortedKeys[V any](m map[string]V) []string

func StringValue

func StringValue(v any) string

StringValue stringifies one input value the way the CLI does — strings pass through, numbers/booleans become their JSON repr (so body.Compose's json.Unmarshal recovers the typed scalar), nested objects/arrays go through json.Marshal. Empty / nil → empty string so callers can `if s == ""` skip.

func ToolName

func ToolName(resource, verb string) string

ToolName converts (resource, verb) into a stable MCP tool name.

bron_<resource>_<verb> with dashes turned into underscores.

The MCP spec restricts tool names to [a-zA-Z0-9_-]; our resources and verbs already comply, but address-book/create-signing-request style verbs need the dash → underscore swap so the JSON-Schema name pattern ($_a-z0-9) is satisfied uniformly.

func UniqueAssetIds added in v0.1.1

func UniqueAssetIds(v interface{}) []string

UniqueAssetIds walks a balances response and returns deduplicated assetIds. Treats both the wrapped `{"balances":[...]}` shape and a bare array as input.

func UniqueNetworkIds added in v0.2.0

func UniqueNetworkIds(v interface{}) []string

func UniqueTxAssetIds added in v0.1.1

func UniqueTxAssetIds(v interface{}) []string

UniqueTxAssetIds collects every assetId reachable through `params.assetId` on each transaction. Intent transactions store fromAssetId/toAssetId in a separate intents resource, not on the tx itself, so they're not resolved here — that needs `--embed intents` (out of scope for this commit).

func WrapUntrusted added in v0.4.0

func WrapUntrusted(v any, opts WrapOptions) any

func WrapUntrustedFields

func WrapUntrustedFields(v any) any

func WrapUntrustedFieldsWithKeys

func WrapUntrustedFieldsWithKeys(v any, keys map[string]bool) any

Types

type APIError

type APIError struct {
	Status    int
	Code      string
	Message   string
	RequestID string
	Embedded  map[string]any
}

func (*APIError) Error

func (e *APIError) Error() string

type Doer

type Doer interface {
	Do(ctx context.Context, method, path string, pathParams map[string]string, body, query, result any) error
}

Doer executes one Bron API request. Both the CLI's HTTP client (process-wide workspace + API key) and Desktop's per-grant signer satisfy it, so the spec-driven registration below is shared: the caller supplies how a request is authenticated and dispatched, the registrar owns which tools exist and how their arguments map onto a request.

type EmbedAugmentor

type EmbedAugmentor struct {
	Description string
	Apply       func(ctx context.Context, doer Doer, result any, tokens []string) error
	Injects     map[string]string
}

EmbedAugmentor encapsulates a client-side join: when the agent passes an `embed` token on a registered (resource, verb), Apply mutates the result in place to attach the resolved/calculated extras under `_embedded`.

type Options

type Options struct {
	ReadOnly          bool
	Allow             func(toolName string) bool
	WorkspaceParam    bool
	EmbedAugmentors   map[string]*EmbedAugmentor
	PreCallValidators map[string]func(in map[string]any) error
}

Options tunes spec-driven registration for one consumer.

  • ReadOnly skips state-changing endpoints (keeps GET + `tx.dry-run`).
  • Allow gates each candidate tool by name; nil means "register everything".
  • WorkspaceParam adds a required `workspaceId` selector to every tool and routes it into the request path — Desktop resolves the signing grant from it. The CLI leaves it off (its client injects a process-wide workspace).
  • EmbedAugmentors / PreCallValidators attach per-tool client-side behaviour.

type SpecTool

type SpecTool struct {
	Name        string
	Resource    string
	Verb        string
	Entry       catalog.HelpEntry
	Description string
	InputSchema *jsonschema.Schema
}

SpecTool is one spec-driven MCP tool that passed the active Options filters.

func SpecTools

func SpecTools(opts Options) []SpecTool

SpecTools returns the endpoint tools that survive the ReadOnly and Allow filters, with input schemas already built for opts. RegisterSpecDriven wires these onto a server; tests inspect them directly.

type WrapOptions added in v0.4.0

type WrapOptions struct {
	Keys     map[string]bool
	Paths    map[string]bool
	SwitchAt map[string]string
}

Jump to

Keyboard shortcuts

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