{"uid":"cap_du6Ev9dTNkhcrJev51B1b","slug":"graph-algorithms-kruskal-minimum-spanning-tree-a8186c31","name":"Graph Algorithms – Kruskal Minimum Spanning Tree","description":"Kruskal minimum spanning tree of an undirected weighted edge list; returns a spanning forest if disconnected.","url":"https://graph-algorithms.x402tookit.com/minimum-spanning-tree?utm_source=zero.xyz","method":"GET","headers":{},"bodySchema":{"type":"object","$schema":"https://json-schema.org/draft/2020-12/schema","required":["input"],"properties":{"input":{"type":"object","required":["type","method"],"properties":{"type":{"type":"string","const":"http"},"method":{"enum":["GET"],"type":"string"},"queryParams":{"type":"object","required":["edges"],"properties":{"edges":{"type":"string","description":"Edges separated by ; or newline, each 'from,to' or 'from,to,weight' (default weight 1), or a JSON array of [from,to,weight]; up to 200 nodes, 1000 edges, 60000 characters; node names 1-32 characters of letters, digits, _ . : + -. Edges are undirected"},"nodes":{"type":"string","description":"Optional extra node names (comma or space separated) so isolated nodes are counted; the total still counts toward the 200-node cap"}}}},"additionalProperties":false},"output":{"type":"object","required":["type"],"properties":{"type":{"type":"string"},"example":{"type":"object","properties":{"asOf":{"type":["null","string"]},"source":{"type":["null","string"]},"reasons":{"type":["array","null"],"items":{"type":"string"}},"summary":{"type":["null","string"]},"verdict":{"type":["null","string"]},"degraded":{"type":["boolean","null"]},"edgeCount":{"type":["null","number"]},"nodeCount":{"type":["null","number"]},"treeEdges":{"type":["array","null"],"items":{"type":"object","properties":{"to":{"type":["null","string"]},"from":{"type":["null","string"]},"weight":{"type":["null","number"]}}}},"components":{"type":["null","number"]},"disclaimer":{"type":["null","string"]},"notChecked":{"type":["array","null"],"items":{"type":"string"}},"totalWeight":{"type":["null","number"]},"treeEdgeCount":{"type":["null","number"]},"skippedSelfLoops":{"type":["null","number"]}}}}}}},"responseSchema":null,"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.02","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.02/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.02","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.02","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_6Oyq6vyx9beX-0fKDx4y0","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.02","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Computes the minimum spanning tree (or spanning forest if disconnected) of an undirected weighted edge list using Kruskal's algorithm.","exampleAgentPrompt":"Find the minimum spanning tree for this network: A,B,4; A,C,2; B,C,1; B,D,5; C,D,8; C,E,10; D,E,2 — I need to know which edges are in the MST and the total weight.","exampleUseCases":[{"title":"Network cable cost minimization","prompt":"I need to connect 5 office locations with fiber cables as cheaply as possible. The distances in km are: HQ,BranchA,12; HQ,BranchB,8; BranchA,BranchC,6; BranchB,BranchC,4; BranchA,BranchD,9; BranchC,BranchD,3. Which cables should I lay and what's the total length?"},{"title":"Cluster connectivity in data pipeline","prompt":"I have a set of microservices with estimated latency costs between them: auth,api,5; api,db,2; api,cache,1; db,storage,7; cache,storage,4; auth,cache,3. Find the minimum spanning tree so I know the minimum-latency backbone connecting all services."},{"title":"Spanning forest for disconnected graph","prompt":"My graph has two separate subnetworks with edges: X1,X2,3; X1,X3,1; X2,X3,2 and Y1,Y2,4; Y1,Y3,6; Y2,Y3,5. Can you run Kruskal's MST algorithm on this and tell me the spanning forest, total weight, and how many components there are?"}],"resultDescription":"Returns a list of tree edges (from, to, weight) forming the minimum spanning tree or spanning forest, along with the total MST weight, number of nodes and edges processed, number of connected components, tree edge count, and count of skipped self-loops. Also includes a summary string and any degradation notices.","failureModes":["More than 200 unique nodes — request rejected with node cap error","More than 1000 edges — request rejected with edge cap error","Edge string exceeds 60000 characters — payload too large","Malformed edge format (e.g. missing separator or invalid node name characters) — parse error returned","Node names containing characters outside allowed set (letters, digits, _ . : + -) — validation error"],"whenToPreferThis":"Use this endpoint when you need the globally optimal minimum spanning tree or spanning forest for an undirected weighted graph, especially for network design, clustering, or cost minimization problems. Prefer this over shortest-path endpoints (Dijkstra, Bellman-Ford) when the goal is connecting all nodes at minimum total cost rather than finding the fastest route between two specific nodes. Choose this over Floyd-Warshall when you need spanning connectivity rather than all-pairs distances.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-11-02T12:30:44.843Z","isFirstParty":false,"canonicalSlug":"graph-algorithms-kruskal-minimum-spanning-tree-a8186c31"}