Graph ancestors
graph-ancestors · version 1.0.0 · Graphs & scheduling · free, no key needed
List every ancestor of given targets, including the targets, in reverse-graph BFS discovery order.
Use when you need to: graph ancestors · upstream prerequisites of targets · ancestors of graph nodes.
Supported
- graph ancestors
- upstream prerequisites of targets
- ancestors of graph nodes
Not supported
- dominance
- immediate parents only
- undirected ancestor search
- enumerating every ancestor path
Behavior
- Input is a directed simple graph plus a non-empty targets array of unique existing node ids.
- An original edge from u to v means u is a prerequisite of v and a reverse-graph successor of v.
- The output nodes array is reverse-graph BFS discovery order, including every target.
- Targets are enqueued in the given targets array order, skipping an id already queued.
- After a node is popped, unseen reverse-graph neighbors are pushed in the declared order of original incoming edges.
- A target is included even when it has no incoming edges.
- Empty graph cannot name a target and is rejected.
- Self-loops and directed cycles are allowed; first visit wins.
- Unknown fields, duplicate nodes or edges, missing endpoints, and unknown or duplicate targets are rejected.
Input
nodes(array of string, required): max items 2000; each min length 1; each max length 256edges(array of object, required): max items 10000targets(array of string, required): min items 1; max items 2000; each min length 1; each max length 256
Output
nodes(array of string, required)
Limits
- max nodes: 2000
- max edges: 10000
- max node id bytes: 256
- max targets: 2000
Example
Request input:
{
"nodes": [
"compile",
"test",
"lint",
"package",
"deploy"
],
"edges": [
{
"from": "compile",
"to": "test"
},
{
"from": "compile",
"to": "package"
},
{
"from": "lint",
"to": "package"
},
{
"from": "test",
"to": "deploy"
},
{
"from": "package",
"to": "deploy"
}
],
"targets": [
"deploy"
]
}
Response:
{
"result": {
"nodes": [
"deploy",
"test",
"package",
"compile",
"lint"
]
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "graph-ancestors",
"version": "1.0.0",
"input": {
"nodes": [
"compile",
"test",
"lint",
"package",
"deploy"
],
"edges": [
{
"from": "compile",
"to": "test"
},
{
"from": "compile",
"to": "package"
},
{
"from": "lint",
"to": "package"
},
{
"from": "test",
"to": "deploy"
},
{
"from": "package",
"to": "deploy"
}
],
"targets": [
"deploy"
]
}
}
HTTP (no key)
curl -X POST https://computefirst.net/v1/tools/graph-ancestors/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"nodes":["compile","test","lint","package","deploy"],"edges":[{"from":"compile","to":"test"},{"from":"compile","to":"package"},{"from":"lint","to":"package"},{"from":"test","to":"deploy"},{"from":"package","to":"deploy"}],"targets":["deploy"]}'
The machine-readable contract is at /v1/tools/graph-ancestors/versions/1.0.0.
CLI
node cli.mjs run graph-ancestors 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- Graph dependency impact: List nodes downstream of a removed set: not themselves removed, reachable by a directed path of length at least 1.
- Graph induced subgraph: Return the vertex-induced subgraph on a listed node subset, preserving declared node and edge order.
- Graph reachable from: List nodes reachable from given sources by directed BFS, in discovery order.
- Graph shortest unweighted path: Find a shortest directed path by fewest edges from source to target.
- Graph validate: Inspect a well-formed directed simple graph and report counts, isolated nodes, and maximum degrees.
- Graph connected components: Partition a directed simple graph into undirected connected components, ignoring edge direction.