Function addMCPSchema

  • Registers an MCP (Model Context Protocol) instance in the framework — the bridge exposing live trading of a strategy to an MCP agent (see MCP.getStatus).

    The MCP binds to a strategy: status snapshots and position commands operate on every live instance of that strategy. getMessages renders the portfolio for the agent; when omitted the default renderer emits one text message per traded symbol.

    Parameters

    • mcpSchema: IMCPSchema

      MCP (Model Context Protocol) configuration object

      Registration schema of an MCP (Model Context Protocol) instance.

      Binds an MCP name to a strategy: status and position commands operate on every live instance of that strategy.

      • mcpName — registry key; duplicate registration is a validation error.
      • strategyName — the strategy whose live instances the MCP observes and trades. Optional: when omitted, the SINGLE registered strategy is used; with two or more strategies registered every MCP call throws until the schema names one explicitly — ambiguity is an error, not a guess.
      • positionCost — entry cost in USD for commitPositionOpen; defaults to GLOBAL_CONFIG.CC_POSITION_ENTRY_COST when omitted.
      • permissions — per-method grants for the agent-facing methods; defaults to ALL of them when omitted. Listing permissions explicitly narrows the agent to exactly those methods; a call to a method whose permission is missing throws with an agent-readable denial. The check runs per call, so an overridden schema applies immediately.
      • getMessages — renders the portfolio snapshot into agent messages; when omitted the default renderer emits one text message per symbol.
      • callbacks — all optional; an omitted callback is simply never fired.
      • Optionalcallbacks?: Partial<IMCPCallbacks>

        Lifecycle callbacks (all optional)

      • OptionalgetMessages?: (
            context: IMCPContext,
            when: Date,
            mcpName: string,
        ) => IMCPMessage[] | Promise<IMCPMessage[]>

        Renders the portfolio snapshot into messages for the MCP (Model Context Protocol) agent (default: text per symbol)

      • mcpName: string

        Unique MCP (Model Context Protocol) identifier for the schema registry

      • OptionalminuteEstimatedTime?: number

        Estimated time in minutes for a position to reach its TP or SL.

      • Optionalpermissions?: MCPPermission[]

        Per-method grants for the agent; each permission name gates the agent-facing MCP (Model Context Protocol) method of the same name. Default: all of them

      • OptionalpositionCost?: number

        Entry cost in USD for opened positions. Default: GLOBAL_CONFIG.CC_POSITION_ENTRY_COST

      • OptionalstrategyName?: string

        Strategy whose live instances this MCP (Model Context Protocol) observes and trades. Optional: defaults to the single registered strategy; ambiguous (2+ registered) requires it

    Returns void

    addMCPSchema({
    mcpName: "my-mcp",
    strategyName: "my-strategy",
    positionCost: 100,
    getMessages: (context, when) => [
    { id: randomString(), type: "text", text: `Symbols: ${Object.keys(context).join(", ")}` },
    ],
    });