# Graph shortest unweighted path

`graph-shortest-unweighted-path` · version 1.0.0 · Graphs & scheduling · free, no key needed

Find a shortest directed path by fewest edges from source to target.

**Use when you need to: graph shortest unweighted path · fewest directed edges from source to target · unweighted shortest path between two nodes.**

## Supported

- graph shortest unweighted path
- fewest directed edges from source to target
- unweighted shortest path between two nodes

## Not supported

- weighted shortest path
- k-shortest paths
- negative-weight shortest path
- all-pairs shortest paths
- undirected shortest path

## Behavior

- Input is a directed simple graph plus source and target, which must both be existing node ids.
- length is the number of directed edges on the path, equal to path.length - 1.
- When source equals target, the result is reachable with path [source] and length 0, even if a self-loop or cycle exists.
- Otherwise the path is a BFS from source: first visit wins, outgoing neighbors follow declared edge order, and the route is reconstructed from parent pointers.
- If target is unreachable, reachable is false, path is [], and length is null.
- Self-loops and directed cycles are allowed; they do not change the first-visit BFS rule.

## 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
- `source` (string, required): min length 1; max length 256
- `target` (string, required): min length 1; max length 256

## Output

- `reachable` (boolean, required)
- `path` (array of string, required)
- `length` (integer or null, required): min 0

## Limits

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

## Example

Request input:

```json
{
  "nodes": [
    "start",
    "left",
    "right",
    "end"
  ],
  "edges": [
    {
      "from": "start",
      "to": "right"
    },
    {
      "from": "start",
      "to": "left"
    },
    {
      "from": "left",
      "to": "end"
    },
    {
      "from": "right",
      "to": "end"
    }
  ],
  "source": "start",
  "target": "end"
}
```

Response:

```json
{
  "result": {
    "reachable": true,
    "path": [
      "start",
      "right",
      "end"
    ],
    "length": 2
  }
}
```

## How to call it

### MCP

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

```json
{
  "id": "graph-shortest-unweighted-path",
  "version": "1.0.0",
  "input": {
    "nodes": [
      "start",
      "left",
      "right",
      "end"
    ],
    "edges": [
      {
        "from": "start",
        "to": "right"
      },
      {
        "from": "start",
        "to": "left"
      },
      {
        "from": "left",
        "to": "end"
      },
      {
        "from": "right",
        "to": "end"
      }
    ],
    "source": "start",
    "target": "end"
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/graph-shortest-unweighted-path/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"nodes":["start","left","right","end"],"edges":[{"from":"start","to":"right"},{"from":"start","to":"left"},{"from":"left","to":"end"},{"from":"right","to":"end"}],"source":"start","target":"end"}'
```

The machine-readable contract is at [/v1/tools/graph-shortest-unweighted-path/versions/1.0.0](/v1/tools/graph-shortest-unweighted-path/versions/1.0.0).

### CLI

```sh
node cli.mjs run graph-shortest-unweighted-path 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 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 to adjacency](/tools/graph-to-adjacency): Convert a directed simple graph into per-node outgoing adjacency lists.
- [Graph validate](/tools/graph-validate): Inspect a well-formed directed simple graph and report counts, isolated nodes, and maximum degrees.
- [Schedule critical path](/tools/schedule-critical-path): Compute CPM zero-slack critical nodes and tight edges on a DAG, plus one representative critical path.
