SwarmOps
ReferenceMcp toolsread_tree
View as Markdown

read_tree#

Lists one directory at a revision, without a checkout, a page of entries at a time, each file with its size, and with depth the directories below it too; pass a limit of 100 or less and page on with the cursor, since clients limit long tool results.

Metadata
Since
0.1.0
Mutates
no
Identity required
no
Envelope op
read_tree
Cli command
swarmops ls
Request type
ReadTreeReq
Annotations
{"destructiveHint":false,"idempotentHint":true,"openWorldHint":false,"readOnlyHint":true}
Max result chars
null
CLI command
swarmops ls

Input schema#

arguments is a ReadTreeReq: swarmops schema ReadTreeReq prints the type. A field the type does not know is ignored.

FieldTypeRequiredDefaultDescription
cursorstring or nullnoResume a listing: the previous page's cursor. Pass it back exactly as returned; do not construct it (cursors are opaque). This page starts after the entry it names.
depthintegerno1How many levels to list: 1 for the directory's own entries, 2 for theirs too, and so on, up to 64 (0 or more than 64 is E_INVALID_ARG).
limitintegerno250The most entries to return: at least 1 (0 is E_INVALID_ARG).
pathstring or nullnoThe directory's repository path; omitted for the root.
revstringyesThe revision to read at. A revision as the caller wrote it, for the store to resolve: a ref name (main, release/1.2), a full 64-hex changeset id or a unique prefix of at least 12 hex digits, optionally followed by ~N for the N-th first-parent ancestor.

JSON Schema#

As tools/list gives it: each $ref replaced by its definition, so that it stands alone.

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "description": "`read_tree` (CLI `ls`): list one directory at a revision, without a checkout, a page at a\ntime; with `depth`, the directories below it too.",
  "properties": {
    "cursor": {
      "description": "Resume a listing: the previous page's `cursor`. Pass it back exactly as returned; do not\nconstruct it (cursors are opaque). This page starts after the entry it names.",
      "type": [
        "string",
        "null"
      ]
    },
    "depth": {
      "default": 1,
      "description": "How many levels to list: 1 for the directory's own entries, 2 for theirs too, and so on, up\nto 64 (0 or more than 64 is `E_INVALID_ARG`).",
      "format": "uint32",
      "maximum": 64,
      "minimum": 1,
      "type": "integer"
    },
    "limit": {
      "default": 250,
      "description": "The most entries to return: at least 1 (0 is `E_INVALID_ARG`).",
      "format": "uint",
      "minimum": 1,
      "type": "integer"
    },
    "path": {
      "description": "The directory's repository path; omitted for the root.",
      "type": [
        "string",
        "null"
      ]
    },
    "rev": {
      "description": "The revision to read at. A revision as the caller wrote it, for the store to resolve: a ref name (`main`,\n`release/1.2`), a full 64-hex changeset id or a unique prefix of at least 12 hex digits,\noptionally followed by `~N` for the N-th first-parent ancestor.",
      "type": "string"
    }
  },
  "required": [
    "rev"
  ],
  "title": "ReadTreeReq",
  "type": "object"
}

Annotations#

It only reads the store.

AnnotationValueMeaning
destructiveHintfalseTrue: a tool that changes the store may overwrite or delete what is there, not only add to it.
idempotentHinttrueTrue: calling it again with the same arguments changes nothing more.
openWorldHintfalseTrue: it reaches beyond a closed set of things. Every tool here stays inside the store.
readOnlyHinttrueTrue: the tool does not change its environment, the store.

Its entry in tools/list carries no _meta.

CLI command#

swarmops ls runs the same operation and prints the same envelope.

Examples#

{
  "id": 9,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "rev": "main"
    },
    "name": "read_tree"
  }
}
{
  "id": 9,
  "jsonrpc": "2.0",
  "result": {
    "content": [
      {
        "text": "{\"ok\":true,\"op\":\"read_tree\",\"api\":1,\"result\":{\"entries\":[{\"name\":\"README.md\",\"kind\":\"file\",\"size\":7,\"id\":\"[blob]\"},{\"name\":\"src\",\"kind\":\"dir\",\"id\":\"[id2]\"}],\"truncated\":false},\"meta\":{\"repo\":\"[tmp]/store\",\"elapsed_ms\":\"[elapsed_ms]\",\"resolved\":{\"main\":\"[c1]\"},\"auth\":\"trust\"}}",
        "type": "text"
      }
    ],
    "isError": false,
    "structuredContent": {
      "api": 1,
      "meta": {
        "auth": "trust",
        "elapsed_ms": "[elapsed_ms]",
        "repo": "[tmp]/store",
        "resolved": {
          "main": "[c1]"
        }
      },
      "ok": true,
      "op": "read_tree",
      "result": {
        "entries": [
          {
            "id": "[blob]",
            "kind": "file",
            "name": "README.md",
            "size": 7
          },
          {
            "id": "[id2]",
            "kind": "dir",
            "name": "src"
          }
        ],
        "truncated": false
      }
    }
  }
}

The server ran as swarmops mcp --repo [tmp]/store --as agent/worker-17, after initialize. Recorded by the MCP tests. A name in square brackets, such as [tmp] or [c1], stands for what differs from run to run: the test's temporary directory, an id, a time, the version.

Details#

Pass a limit of 100 or less and page on with the cursor the result gives. Each file comes with its size; with depth, the directories below the one asked for are listed too. No checkout is needed: it reads the tree at the revision.

Return information#

A tool result: the envelope, whose op is read_tree, as structuredContent and again as the text of its one content block. isError is true exactly when the envelope's ok is false. On success the envelope's result is what swarmops ls returns.

Errors#

A failed call is a tool result with isError: true; the envelope's error.code is one of the error codes.

  • E_INVALID_ARG: arguments that do not fit ReadTreeReq, a field named twice among them included, or that break one of the server's own rules.
  • E_NOT_A_REPO: the server's store is not there; the server serves on.
  • E_INTERNAL: the operation panicked, a bug.

Then the errors of the operation, as swarmops ls lists them.

See also#

Edit on GitHub

On this page