{
  "openapi": "3.1.1",
  "info": {
    "title": "Graph Algorithm Visualizer API",
    "version": "1.0.0",
    "summary": "BFS, DFS, Dijkstra, Bellman–Ford, A*, MST, topological sort and SCCs on your edge list.",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://graphalgorithmvisualizer.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "BFS, DFS, Dijkstra, Bellman–Ford, A*, MST, topological sort and SCCs on your edge list.",
        "description": "Paste an edge list (weighted or not, directed or not) and run a classic graph algorithm: BFS, DFS, Dijkstra, Bellman–Ford (with negative-cycle detection), A* with node coordinates, Prim or Kruskal minimum spanning tree, Kahn topological sort or Tarjan strongly connected components. Shows every step, the distances and the highlighted path or tree.\n\nMethodology:\n- Neighbours are visited in the order nodes first appear in your edge list, so every run is deterministic. Undirected edges are usable in both directions.\n- BFS finds fewest-edge paths; DFS records discovery and finish times. Dijkstra settles nodes in order of distance with a binary heap and refuses negative weights; Bellman–Ford relaxes all edges up to n − 1 times and then checks for a negative cycle.\n- A* is Dijkstra ordered by g + h with h = straight-line distance between coordinates. It returns optimal paths when h never overestimates (admissible) and is consistent; the tool warns when an edge is shorter than its straight-line length.\n- Prim grows a tree from the start node (a forest if the graph is disconnected); Kruskal adds the cheapest edges that do not close a cycle (union–find). Kahn's algorithm outputs nodes without remaining incoming edges and detects cycles; Tarjan's algorithm finds strongly connected components in one DFS.",
        "tags": [
          "math"
        ],
        "x-mcp-tool": "graph_algorithm_visualizer",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GraphAlgorithmVisualizerInput"
              },
              "examples": {
                "example1": {
                  "summary": "Dijkstra from A to F",
                  "value": {
                    "algorithm": "dijkstra",
                    "source": "A",
                    "target": "F"
                  }
                },
                "example2": {
                  "summary": "Kruskal MST",
                  "value": {
                    "algorithm": "kruskal"
                  }
                },
                "example3": {
                  "summary": "Topological sort of build steps",
                  "value": {
                    "directed": true,
                    "algorithm": "topo",
                    "edges": "fetch compile\ncompile test\ncompile package\ntest release\npackage release\nlint release"
                  }
                },
                "example4": {
                  "summary": "Bellman–Ford with a negative edge",
                  "value": {
                    "directed": true,
                    "algorithm": "bellman-ford",
                    "source": "S",
                    "target": "D",
                    "edges": "S A 4\nS B 5\nA C -3\nB C 2\nC D 2\nB D 6"
                  }
                },
                "example5": {
                  "summary": "A* on a grid",
                  "value": {
                    "algorithm": "astar",
                    "source": "S",
                    "target": "G",
                    "edges": "S A 1\nA B 1\nB G 1\nS C 1.5\nC D 1.5\nD G 1.5\nA C 1",
                    "coordinates": "S 0 0\nA 1 0\nB 2 0\nG 3 0\nC 0.5 1\nD 2 1"
                  }
                },
                "example6": {
                  "summary": "Strongly connected components",
                  "value": {
                    "directed": true,
                    "algorithm": "scc",
                    "edges": "1 2\n2 3\n3 1\n3 4\n4 5\n5 6\n6 4\n7 6\n7 8\n8 7"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GraphAlgorithmVisualizerResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "GraphAlgorithmVisualizerInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "edges": {
            "title": "Edges (one per line: from to [weight])",
            "description": "Formats: \"A B 4\", \"A -> B 4\", \"A,B,4\". A line with one name adds an isolated node. # starts a comment. Max 200 nodes, 2,000 edges.",
            "type": "string",
            "maxLength": 40000,
            "default": "A B 4\nA C 2\nB C 5\nB D 10\nC E 3\nE D 4\nD F 11"
          },
          "directed": {
            "title": "Directed edges",
            "type": "boolean",
            "default": false
          },
          "algorithm": {
            "title": "Algorithm",
            "type": "string",
            "enum": [
              "bfs",
              "dfs",
              "dijkstra",
              "bellman-ford",
              "astar",
              "prim",
              "kruskal",
              "topo",
              "scc"
            ],
            "default": "dijkstra"
          },
          "source": {
            "title": "Start node",
            "description": "Default: the first node. Used by BFS, DFS, Dijkstra, Bellman–Ford, A* and Prim.",
            "type": "string",
            "maxLength": 40
          },
          "target": {
            "title": "Target node",
            "description": "Optional for searches; required for A*.",
            "type": "string",
            "maxLength": 40
          },
          "coordinates": {
            "title": "Node coordinates (node x y), for A* and layout",
            "description": "A* uses the straight-line distance as heuristic; it is admissible only if no edge is shorter than the distance between its end points.",
            "type": "string",
            "maxLength": 20000
          }
        },
        "required": [
          "edges"
        ]
      },
      "GraphAlgorithmVisualizerResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "required": [
              "algorithm",
              "directed",
              "weighted",
              "nodeCount",
              "edgeCount",
              "steps"
            ],
            "properties": {
              "algorithm": {
                "type": "string"
              },
              "directed": {
                "type": "boolean"
              },
              "weighted": {
                "type": "boolean"
              },
              "nodeCount": {
                "type": "integer"
              },
              "edgeCount": {
                "type": "integer"
              },
              "source": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "target": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "order": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "Visit / settle / output order."
              },
              "distances": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "node",
                    "distance",
                    "previous"
                  ],
                  "properties": {
                    "node": {
                      "type": "string"
                    },
                    "distance": {
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "previous": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              },
              "path": {
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "type": "string"
                }
              },
              "pathCost": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "mst": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "total": {
                    "type": "number"
                  },
                  "edges": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "components": {
                    "type": "integer"
                  }
                }
              },
              "topologicalOrder": {
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "type": "string"
                }
              },
              "components": {
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              },
              "negativeCycle": {
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "type": "string"
                }
              },
              "steps": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "step",
                    "detail"
                  ],
                  "properties": {
                    "step": {
                      "type": "integer"
                    },
                    "action": {
                      "type": "string"
                    },
                    "node": {
                      "type": "string"
                    },
                    "detail": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}