Skip to main content
Glama

BotSpot: AI Trading, Backtests and Bots

Replace a strategy file

replace_file
Destructive

Replaces the full contents of an existing strategy file in a new immutable revision for any strategy owned by the authenticated user. Requires editHandle from get_file/list_files. Use this for first-build main.py replacement after create_strategy returns neutral starter files. For the current attached/open strategy, omit strategyId and revisionId after get_file; the server resolves the latest conversation revision, so do not manually transcribe those UUIDs. Pass explicit ids only for a named or different strategy. For existing-strategy fixes, this is the action step after get_file identified the concrete change and returned an editHandle. Mutate only the strategy/revision named by the user when it differs from the open page context. A successful replace result confirms the saved content; use its returned new revisionId and editHandle, do not call get_file to re-read it, and never check against the original/base revisionId from before the edit. When an edit follows a backtest request or result in the same conversation, validate the new saved revision with the established window, capital and data settings, even when the earlier run succeeded and the customer did not repeat the test request. Explicit save-only instructions and disabled automatic-backtest preferences take precedence. A standalone file edit without a backtesting workflow is complete after saving unless testing was requested. Never deploy or trade merely to validate an edit. A successful mutation or compiling/ready analysis alone does not complete the requested repair. If the saved executable code still uses the faulty causal path the user asked to repair, or new helpers/scaffolding are not connected to it, continue the remaining authorized file edits with the current editHandle. Do not final-answer with a plan, apology, model-upgrade suggestion, or admission that the repair is incomplete while authorization and execution budget permit, the file tools work, and the remaining corrective edit is known. Recover ambiguous anchors with the returned unique context, an exact guarded range, or complete replace_file; a recoverable patch-format error is not a missing capability. Finish the requested change and preserve unrelated behavior and files. For copy/apply-same-rules requests, do not use replace_file after reading only one strategy, and do not use it after reading only the target. A different revision of the named target is still target evidence, not source evidence, unless the user explicitly asked to copy from an older target revision. First read the source strategy code and the named target strategy code, then diff executable assignments/thresholds/cadence/branches within the requested copy scope. Copy only explicitly requested mechanics for a limited transfer; update every differing target value to the source value only for whole-strategy parity. Preserve target-specific identity such as symbol/ticker, strategy name, account/broker identity, and labels unless the user explicitly asks to change them; do not copy the source symbol/name into the target. Build the replacement from the target file and selectively copy behavior values into it; do not replace the named target wholesale with the source file when identities differ. In Python strategy code, self.symbol is target identity when source and target tickers differ; for a TQQQ source applied to an SQQQ target, keep self.symbol as SQQQ while copying behavior rules. Target identity does not include cadence, sleeptime, trigger thresholds, order sizing, entry/exit branches, helper calls, or risk rules; those are behavior and must match the source only when included in the requested copy scope. Do not add settings absent from the source or merge unrelated memory/preferences. Before replace_file in a copy/apply-same-rules edit, preserve the literal target identity line from the target readback in the replacement content. If your replacement would turn target identity into source identity, do not call this tool yet; correct the replacement first. After saving a copy/apply-same-rules edit, if the content you saved contains source identity such as the source symbol/name/account/broker, edit again before final-answering. Do not list source identity as evidence of success. When the fix replaces an executable setting, guard, helper call, order path, or branch, remove or replace the stale executable code; do not append a competing line and leave the old contradictory behavior in place. When the user says to stop using a value/source, or says that value/source is stale or wrong, remove executable fallback uses of that value/source instead of keeping them as a backup path. If the content you saved still contains the stale executable value/source/fallback the user asked to remove, the edit is not complete; call patch_file or replace_file again before final-answering. If the user supplied a concrete replacement value for a code-owned setting such as cost basis, entry price, threshold, cadence, market, symbol, or helper path, replace the stale executable literal/path. For live fill/cost-basis fixes where live order tools fail but the user supplied a concrete bot-owned fill, record/use that exact fill value in executable state/code as the bootstrap latest verified bot-owned fill; do not add only an unset placeholder such as None. For plan-driven first-build work, make the visible implementation item in_progress with update_plan_item before using file tools so the user sees the current plan step while file work runs. If replace_file or patch_file fails, no new revision was created: read the current file/editHandle and retry with a valid edit before starting a backtest or ending the strategy build.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "path": "<path>",
      "editHandle": "<editHandle>",
      "content": "<content>"
    },
    "name": "replace_file"
  }
}

Input Schema

NameRequiredDescriptionDefault
pathYes
contentYes
editHandleYesOpaque edit handle returned by list_files or get_file. It replaces raw hash copying while preserving stale-write protection.
revisionIdNoBase revision ID to snapshot from. Omit with strategyId for the current attached/open strategy.
strategyIdNoBase strategy id. Omit with revisionId for the current attached/open strategy so the server uses the conversation's latest saved revision.
descriptionNoShown to the customer as "How your strategy works". One or two plain sentences on what the strategy now does, e.g. "Buys Apple after a 5% drop in a day and sells at a 10% gain." Write for the customer, not an internal change note.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed8 schema fields changed
    • addedInput schema / properties / description / anyOf
      Added value: +[
      +  {
      +    "maxLength": 2000,
      +    "type": "string"
      +  },
      +  {
      +    "type": "null"
      +  }
      +]
    • removedInput schema / properties / description / maxLength
      Removed value: -2000
    • removedInput schema / properties / description / type
      Removed value: -"string"
    • removedInput schema / properties / revisionId / $ref
      Removed value: -"#/properties/strategyId"
    • addedInput schema / properties / revisionId / anyOf
      Added value: +[
      +  {
      +    "$ref": "#/properties/strategyId/anyOf/0"
      +  },
      +  {
      +    "type": "null"
      +  }
      +]
    • addedInput schema / properties / strategyId / anyOf
      Added value: +[
      +  {
      +    "format": "uuid",
      +    "type": "string"
      +  },
      +  {
      +    "type": "null"
      +  }
      +]
    • removedInput schema / properties / strategyId / format
      Removed value: -"uuid"
    • removedInput schema / properties / strategyId / type
      Removed value: -"string"
  2. Changed1 schema field changed
    • addedInput schema / properties / description / description
      Added value: +"Shown to the customer as \"How your strategy works\". One or two plain sentences on what the strategy now does, e.g. \"Buys Apple after a 5% drop in a day and sells at a 10% gain.\" Write for the customer, not an internal change note."
  3. First observed

TDQS

A4/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare destructive=true, readOnly=false, idempotent=false, and openWorld=true, so the safety profile is structured. Beyond that, the description adds useful behavior: replacement creates a new immutable revision, a successful result returns a new revisionId and editHandle, and a failed replace means no new revision was created. It does not cover permissions or rate limits, and much of the rest is workflow policy rather than tool behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness2/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The first two sentences front-load the core operation and prerequisite well, but the description then sprawls into dozens of sentences of agent workflow policy, backtesting validation rules, copy/parity instructions, and repeated directives about not final-answering prematurely. Much of this is not needed to select or invoke replace_file, and the volume makes the tool definition hard to scan.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a six-parameter mutation tool with no output schema and destructive/open-world annotations, the description covers the critical completeness gaps: required editHandle, immutable revision behavior, ID omission rules, success semantics, and failure behavior. It does not fully specify the return payload or path validation, but an agent has enough information to call the tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 67%, and the description adds substantial meaning beyond the schema for strategyId and revisionId: omit both for the current attached/open strategy, do not manually transcribe UUIDs, and pass explicit IDs only for a named or different strategy. It also reinforces that editHandle comes from get_file/list_files and carries stale-write protection. It says little about path semantics and does not discuss the optional description parameter.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states a specific verb and resource: it replaces the full contents of an existing strategy file, creating an immutable revision for an authenticated user's strategy. It also identifies the key prerequisite, an editHandle from get_file/list_files. It does not crisply distinguish when to use patch_file instead, so it is clear but not fully sibling-differentiated.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Usage guidance is extensive and explicit: omit strategyId/revisionId for the current open strategy, pass explicit IDs only for a named or different strategy, and use it for first-build main.py replacement after create_strategy. It also gives concrete when-not rules for copy/apply-same-rules work, such as not using replace_file after reading only one strategy or only the target.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.