# Topological Sort Calculator API

> For the complete documentation index, see [llms.txt](/llms.txt).

Topologically order a directed graph with Kahn or DFS, detect cycles, and report layers, sources, sinks, longest path, and the number of valid orderings.

Use this endpoint to add the tool to your app, site, workflow, or agent without rebuilding formulas, validation, examples, and docs.

- Slug: `topological-sort-calculator`
- Category: `math`
- Version: `2026-04-22`
- Credits per successful call: 1
- Starts on: free
- Max payload: 262144 bytes
- Privacy mode: `hash_only`
- Available on: free, starter, pro, business, scale
- Browser tool: https://miniwebtool.com/topological-sort-calculator/

## Endpoint

`POST https://api.miniwebtool.com/v1/tools/topological-sort-calculator/run`

## Request body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `edges` | `str` | no | directed edges, e.g. A->B, B->C |
| `extra_vertices` | `str` | no | optional isolated vertices to include |
| `method` | `str` | no | lexicographic | insertion | dfs Choices: lexicographic, insertion, dfs |

## Example request

```json
{
  "edges": "A->B, A->C, B->D, C->D, D->E",
  "method": "lexicographic"
}
```

## cURL

```bash
curl -X POST https://api.miniwebtool.com/v1/tools/topological-sort-calculator/run \
  -H 'Authorization: Bearer mwt_live_YOUR_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"edges":"A->B, A->C, B->D, C->D, D->E","method":"lexicographic"}'
```

## Response envelope

```json
{
  "request_id": "01K...",
  "tool": "topological-sort-calculator",
  "tool_version": "2026-04-22",
  "credits_used": 1,
  "result": {}
}
```

## Errors

Errors are RFC 7807 `application/problem+json`. Branch on `code`, not `title`.

## MCP

Agents can discover and call this tool through `https://api.miniwebtool.com/mcp` or `https://api.miniwebtool.com/v1/mcp` using MCP `tools/list` and `tools/call`.

## Frequently asked

### What does the Topological Sort Calculator API do?

Topologically order a directed graph with Kahn or DFS, detect cycles, and report layers, sources, sinks, longest path, and the number of valid orderings. Use it to add this utility without rebuilding formulas, validation, examples, and documentation.

### How much does one call cost?

1 credit per successful call. Failed calls do not bill.

### What parameters are required?

Required fields: (none). Full schema at `https://api.miniwebtool.com/v1/openapi.json`.

### Is this deterministic?

Yes. Same input, same output. Tool version: 2026-04-22.
