# Graph transitive closure

`graph-transitive-closure` · version 1.0.0 · Graphs & scheduling · free, no key needed

List directed reachability pairs of path length at least 1, ordered by declared node index.

**Use when you need to: graph transitive closure · directed reachability pairs · positive-length reachability pairs.**

## Supported

- graph transitive closure
- directed reachability pairs
- positive-length reachability pairs

## Not supported

- counting paths
- reflexive closure option
- undirected closure
- reachability from named sources

## Behavior

- Input is a directed simple graph with unique node ids and unique from-to edges.
- Each output pair (from, to) means a directed walk of length at least 1 exists from from to to.
- A pair (v, v) is included only when a positive-length directed cycle returns to v, including a self-loop.
- Trivial reflexive pairs are omitted when no such cycle exists.
- Pairs are ordered by increasing declared from index, then increasing declared to index. Ids are not sorted lexicographically.
- An empty graph or a graph with no edges returns an empty pairs array.
- More than 500 nodes is rejected. More than 50000 pairs is rejected.
- Self-loops and longer cycles are allowed. This operation does not count paths or ignore edge direction.

## Input

- `nodes` (array of string, required): max items 500; each min length 1; each max length 256
- `edges` (array of object, required): max items 10000

## Output

- `pairs` (array of object, required): max items 50000

## Limits

- max nodes: 500
- max edges: 10000
- max node id bytes: 256
- max pairs: 50000

## Example

Request input:

```json
{
  "nodes": [
    "build",
    "test",
    "package",
    "deploy"
  ],
  "edges": [
    {
      "from": "build",
      "to": "test"
    },
    {
      "from": "test",
      "to": "package"
    },
    {
      "from": "package",
      "to": "deploy"
    },
    {
      "from": "build",
      "to": "package"
    }
  ]
}
```

Response:

```json
{
  "result": {
    "pairs": [
      {
        "from": "build",
        "to": "test"
      },
      {
        "from": "build",
        "to": "package"
      },
      {
        "from": "build",
        "to": "deploy"
      },
      {
        "from": "test",
        "to": "package"
      },
      {
        "from": "test",
        "to": "deploy"
      },
      {
        "from": "package",
        "to": "deploy"
      }
    ]
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "graph-transitive-closure",
  "version": "1.0.0",
  "input": {
    "nodes": [
      "build",
      "test",
      "package",
      "deploy"
    ],
    "edges": [
      {
        "from": "build",
        "to": "test"
      },
      {
        "from": "test",
        "to": "package"
      },
      {
        "from": "package",
        "to": "deploy"
      },
      {
        "from": "build",
        "to": "package"
      }
    ]
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/graph-transitive-closure/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"nodes":["build","test","package","deploy"],"edges":[{"from":"build","to":"test"},{"from":"test","to":"package"},{"from":"package","to":"deploy"},{"from":"build","to":"package"}]}'
```

The machine-readable contract is at [/v1/tools/graph-transitive-closure/versions/1.0.0](/v1/tools/graph-transitive-closure/versions/1.0.0).

### CLI

```sh
node cli.mjs run graph-transitive-closure 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Graph reachable from](/tools/graph-reachable-from): List nodes reachable from given sources by directed BFS, in discovery order.
- [Graph find cycle](/tools/graph-find-cycle): Find one directed cycle by 3-color DFS, or report that the graph is acyclic.
- [Graph reverse](/tools/graph-reverse): Reverse every directed edge of a simple graph, keeping node order and original edge order.
- [Graph shortest unweighted path](/tools/graph-shortest-unweighted-path): Find a shortest directed path by fewest edges from source to target.
- [Graph strongly connected components](/tools/graph-strongly-connected-components): Partition a directed simple graph into strongly connected components, listed by declared node index.
- [Graph to adjacency](/tools/graph-to-adjacency): Convert a directed simple graph into per-node outgoing adjacency lists.
