# Graph from adjacency

`graph-from-adjacency` · version 1.0.0 · Graphs & scheduling · free, no key needed

Rebuild a simple directed graph from adjacency lists of node ids and successors.

**Use when you need to: graph from adjacency · adjacency list to graph · rebuild graph from adjacency lists.**

## Supported

- graph from adjacency
- adjacency list to graph
- rebuild graph from adjacency lists

## Not supported

- adding missing successor nodes silently
- weighted adjacency
- undirected pairs
- adjacency matrix input

## Behavior

- Input adjacency is an array of {node, successors} objects and nothing else.
- Output nodes are the entry node ids in adjacency-entry order.
- Output edges are flattened in entry order, then successor-list order, as {from: node, to: successor}.
- Every successor must equal some node in this adjacency list; missing nodes are rejected, not inserted.
- Duplicate node ids and duplicate (node, successor) pairs, including repeats inside one successors list, are rejected.
- Self-loops and directed cycles are allowed; this tool does not reject them.
- Empty adjacency yields {nodes: [], edges: []}.

## Input

- `adjacency` (array of object, required): max items 2000

## Output

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

## Limits

- max nodes: 2000
- max edges: 10000
- max node id bytes: 256

## Example

Request input:

```json
{
  "adjacency": [
    {
      "node": "build",
      "successors": [
        "test",
        "deploy"
      ]
    },
    {
      "node": "test",
      "successors": [
        "deploy"
      ]
    },
    {
      "node": "deploy",
      "successors": []
    }
  ]
}
```

Response:

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

## How to call it

### MCP

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

```json
{
  "id": "graph-from-adjacency",
  "version": "1.0.0",
  "input": {
    "adjacency": [
      {
        "node": "build",
        "successors": [
          "test",
          "deploy"
        ]
      },
      {
        "node": "test",
        "successors": [
          "deploy"
        ]
      },
      {
        "node": "deploy",
        "successors": []
      }
    ]
  }
}
```

### HTTP (no key)

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

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

### CLI

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

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

## Related tools

- [Graph to adjacency](/tools/graph-to-adjacency): Convert a directed simple graph into per-node outgoing adjacency lists.
- [Graph shortest unweighted path](/tools/graph-shortest-unweighted-path): Find a shortest directed path by fewest edges from source to target.
- [Graph induced subgraph](/tools/graph-induced-subgraph): Return the vertex-induced subgraph on a listed node subset, preserving declared node and edge order.
- [Graph reachable from](/tools/graph-reachable-from): List nodes reachable from given sources by directed BFS, in discovery order.
- [Graph ancestors](/tools/graph-ancestors): List every ancestor of given targets, including the targets, in reverse-graph BFS discovery order.
- [Graph connected components](/tools/graph-connected-components): Partition a directed simple graph into undirected connected components, ignoring edge direction.
