# Graph DAG longest path

`graph-dag-longest-path` · version 1.0.0 · Graphs & scheduling · free, no key needed

Return a longest node-weighted path in a DAG, where path weight is the sum of node durations.

**Use when you need to: graph dag longest path · longest node-weighted path in a dag · dag longest duration chain.**

## Supported

- graph dag longest path
- longest node-weighted path in a dag
- dag longest duration chain

## Not supported

- edge weights
- longest path in cyclic graphs
- negative durations
- k shortest paths

## Behavior

- Path weight is the sum of node durations along the path, not edge weights.
- The graph must be a DAG under Kahn order (smallest declared index among remaining indegree-0 nodes); a cycle including a self-loop is rejected.
- Empty graph returns path [] and length 0.
- In Kahn order, dist[v] equals duration[v] plus the maximum dist of its predecessors, or duration[v] if it has none.
- When several predecessors share that incoming maximum, the parent is the predecessor with the smallest declared index.
- The reported path ends at a maximum-dist node, breaking ties by smallest declared index, and is reconstructed through those parents.
- Duration values and the path length are canonical non-negative base-10 integer strings with at most 18 digits.

## 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
- `durations` (object, required)

## Output

- `path` (array of string, required)
- `length` (string, required): max length 18; pattern `^(0|[1-9][0-9]*)$`

## Limits

- max nodes: 2000
- max edges: 10000
- max node id bytes: 256
- max duration digits: 18

## Example

Request input:

```json
{
  "nodes": [
    "design",
    "build",
    "test",
    "ship"
  ],
  "edges": [
    {
      "from": "design",
      "to": "build"
    },
    {
      "from": "build",
      "to": "test"
    },
    {
      "from": "design",
      "to": "test"
    },
    {
      "from": "test",
      "to": "ship"
    }
  ],
  "durations": {
    "design": "3",
    "build": "5",
    "test": "2",
    "ship": "1"
  }
}
```

Response:

```json
{
  "result": {
    "path": [
      "design",
      "build",
      "test",
      "ship"
    ],
    "length": "11"
  }
}
```

## How to call it

### MCP

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

```json
{
  "id": "graph-dag-longest-path",
  "version": "1.0.0",
  "input": {
    "nodes": [
      "design",
      "build",
      "test",
      "ship"
    ],
    "edges": [
      {
        "from": "design",
        "to": "build"
      },
      {
        "from": "build",
        "to": "test"
      },
      {
        "from": "design",
        "to": "test"
      },
      {
        "from": "test",
        "to": "ship"
      }
    ],
    "durations": {
      "design": "3",
      "build": "5",
      "test": "2",
      "ship": "1"
    }
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/graph-dag-longest-path/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"nodes":["design","build","test","ship"],"edges":[{"from":"design","to":"build"},{"from":"build","to":"test"},{"from":"design","to":"test"},{"from":"test","to":"ship"}],"durations":{"design":"3","build":"5","test":"2","ship":"1"}}'
```

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

### CLI

```sh
node cli.mjs run graph-dag-longest-path 1.0.0 --input input.json --base-url https://computefirst.net
```

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

## Related tools

- [Graph induced subgraph](/tools/graph-induced-subgraph): Return the vertex-induced subgraph on a listed node subset, preserving declared node and edge 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 to adjacency](/tools/graph-to-adjacency): Convert a directed simple graph into per-node outgoing adjacency lists.
- [Graph topological sort](/tools/graph-topological-sort): Return a Kahn topological order of a directed acyclic graph, breaking ready-set ties by declared node index.
