{
  "openapi": "3.1.1",
  "info": {
    "title": "Knotwork Link Graph Analyser API",
    "version": "1.0.0",
    "summary": "Degree, groups, shortest path and PageRank for any link graph — find hubs and orphans.",
    "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://knotworklinkgraph.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Degree, groups, shortest path and PageRank for any link graph — find hubs and orphans.",
        "description": "Paste the links between your pages, issues, notes or any other items — as an edge list (“A -\u003e B”) or JSON with nodes and edges — and get the number of links per item (in, out and total), the connected groups, the most linked hubs, the most central items by PageRank, the orphans nobody links to and, if you name two items, the shortest chain of links between them. The same analysis Knotwork runs on a workspace graph.\n\nMethodology:\n- Links are directed (from → to). Duplicate links and self-loops are counted once / ignored; end points that are not listed as nodes are added.\n- Degree = number of distinct items linked with an item in either direction; in/out count links that point to / leave it. Hubs are sorted by degree, then incoming links, then input order.\n- Connected groups (weakly connected components) and the shortest path use breadth-first search with neighbours in input order, so the same input always gives the same path. The path ignores link direction unless you tick the option.\n- PageRank: power iteration of r = (1 − d)/N + d · (Σ r(j)/out(j) over items j linking here + r(dangling)/N), where items without outgoing links spread their rank over all items; it stops when the total change is below 10⁻¹⁰ (at most 200 rounds). Scores sum to 1.\n- Orphans are items with no link at all. Density = links ÷ (N · (N − 1)).",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "knotwork_link_graph",
        "x-owner-app": "knotwork",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/KnotworkLinkGraphInput"
              },
              "examples": {
                "example1": {
                  "summary": "Product team: hubs, orphans and the path from Ana to the mobile app",
                  "value": {
                    "graph": "# Product team knowledge: one link per line (from -\u003e to)\nRoadmap 2027 -\u003e Checkout redesign\nRoadmap 2027 -\u003e Mobile app\nCheckout redesign -\u003e WEB-12 Payment form\nCheckout redesign -\u003e WEB-14 Address autocomplete\nWEB-12 Payment form -\u003e WEB-14 Address autocomplete\nWEB-15 Card validation -\u003e WEB-12 Payment form\nMobile app -\u003e APP-3 Offline mode\n#design-review message -\u003e Checkout redesign\n#design-review message -\u003e WEB-12 Payment form\nCard: Usability test -\u003e Checkout redesign\nAna -\u003e WEB-12 Payment form\nBen -\u003e APP-3 Offline mode\nOld onboarding notes",
                    "from": "Ana",
                    "to": "Mobile app"
                  }
                },
                "example2": {
                  "summary": "Directed cycle: every page gets the same PageRank",
                  "value": {
                    "graph": "A -\u003e B\nB -\u003e C\nC -\u003e A",
                    "from": "",
                    "to": ""
                  }
                },
                "example3": {
                  "summary": "JSON graph with two groups",
                  "value": {
                    "graph": "{\"nodes\":[{\"id\":\"p1\",\"title\":\"Onboarding\",\"kind\":\"page\"},{\"id\":\"p2\",\"title\":\"Payroll FAQ\",\"kind\":\"page\"},{\"id\":\"i1\",\"title\":\"HR-4 Laptop order\",\"kind\":\"issue\"},{\"id\":\"p3\",\"title\":\"Office map\",\"kind\":\"page\"},{\"id\":\"p4\",\"title\":\"Parking\",\"kind\":\"page\"}],\"edges\":[{\"from\":\"p1\",\"to\":\"p2\"},{\"from\":\"p1\",\"to\":\"i1\"},{\"from\":\"p3\",\"to\":\"p4\"}]}",
                    "from": "p2",
                    "to": "i1"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/KnotworkLinkGraphResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "KnotworkLinkGraphInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "graph": {
            "title": "Links (one per line: from -\u003e to) or graph JSON",
            "description": "Lines like “A -\u003e B”, “A → B”, “A, B” or tab-separated. A line with one name adds an item without links; # starts a comment. JSON: { \"nodes\": [{ \"id\", \"title\", \"kind\" }], \"edges\": [{ \"from\", \"to\", \"kind\" }] } — the format Knotwork exports. At most 20,000 nodes and 100,000 links.",
            "type": "string",
            "maxLength": 4000000,
            "default": "# Product team knowledge: one link per line (from -\u003e to)\nRoadmap 2027 -\u003e Checkout redesign\nRoadmap 2027 -\u003e Mobile app\nCheckout redesign -\u003e WEB-12 Payment form\nCheckout redesign -\u003e WEB-14 Address autocomplete\nWEB-12 Payment form -\u003e WEB-14 Address autocomplete\nWEB-15 Card validation -\u003e WEB-12 Payment form\nMobile app -\u003e APP-3 Offline mode\n#design-review message -\u003e Checkout redesign\n#design-review message -\u003e WEB-12 Payment form\nCard: Usability test -\u003e Checkout redesign\nAna -\u003e WEB-12 Payment form\nBen -\u003e APP-3 Offline mode\nOld onboarding notes"
          },
          "from": {
            "title": "Path from (node id, optional)",
            "type": "string",
            "maxLength": 200,
            "default": ""
          },
          "to": {
            "title": "Path to (node id, optional)",
            "type": "string",
            "maxLength": 200,
            "default": ""
          },
          "directed": {
            "title": "Path follows link direction only",
            "type": "boolean",
            "default": false
          },
          "top": {
            "title": "Hubs and PageRank: show the top",
            "type": "number",
            "minimum": 1,
            "maximum": 100,
            "default": 10
          },
          "damping": {
            "title": "PageRank damping factor",
            "description": "Probability that the random surfer follows a link instead of jumping anywhere. 0.85 is the classic value.",
            "type": "number",
            "minimum": 0,
            "maximum": 0.99,
            "default": 0.85
          }
        },
        "required": [
          "graph"
        ]
      },
      "KnotworkLinkGraphResult": {
        "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": [
              "nodes",
              "edges",
              "components",
              "degree",
              "pageRank",
              "hubs",
              "topPageRank",
              "orphans",
              "stats"
            ],
            "properties": {
              "nodes": {
                "type": "integer"
              },
              "edges": {
                "type": "integer",
                "description": "Distinct directed links (duplicates and self-loops removed)."
              },
              "density": {
                "type": "number"
              },
              "components": {
                "type": "object",
                "properties": {
                  "count": {
                    "type": "integer"
                  },
                  "largest": {
                    "type": "integer"
                  },
                  "sizes": {
                    "type": "array",
                    "items": {
                      "type": "integer"
                    }
                  }
                }
              },
              "degree": {
                "type": "object",
                "properties": {
                  "min": {
                    "type": "integer"
                  },
                  "max": {
                    "type": "integer"
                  },
                  "mean": {
                    "type": "number"
                  },
                  "median": {
                    "type": "number"
                  }
                }
              },
              "pageRank": {
                "type": "object",
                "properties": {
                  "damping": {
                    "type": "number"
                  },
                  "iterations": {
                    "type": "integer"
                  },
                  "converged": {
                    "type": "boolean"
                  }
                }
              },
              "hubs": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "title": {
                      "type": "string"
                    },
                    "kind": {
                      "type": "string"
                    },
                    "in": {
                      "type": "integer"
                    },
                    "out": {
                      "type": "integer"
                    },
                    "degree": {
                      "type": "integer"
                    },
                    "pageRank": {
                      "type": "number"
                    },
                    "component": {
                      "type": "integer"
                    }
                  }
                }
              },
              "topPageRank": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "title": {
                      "type": "string"
                    },
                    "kind": {
                      "type": "string"
                    },
                    "in": {
                      "type": "integer"
                    },
                    "out": {
                      "type": "integer"
                    },
                    "degree": {
                      "type": "integer"
                    },
                    "pageRank": {
                      "type": "number"
                    },
                    "component": {
                      "type": "integer"
                    }
                  }
                }
              },
              "orphans": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "title": {
                      "type": "string"
                    },
                    "kind": {
                      "type": "string"
                    }
                  }
                }
              },
              "path": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "found": {
                    "type": "boolean"
                  },
                  "length": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  },
                  "nodes": {
                    "type": "array"
                  }
                }
              },
              "stats": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "title": {
                      "type": "string"
                    },
                    "kind": {
                      "type": "string"
                    },
                    "in": {
                      "type": "integer"
                    },
                    "out": {
                      "type": "integer"
                    },
                    "degree": {
                      "type": "integer"
                    },
                    "pageRank": {
                      "type": "number"
                    },
                    "component": {
                      "type": "integer"
                    }
                  }
                },
                "description": "Every node in input order."
              }
            }
          },
          "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"
              }
            }
          }
        }
      }
    }
  }
}