# Graph to adjacency

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

Convert a directed simple graph into per-node outgoing adjacency lists.

**Use when you need to: graph to adjacency · convert directed graph to adjacency lists · list outgoing successors per node.**

## Supported

- graph to adjacency
- convert directed graph to adjacency lists
- list outgoing successors per node

## Not supported

- incoming predecessor lists
- adjacency matrix
- weighted adjacency
- undirected adjacency pairs

## Behavior

- Input is a directed simple graph: unique node ids and unique (from, to) edges whose endpoints exist in nodes.
- Output adjacency contains one object per node, in declared node order.
- Each successors array lists destination ids of that node’s outgoing edges in declared edge order.
- A self-loop appears as the node id inside that node’s successors list.
- Isolated nodes are present with an empty successors array.
- Adjacency is an array of {node, successors} objects, not a string-keyed map, so prototype-like ids stay ordinary entries.
- Empty input {nodes:[], edges:[]} yields {adjacency:[]}. Cycles are data and are not rejected.

## Input

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

## Output

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

## Limits

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

## Example

Request input:

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

Response:

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

## How to call it

### MCP

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

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

### HTTP (no key)

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

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

### CLI

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

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

## Related tools

- [Graph from adjacency](/tools/graph-from-adjacency): Rebuild a simple directed graph from adjacency lists of node ids and successors.
- [Graph induced subgraph](/tools/graph-induced-subgraph): Return the vertex-induced subgraph on a listed node subset, preserving declared node and edge order.
- [Graph shortest unweighted path](/tools/graph-shortest-unweighted-path): Find a shortest directed path by fewest edges from source to target.
- [Graph DAG longest path](/tools/graph-dag-longest-path): Return a longest node-weighted path in a DAG, where path weight is the sum of node durations.
- [Graph find cycle](/tools/graph-find-cycle): Find one directed cycle by 3-color DFS, or report that the graph is acyclic.
- [Graph reachable from](/tools/graph-reachable-from): List nodes reachable from given sources by directed BFS, in discovery order.
