CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 | /**
* Expanded MCP tool surface — wraps every meaningful Gluecron action so
* any AI tool-use loop can drive the platform end-to-end.
*
* Each tool here is a THIN wrapper around an existing lib helper or a
* REST handler's underlying primitives — we never duplicate business
* logic. Auth/gating reuses the shared helpers exported from
* `mcp-tools.ts`.
*
* Categories (per the build spec):
*
* REPOS fork / delete / update / search / clone_url
* ISSUES close / reopen / label / unlabel / assign / search
* PRS close / request_changes / search / open_draft /
* generate_description
* FILES & GIT read_file / write_file / delete_file / list_tree /
* get_commit / create_branch / atomic_multi_file_commit
* AI WORKFLOWS ship_spec / voice_to_pr / refactor_across_repos /
* explain_repo / chat_with_repo / chat_continue /
* generate_tests / generate_commit_message /
* generate_release_notes / propose_migration /
* propose_doc_update
* CI / DEPLOYS trigger_workflow / get_workflow_run /
* get_workflow_logs / cancel_workflow_run /
* get_preview_url / provision_pr_sandbox
* AGENTS create_agent_session / acquire_lease /
* release_lease / get_agent_budget
* SEMANTIC semantic_search / find_symbol
* INSIGHTS pr_status_summary / repo_health / ai_cost_summary
*
* Scope contract:
* - Read-only tools accept any authenticated caller (anonymous works
* on public repos via the existing `resolveAccessibleRepo` flow).
* - Write tools require `repo` scope.
* - Destructive tools (delete_repo) require `admin` scope.
*/
import { and, eq, like, or, desc, asc } from "drizzle-orm";
import { db } from "../db";
import {
repositories,
users,
issues,
issueComments,
pullRequests,
prComments,
labels,
issueLabels,
workflows,
workflowRuns,
workflowJobs,
} from "../db/schema";
import {
repoExists,
getRepoPath,
getBlob,
getTree,
getTreeRecursive,
getCommit,
resolveRef,
refExists,
objectExists,
updateRef,
writeBlob,
createOrUpdateFileOnBranch,
getBlobShaAtPath,
} from "../git/repository";
import { join } from "path";
import { mkdir, unlink, rm } from "fs/promises";
import { config } from "./config";
import { McpError, ERR_INVALID_PARAMS, ERR_METHOD_NOT_FOUND } from "./mcp";
import type { McpContext } from "./mcp";
import type { McpToolHandler } from "./mcp-tools";
import {
mcpArgString,
mcpArgNumber,
mcpGateWriteAccess,
mcpResolveAccessibleRepo,
mcpRequireAuthedCtx,
mcpLoadPrByNumber,
mcpLoadIssueByNumber,
mcpPrUrl,
mcpIssueUrl,
} from "./mcp-tools";
// ---------------------------------------------------------------------------
// Local helpers
// ---------------------------------------------------------------------------
/**
* Require a scope on the caller's token. Session-cookie callers receive
* `["repo","user","admin"]` so they always pass. Anonymous and limited
* PATs may fail here. When `ctx.scopes` is undefined we treat the context
* as legacy-permissive (matches the pre-expansion behaviour of the
* existing 15-tool surface).
*/
function requireScope(ctx: McpContext, scope: string, toolName: string): void {
// Undefined scopes → legacy/permissive. Anonymous (no userId) is caught
// separately by `requireAuthedCtx` further upstream.
if (ctx.scopes === undefined) return;
if (ctx.scopes.includes(scope) || ctx.scopes.includes("admin")) return;
throw new McpError(
ERR_INVALID_PARAMS,
`tool ${toolName} requires '${scope}' scope (token carries: ${ctx.scopes.join(",") || "none"})`
);
}
function argBool(args: Record<string, unknown>, key: string, fallback = false): boolean {
const v = args[key];
if (typeof v === "boolean") return v;
if (typeof v === "string") return v === "true" || v === "1";
return fallback;
}
function argStringArray(args: Record<string, unknown>, key: string): string[] {
const v = args[key];
if (Array.isArray(v)) return v.filter((x): x is string => typeof x === "string");
return [];
}
// ---------------------------------------------------------------------------
// REPOS
// ---------------------------------------------------------------------------
const forkRepo: McpToolHandler = {
tool: {
name: "gluecron_fork_repo",
description:
"Fork a repository to the authenticated caller's namespace. Mirrors POST /:owner/:repo/fork. Returns {owner, repo, url}. Requires 'repo' scope.",
annotations: { title: "Fork repository", readOnlyHint: false, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string", description: "Source repo owner" },
repo: { type: "string", description: "Source repo name" },
},
required: ["owner", "repo"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const userId = mcpRequireAuthedCtx(ctx, "gluecron_fork_repo");
requireScope(ctx, "repo", "gluecron_fork_repo");
const info = await mcpResolveAccessibleRepo(owner, repo, userId);
const [me] = await db
.select({ id: users.id, username: users.username })
.from(users)
.where(eq(users.id, userId))
.limit(1);
if (!me) throw new McpError(ERR_INVALID_PARAMS, "caller user not found");
if (me.username === owner) {
throw new McpError(ERR_INVALID_PARAMS, "cannot fork your own repository");
}
if (await repoExists(me.username, repo)) {
throw new McpError(
ERR_INVALID_PARAMS,
`${me.username}/${repo} already exists`
);
}
const sourcePath = getRepoPath(owner, repo);
const destPath = join(config.gitReposPath, me.username, `${repo}.git`);
const proc = Bun.spawn(["git", "clone", "--bare", sourcePath, destPath], {
stdout: "pipe",
stderr: "pipe",
});
const code = await proc.exited;
if (code !== 0) {
throw new McpError(ERR_INVALID_PARAMS, "git clone --bare failed");
}
const [sourceRepo] = await db
.select()
.from(repositories)
.where(eq(repositories.id, info.repoId))
.limit(1);
if (!sourceRepo) throw new McpError(ERR_METHOD_NOT_FOUND, "source repo row missing");
const [newRepo] = await db
.insert(repositories)
.values({
name: repo,
ownerId: me.id,
description: sourceRepo.description
? `Fork of ${owner}/${repo} — ${sourceRepo.description}`
: `Fork of ${owner}/${repo}`,
isPrivate: false,
defaultBranch: sourceRepo.defaultBranch,
diskPath: destPath,
forkedFromId: sourceRepo.id,
})
.returning();
if (newRepo) {
try {
const { bootstrapRepository } = await import("./repo-bootstrap");
await bootstrapRepository({
repositoryId: newRepo.id,
ownerUserId: me.id,
defaultBranch: sourceRepo.defaultBranch,
skipWelcomeIssue: true,
});
} catch {
/* bootstrap is non-fatal */
}
}
try {
await db
.update(repositories)
.set({ forkCount: (sourceRepo.forkCount ?? 0) + 1 })
.where(eq(repositories.id, sourceRepo.id));
} catch {
/* non-fatal */
}
return {
owner: me.username,
repo,
url: `/${me.username}/${repo}`,
};
},
};
const deleteRepo: McpToolHandler = {
tool: {
name: "gluecron_delete_repo",
description:
"Permanently delete a repository row (git data on disk is left untouched). Owner-only. Requires 'admin' scope. Returns {deleted: true}.",
annotations: { title: "Delete repository", readOnlyHint: false, destructiveHint: true },
inputSchema: {
type: "object",
properties: {
owner: { type: "string", description: "Repo owner username" },
repo: { type: "string", description: "Repo name" },
},
required: ["owner", "repo"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
requireScope(ctx, "admin", "gluecron_delete_repo");
const gate = await mcpGateWriteAccess({ owner, repo }, ctx, "gluecron_delete_repo");
if (gate.ownerId !== gate.userId) {
throw new McpError(
ERR_METHOD_NOT_FOUND,
`no admin access to ${owner}/${repo}`
);
}
await db.delete(repositories).where(eq(repositories.id, gate.repoId));
return { deleted: true };
},
};
const updateRepo: McpToolHandler = {
tool: {
name: "gluecron_update_repo",
description:
"Update repository description / visibility / default_branch. Owner-only. Requires 'repo' scope. Returns {ok: true}.",
// Destructive: overwrites prior settings (old values unrecoverable) and can flip visibility.
annotations: { title: "Update repository settings", readOnlyHint: false, destructiveHint: true },
inputSchema: {
type: "object",
properties: {
owner: { type: "string", description: "Repo owner username" },
repo: { type: "string", description: "Repo name" },
description: { type: "string", description: "New description (optional)" },
is_private: { type: "boolean", description: "Set visibility (optional)" },
default_branch: { type: "string", description: "Set default branch (optional)" },
},
required: ["owner", "repo"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
requireScope(ctx, "repo", "gluecron_update_repo");
const gate = await mcpGateWriteAccess({ owner, repo }, ctx, "gluecron_update_repo");
if (gate.ownerId !== gate.userId) {
throw new McpError(
ERR_METHOD_NOT_FOUND,
`no admin access to ${owner}/${repo}`
);
}
const updates: Record<string, unknown> = { updatedAt: new Date() };
if (typeof args.description === "string") updates.description = args.description;
if (typeof args.is_private === "boolean") updates.isPrivate = args.is_private;
if (typeof args.default_branch === "string") updates.defaultBranch = args.default_branch;
if (Object.keys(updates).length === 1) {
return { ok: true, noop: true };
}
await db.update(repositories).set(updates).where(eq(repositories.id, gate.repoId));
return { ok: true };
},
};
const searchRepos: McpToolHandler = {
tool: {
name: "gluecron_search_repos",
description:
"Full-text search of public repositories by name/description. Mirrors GET /api/v2/search/repos. Returns ranked rows.",
annotations: { title: "Search repositories (ranked)", readOnlyHint: true, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
query: { type: "string", description: "Search keyword" },
sort: { type: "string", description: "stars | updated | name (default: stars)" },
limit: { type: "number", description: "Max results (1-100, default 30)" },
},
required: ["query"],
},
},
async run(args) {
const q = mcpArgString(args, "query");
const sort = mcpArgString(args, "sort", "stars");
const limit = Math.max(1, Math.min(100, mcpArgNumber(args, "limit", 30)));
const orderBy =
sort === "updated"
? desc(repositories.updatedAt)
: sort === "name"
? asc(repositories.name)
: desc(repositories.starCount);
const pattern = `%${q.replace(/[%_]/g, (m) => "\\" + m)}%`;
const rows = await db
.select({
id: repositories.id,
name: repositories.name,
description: repositories.description,
stars: repositories.starCount,
forks: repositories.forkCount,
ownerName: users.username,
})
.from(repositories)
.innerJoin(users, eq(repositories.ownerId, users.id))
.where(
and(
eq(repositories.isPrivate, false),
or(
like(repositories.name, pattern),
like(repositories.description, pattern)
)
)
)
.orderBy(orderBy)
.limit(limit);
return {
total: rows.length,
repos: rows.map((r) => ({
fullName: `${r.ownerName}/${r.name}`,
description: r.description || "",
stars: r.stars,
forks: r.forks,
})),
};
},
};
const cloneUrl: McpToolHandler = {
tool: {
name: "gluecron_clone_url",
description:
"Return the authenticated HTTPS clone URL for a repo + a credential-helper hint. Use this instead of embedding tokens in URLs. Returns {url, hint}.",
annotations: { title: "Get clone URL", readOnlyHint: true, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string", description: "Repo owner username" },
repo: { type: "string", description: "Repo name" },
},
required: ["owner", "repo"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
// Verify access; rejects private-without-access via the privacy
// contract.
await mcpResolveAccessibleRepo(owner, repo, ctx.userId);
const base = config.appBaseUrl?.replace(/\/$/, "") || "https://gluecron.com";
return {
url: `${base}/${owner}/${repo}.git`,
hint:
"Use a credential helper rather than embedding a PAT in the URL:\n" +
` git -c credential.helper='!f() { echo "username=token"; echo "password=$GLUECRON_PAT"; }; f' clone ${base}/${owner}/${repo}.git`,
};
},
};
// ---------------------------------------------------------------------------
// ISSUES — label/unlabel/assign/search (close/reopen already live in mcp-tools)
// ---------------------------------------------------------------------------
const labelIssue: McpToolHandler = {
tool: {
name: "gluecron_label_issue",
description:
"Attach one or more labels to an issue. Labels are created if they don't yet exist on the repo. Requires 'repo' scope. Returns {labels}.",
annotations: { title: "Label issue", readOnlyHint: false, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
number: { type: "number" },
labels: { type: "array", description: "Label names (strings)" },
},
required: ["owner", "repo", "number", "labels"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const number = mcpArgNumber(args, "number");
const labelNames = argStringArray(args, "labels");
if (labelNames.length === 0) {
throw new McpError(ERR_INVALID_PARAMS, "labels must be a non-empty array of strings");
}
requireScope(ctx, "repo", "gluecron_label_issue");
const gate = await mcpGateWriteAccess({ owner, repo }, ctx, "gluecron_label_issue");
const issue = await mcpLoadIssueByNumber(gate.repoId, number);
if (!issue) {
throw new McpError(ERR_METHOD_NOT_FOUND, `issue not found: ${owner}/${repo}#${number}`);
}
const applied: string[] = [];
for (const name of labelNames) {
const trimmed = name.trim();
if (!trimmed) continue;
// Ensure label row exists.
let [labelRow] = await db
.select()
.from(labels)
.where(and(eq(labels.repositoryId, gate.repoId), eq(labels.name, trimmed)))
.limit(1);
if (!labelRow) {
const inserted = await db
.insert(labels)
.values({ repositoryId: gate.repoId, name: trimmed })
.returning();
labelRow = inserted[0];
}
if (!labelRow) continue;
try {
await db
.insert(issueLabels)
.values({ issueId: issue.id, labelId: labelRow.id });
} catch {
/* unique violation — already attached */
}
applied.push(trimmed);
}
return { labels: applied };
},
};
const unlabelIssue: McpToolHandler = {
tool: {
name: "gluecron_unlabel_issue",
description:
"Detach a label from an issue. Idempotent. Requires 'repo' scope. Returns {removed: boolean}.",
// Removal is trivially reversible (re-attach the label) — not destructive.
annotations: { title: "Remove issue label", readOnlyHint: false, destructiveHint: false, idempotentHint: true },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
number: { type: "number" },
label: { type: "string" },
},
required: ["owner", "repo", "number", "label"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const number = mcpArgNumber(args, "number");
const labelName = mcpArgString(args, "label");
requireScope(ctx, "repo", "gluecron_unlabel_issue");
const gate = await mcpGateWriteAccess({ owner, repo }, ctx, "gluecron_unlabel_issue");
const issue = await mcpLoadIssueByNumber(gate.repoId, number);
if (!issue) {
throw new McpError(ERR_METHOD_NOT_FOUND, `issue not found: ${owner}/${repo}#${number}`);
}
const [labelRow] = await db
.select()
.from(labels)
.where(and(eq(labels.repositoryId, gate.repoId), eq(labels.name, labelName)))
.limit(1);
if (!labelRow) return { removed: false };
const result = await db
.delete(issueLabels)
.where(and(eq(issueLabels.issueId, issue.id), eq(issueLabels.labelId, labelRow.id)))
.returning({ id: issueLabels.id });
return { removed: result.length > 0 };
},
};
const assignIssue: McpToolHandler = {
tool: {
name: "gluecron_assign_issue",
description:
"Assign an issue to a user. Gluecron does not yet have a dedicated assignee table; assignment is modelled as an `assignee:<username>` label so it integrates with existing label tooling. Requires 'repo' scope.",
annotations: { title: "Assign issue", readOnlyHint: false, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
number: { type: "number" },
assignee: { type: "string", description: "Username to assign" },
},
required: ["owner", "repo", "number", "assignee"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const number = mcpArgNumber(args, "number");
const assignee = mcpArgString(args, "assignee");
return await labelIssue.run(
{ owner, repo, number, labels: [`assignee:${assignee}`] },
ctx
);
},
};
const searchIssues: McpToolHandler = {
tool: {
name: "gluecron_search_issues",
description:
"Search issues by title/body keyword on a single repo, filtered by state. Returns ranked rows.",
annotations: { title: "Search issues", readOnlyHint: true, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
query: { type: "string", description: "Search keyword" },
state: { type: "string", description: "open | closed | all (default open)" },
limit: { type: "number" },
},
required: ["owner", "repo", "query"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const q = mcpArgString(args, "query");
const state = mcpArgString(args, "state", "open");
const limit = Math.max(1, Math.min(100, mcpArgNumber(args, "limit", 25)));
const info = await mcpResolveAccessibleRepo(owner, repo, ctx.userId);
const pattern = `%${q.replace(/[%_]/g, (m) => "\\" + m)}%`;
const stateClause =
state === "all"
? eq(issues.repositoryId, info.repoId)
: and(eq(issues.repositoryId, info.repoId), eq(issues.state, state));
const rows = await db
.select({
number: issues.number,
title: issues.title,
body: issues.body,
state: issues.state,
createdAt: issues.createdAt,
})
.from(issues)
.where(
and(
stateClause,
or(like(issues.title, pattern), like(issues.body, pattern))
)
)
.orderBy(desc(issues.createdAt))
.limit(limit);
return {
total: rows.length,
issues: rows.map((r) => ({
number: r.number,
title: r.title,
body: r.body || "",
state: r.state,
url: mcpIssueUrl(owner, repo, r.number),
createdAt: r.createdAt,
})),
};
},
};
// ---------------------------------------------------------------------------
// PRS — close (already), request_changes, search, draft, generate_description
// ---------------------------------------------------------------------------
const requestChanges: McpToolHandler = {
tool: {
name: "gluecron_request_changes",
description:
"Post a 'changes requested' AI-review comment on a PR. The comment is tagged with isAiReview=true so the gate-checker recognises it. Requires 'repo' scope.",
annotations: { title: "Request PR changes", readOnlyHint: false, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
number: { type: "number" },
body: { type: "string", description: "Review body (Markdown)" },
},
required: ["owner", "repo", "number", "body"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const number = mcpArgNumber(args, "number");
const body = mcpArgString(args, "body");
requireScope(ctx, "repo", "gluecron_request_changes");
const gate = await mcpGateWriteAccess({ owner, repo }, ctx, "gluecron_request_changes");
const pr = await mcpLoadPrByNumber(gate.repoId, number);
if (!pr) {
throw new McpError(ERR_METHOD_NOT_FOUND, `pr not found: ${owner}/${repo}#${number}`);
}
const formatted = `**Changes requested**\n\n${body}`;
const [inserted] = await db
.insert(prComments)
.values({
pullRequestId: pr.id,
authorId: gate.userId,
body: formatted,
isAiReview: true,
})
.returning();
return { commentId: inserted.id };
},
};
const searchPrs: McpToolHandler = {
tool: {
name: "gluecron_search_prs",
description: "Search pull requests by title/body keyword on a repo.",
annotations: { title: "Search pull requests", readOnlyHint: true, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
query: { type: "string" },
state: { type: "string", description: "open|closed|merged|all (default open)" },
limit: { type: "number" },
},
required: ["owner", "repo", "query"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const q = mcpArgString(args, "query");
const state = mcpArgString(args, "state", "open");
const limit = Math.max(1, Math.min(100, mcpArgNumber(args, "limit", 25)));
const info = await mcpResolveAccessibleRepo(owner, repo, ctx.userId);
const pattern = `%${q.replace(/[%_]/g, (m) => "\\" + m)}%`;
const stateClause =
state === "all"
? eq(pullRequests.repositoryId, info.repoId)
: and(eq(pullRequests.repositoryId, info.repoId), eq(pullRequests.state, state));
const rows = await db
.select({
number: pullRequests.number,
title: pullRequests.title,
body: pullRequests.body,
state: pullRequests.state,
baseBranch: pullRequests.baseBranch,
headBranch: pullRequests.headBranch,
isDraft: pullRequests.isDraft,
createdAt: pullRequests.createdAt,
})
.from(pullRequests)
.where(
and(
stateClause,
or(like(pullRequests.title, pattern), like(pullRequests.body, pattern))
)
)
.orderBy(desc(pullRequests.createdAt))
.limit(limit);
return {
total: rows.length,
prs: rows.map((p) => ({
number: p.number,
title: p.title,
body: p.body || "",
state: p.state,
baseBranch: p.baseBranch,
headBranch: p.headBranch,
isDraft: p.isDraft,
url: mcpPrUrl(owner, repo, p.number),
createdAt: p.createdAt,
})),
};
},
};
const openDraftPr: McpToolHandler = {
tool: {
name: "gluecron_open_draft_pr",
description:
"Open a draft pull request. Same payload as gluecron_create_pr but forces is_draft=true. Useful for AI-in-progress PRs that shouldn't run mergeability checks yet.",
annotations: { title: "Open draft pull request", readOnlyHint: false, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
title: { type: "string" },
body: { type: "string" },
head_branch: { type: "string" },
base_branch: { type: "string" },
},
required: ["owner", "repo", "title", "head_branch"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const title = mcpArgString(args, "title");
const body = mcpArgString(args, "body", "");
const headBranch = mcpArgString(args, "head_branch");
requireScope(ctx, "repo", "gluecron_open_draft_pr");
const gate = await mcpGateWriteAccess({ owner, repo }, ctx, "gluecron_open_draft_pr");
const baseBranch = mcpArgString(args, "base_branch", gate.defaultBranch);
if (baseBranch === headBranch) {
throw new McpError(ERR_INVALID_PARAMS, "base and head branches must be different");
}
const [pr] = await db
.insert(pullRequests)
.values({
repositoryId: gate.repoId,
authorId: gate.userId,
title,
body: body || null,
baseBranch,
headBranch,
isDraft: true,
})
.returning();
return { number: pr.number, url: mcpPrUrl(owner, repo, pr.number), isDraft: true };
},
};
const generatePrDescription: McpToolHandler = {
tool: {
name: "gluecron_generate_pr_description",
description:
"Generate an AI commit-message-style description for a diff. Uses src/lib/ai-commit-message.ts under the hood; gracefully degrades to a heuristic when ANTHROPIC_API_KEY is missing. Returns {subject, body}.",
// Pure compute over the supplied diff — persists nothing.
annotations: { title: "Generate PR description", readOnlyHint: true, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
diff: { type: "string", description: "Unified-diff body" },
style: {
type: "string",
description: "'conventional' (default) or 'plain'",
},
},
required: ["diff"],
},
},
async run(args) {
const diff = mcpArgString(args, "diff");
const style = mcpArgString(args, "style", "conventional");
const { generateCommitMessage } = await import("./ai-commit-message");
const msg = await generateCommitMessage(diff, {
style: style === "plain" ? "plain" : "conventional",
});
return msg;
},
};
// ---------------------------------------------------------------------------
// FILES & GIT PLUMBING
// ---------------------------------------------------------------------------
const readFile: McpToolHandler = {
tool: {
name: "gluecron_read_file",
description:
"Read a file from a repo at a given ref. Mirrors GET /api/v2/repos/:owner/:repo/contents/:path. Returns {path, size, content, encoding}.",
annotations: { title: "Read file", readOnlyHint: true, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
ref: { type: "string", description: "Branch / tag / sha (default HEAD)" },
path: { type: "string" },
encoding: { type: "string", description: "'utf8' (default) or 'base64'" },
},
required: ["owner", "repo", "path"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const ref = mcpArgString(args, "ref", "HEAD");
const filePath = mcpArgString(args, "path");
await mcpResolveAccessibleRepo(owner, repo, ctx.userId);
const blob = await getBlob(owner, repo, ref, filePath);
if (!blob) {
throw new McpError(ERR_METHOD_NOT_FOUND, `path not found: ${owner}/${repo}@${ref}:${filePath}`);
}
return {
path: filePath,
size: blob.size,
isBinary: blob.isBinary,
content: blob.isBinary ? null : blob.content,
encoding: blob.isBinary ? null : "utf8",
};
},
};
const writeFile: McpToolHandler = {
tool: {
name: "gluecron_write_file",
description:
"Create or update a file on a branch via git plumbing. Wraps `createOrUpdateFileOnBranch`. Pass `content` as a UTF-8 string OR `content_base64` for binary. Requires 'repo' scope.",
// Overwrites are recoverable from git history — not destructive.
annotations: { title: "Write file", readOnlyHint: false, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
path: { type: "string" },
branch: { type: "string" },
message: { type: "string", description: "Commit message" },
content: { type: "string", description: "UTF-8 file body (optional)" },
content_base64: { type: "string", description: "Base64 file body (optional)" },
expect_blob_sha: {
type: "string",
description: "Optimistic-concurrency check: existing blob sha must match.",
},
},
required: ["owner", "repo", "path", "branch", "message"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const filePath = mcpArgString(args, "path");
const branch = mcpArgString(args, "branch");
const message = mcpArgString(args, "message");
requireScope(ctx, "repo", "gluecron_write_file");
const gate = await mcpGateWriteAccess({ owner, repo }, ctx, "gluecron_write_file");
let bytes: Uint8Array;
if (typeof args.content === "string") {
bytes = new TextEncoder().encode(args.content);
} else if (typeof args.content_base64 === "string") {
try {
bytes = new Uint8Array(Buffer.from(args.content_base64, "base64"));
} catch {
throw new McpError(ERR_INVALID_PARAMS, "content_base64 is not valid base64");
}
} else {
throw new McpError(ERR_INVALID_PARAMS, "either content or content_base64 is required");
}
const [author] = await db
.select({ username: users.username, email: users.email })
.from(users)
.where(eq(users.id, gate.userId))
.limit(1);
if (!author) throw new McpError(ERR_INVALID_PARAMS, "author lookup failed");
const expectBlobSha =
typeof args.expect_blob_sha === "string" ? args.expect_blob_sha : null;
const res = await createOrUpdateFileOnBranch({
owner,
name: repo,
branch,
filePath,
bytes,
message,
authorName: author.username,
authorEmail: author.email || `${author.username}@users.noreply.gluecron`,
expectBlobSha,
});
if ("error" in res) {
if (res.error === "sha-mismatch") {
throw new McpError(ERR_INVALID_PARAMS, "sha does not match current blob at path");
}
throw new McpError(ERR_INVALID_PARAMS, `write failed: ${res.error}`);
}
return {
commitSha: res.commitSha,
blobSha: res.blobSha,
parentSha: res.parentSha,
branch,
path: filePath,
};
},
};
const deleteFile: McpToolHandler = {
tool: {
name: "gluecron_delete_file",
description:
"Delete a file from a branch via git plumbing. Requires the existing blob sha (optimistic concurrency) and 'repo' scope. Mirrors DELETE /api/v2/contents.",
annotations: { title: "Delete file", readOnlyHint: false, destructiveHint: true },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
path: { type: "string" },
branch: { type: "string" },
message: { type: "string" },
sha: { type: "string", description: "Current blob sha (40-hex)" },
},
required: ["owner", "repo", "path", "branch", "message", "sha"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const filePath = mcpArgString(args, "path");
const branch = mcpArgString(args, "branch");
const message = mcpArgString(args, "message");
const expectSha = mcpArgString(args, "sha");
if (!/^[0-9a-f]{40}$/.test(expectSha)) {
throw new McpError(ERR_INVALID_PARAMS, "sha must be a 40-char lowercase hex string");
}
requireScope(ctx, "repo", "gluecron_delete_file");
const gate = await mcpGateWriteAccess({ owner, repo }, ctx, "gluecron_delete_file");
const fullRef = `refs/heads/${branch}`;
const repoDir = getRepoPath(owner, repo);
const parentSha = await resolveRef(owner, repo, fullRef);
if (!parentSha) throw new McpError(ERR_METHOD_NOT_FOUND, "branch not found");
const existing = await getBlobShaAtPath(owner, repo, branch, filePath);
if (!existing) throw new McpError(ERR_METHOD_NOT_FOUND, "file not found");
if (existing !== expectSha) {
throw new McpError(ERR_INVALID_PARAMS, "sha does not match current blob at path");
}
const [author] = await db
.select({ username: users.username, email: users.email })
.from(users)
.where(eq(users.id, gate.userId))
.limit(1);
if (!author) throw new McpError(ERR_INVALID_PARAMS, "author lookup failed");
// Stand up a transient index + work-tree dir so git's safety checks pass.
const tmpIndex = join(
repoDir,
`index.tmp.${process.pid}.${Date.now()}.${crypto.randomUUID().replace(/-/g, "").slice(0, 8)}`
);
const tmpWorkTree = join(
repoDir,
`worktree.tmp.${process.pid}.${Date.now()}.${crypto.randomUUID().replace(/-/g, "").slice(0, 8)}`
);
await mkdir(tmpWorkTree, { recursive: true });
const env = {
...process.env,
GIT_INDEX_FILE: tmpIndex,
GIT_DIR: repoDir,
GIT_WORK_TREE: tmpWorkTree,
GIT_AUTHOR_NAME: author.username,
GIT_AUTHOR_EMAIL: author.email || `${author.username}@users.noreply.gluecron`,
GIT_COMMITTER_NAME: author.username,
GIT_COMMITTER_EMAIL: author.email || `${author.username}@users.noreply.gluecron`,
};
const cleanup = async () => {
try {
await unlink(tmpIndex).catch(() => {});
await rm(tmpWorkTree, { recursive: true, force: true }).catch(() => {});
} catch {
/* ignore */
}
};
const run = async (cmd: string[]): Promise<{ code: number; out: string }> => {
const proc = Bun.spawn(cmd, {
cwd: repoDir,
env,
stdout: "pipe",
stderr: "pipe",
});
const out = await new Response(proc.stdout).text();
const code = await proc.exited;
return { code, out };
};
try {
const rt = await run(["git", "read-tree", parentSha]);
if (rt.code !== 0) {
await cleanup();
throw new McpError(ERR_INVALID_PARAMS, "read-tree failed");
}
const ui = await run(["git", "update-index", "--remove", filePath]);
if (ui.code !== 0) {
await cleanup();
throw new McpError(ERR_INVALID_PARAMS, "update-index --remove failed");
}
const wt = await run(["git", "write-tree"]);
const newTree = wt.out.trim();
if (wt.code !== 0 || !/^[0-9a-f]{40}$/.test(newTree)) {
await cleanup();
throw new McpError(ERR_INVALID_PARAMS, "write-tree failed");
}
const ct = await run([
"git",
"commit-tree",
newTree,
"-p",
parentSha,
"-m",
message,
]);
const commitSha = ct.out.trim();
if (ct.code !== 0 || !/^[0-9a-f]{40}$/.test(commitSha)) {
await cleanup();
throw new McpError(ERR_INVALID_PARAMS, "commit-tree failed");
}
const ok = await updateRef(owner, repo, fullRef, commitSha, parentSha);
await cleanup();
if (!ok) throw new McpError(ERR_INVALID_PARAMS, "update-ref failed");
return { commitSha, branch, deletedPath: filePath };
} catch (err) {
await cleanup();
throw err;
}
},
};
const listTree: McpToolHandler = {
tool: {
name: "gluecron_list_tree",
description:
"List directory contents at a ref. Optionally `recursive: true` returns the full file list. Mirrors GET /api/v2/repos/.../tree/:ref.",
annotations: { title: "List tree", readOnlyHint: true, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
ref: { type: "string", description: "Branch / tag / sha" },
path: { type: "string", description: "Sub-path within the repo" },
recursive: { type: "boolean" },
},
required: ["owner", "repo", "ref"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const ref = mcpArgString(args, "ref");
const path = mcpArgString(args, "path", "");
const recursive = argBool(args, "recursive", false);
await mcpResolveAccessibleRepo(owner, repo, ctx.userId);
if (recursive) {
const out = await getTreeRecursive(owner, repo, ref, 50_000);
if (!out) throw new McpError(ERR_METHOD_NOT_FOUND, "ref not found");
return out;
}
const tree = await getTree(owner, repo, ref, path);
return { path, ref, entries: tree };
},
};
const getCommitTool: McpToolHandler = {
tool: {
name: "gluecron_get_commit",
description: "Fetch a single commit's metadata by SHA. Mirrors GET /api/v2/repos/.../commits/:sha.",
annotations: { title: "Get commit", readOnlyHint: true, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
sha: { type: "string", description: "Commit SHA" },
},
required: ["owner", "repo", "sha"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const sha = mcpArgString(args, "sha");
await mcpResolveAccessibleRepo(owner, repo, ctx.userId);
const commit = await getCommit(owner, repo, sha);
if (!commit) throw new McpError(ERR_METHOD_NOT_FOUND, `commit not found: ${sha}`);
return commit;
},
};
const createBranch: McpToolHandler = {
tool: {
name: "gluecron_create_branch",
description:
"Create a new branch ref pointing at an existing sha. Mirrors POST /api/v2/repos/.../git/refs. Requires 'repo' scope. Returns {ref, sha}.",
annotations: { title: "Create branch", readOnlyHint: false, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
branch: { type: "string", description: "New branch name (short form)" },
sha: { type: "string", description: "Target commit sha (40-hex)" },
},
required: ["owner", "repo", "branch", "sha"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const branchName = mcpArgString(args, "branch");
const sha = mcpArgString(args, "sha");
if (!/^[0-9a-f]{40}$/.test(sha)) {
throw new McpError(ERR_INVALID_PARAMS, "sha must be a 40-char lowercase hex string");
}
requireScope(ctx, "repo", "gluecron_create_branch");
await mcpGateWriteAccess({ owner, repo }, ctx, "gluecron_create_branch");
if (!(await objectExists(owner, repo, sha))) {
throw new McpError(ERR_INVALID_PARAMS, `sha not found in repository: ${sha}`);
}
const ref = `refs/heads/${branchName}`;
if (await refExists(owner, repo, ref)) {
const existing = await resolveRef(owner, repo, ref);
if (existing === sha) return { ref, sha, alreadyExists: true };
throw new McpError(ERR_INVALID_PARAMS, `ref already exists: ${ref}`);
}
const ok = await updateRef(owner, repo, ref, sha);
if (!ok) throw new McpError(ERR_INVALID_PARAMS, "update-ref failed");
return { ref, sha };
},
};
const atomicMultiFileCommit: McpToolHandler = {
tool: {
name: "gluecron_atomic_multi_file_commit",
description:
"Apply a set of file writes + deletes as a single atomic commit on a branch (creates the branch if it doesn't exist). The killer agent tool: blob/tree/commit/ref-update sequence. Each change is `{path, content?, content_base64?, deleted?}`. Requires 'repo' scope.",
// Commits (incl. deletes) preserve prior state in git history — not destructive.
annotations: { title: "Atomic multi-file commit", readOnlyHint: false, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
branch: { type: "string" },
base_branch: {
type: "string",
description: "Branch to fork from when `branch` doesn't yet exist (default: repo default).",
},
message: { type: "string" },
changes: {
type: "array",
description: "Array of {path, content?|content_base64?, deleted?} entries.",
},
},
required: ["owner", "repo", "branch", "message", "changes"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const branch = mcpArgString(args, "branch");
const message = mcpArgString(args, "message");
requireScope(ctx, "repo", "gluecron_atomic_multi_file_commit");
const gate = await mcpGateWriteAccess(
{ owner, repo },
ctx,
"gluecron_atomic_multi_file_commit"
);
const baseBranch = mcpArgString(args, "base_branch", gate.defaultBranch);
const rawChanges = Array.isArray(args.changes) ? args.changes : [];
if (rawChanges.length === 0) {
throw new McpError(ERR_INVALID_PARAMS, "changes must be a non-empty array");
}
type Change = {
path: string;
bytes?: Uint8Array;
deleted: boolean;
};
const changes: Change[] = [];
for (const entry of rawChanges) {
if (!entry || typeof entry !== "object") {
throw new McpError(ERR_INVALID_PARAMS, "each change must be an object");
}
const e = entry as Record<string, unknown>;
const path = typeof e.path === "string" ? e.path.trim() : "";
if (!path) {
throw new McpError(ERR_INVALID_PARAMS, "change.path is required");
}
const deleted = e.deleted === true;
let bytes: Uint8Array | undefined;
if (!deleted) {
if (typeof e.content === "string") {
bytes = new TextEncoder().encode(e.content);
} else if (typeof e.content_base64 === "string") {
try {
bytes = new Uint8Array(Buffer.from(e.content_base64, "base64"));
} catch {
throw new McpError(ERR_INVALID_PARAMS, `bad base64 for ${path}`);
}
} else {
throw new McpError(
ERR_INVALID_PARAMS,
`change.${path}: provide content, content_base64, or deleted:true`
);
}
}
changes.push({ path, bytes, deleted });
}
const repoDir = getRepoPath(owner, repo);
const fullRef = `refs/heads/${branch}`;
// Resolve parent — branch exists OR fall back to base_branch HEAD.
let parentSha: string | null = null;
if (await refExists(owner, repo, fullRef)) {
parentSha = await resolveRef(owner, repo, fullRef);
} else {
parentSha = await resolveRef(owner, repo, baseBranch);
if (!parentSha) {
throw new McpError(
ERR_INVALID_PARAMS,
`base_branch ${baseBranch} does not exist`
);
}
}
const [author] = await db
.select({ username: users.username, email: users.email })
.from(users)
.where(eq(users.id, gate.userId))
.limit(1);
if (!author) throw new McpError(ERR_INVALID_PARAMS, "author lookup failed");
const tmpIndex = join(
repoDir,
`index.tmp.${process.pid}.${Date.now()}.${crypto.randomUUID().replace(/-/g, "").slice(0, 8)}`
);
const tmpWorkTree = join(
repoDir,
`worktree.tmp.${process.pid}.${Date.now()}.${crypto.randomUUID().replace(/-/g, "").slice(0, 8)}`
);
await mkdir(tmpWorkTree, { recursive: true });
const env = {
...process.env,
GIT_INDEX_FILE: tmpIndex,
GIT_DIR: repoDir,
GIT_WORK_TREE: tmpWorkTree,
GIT_AUTHOR_NAME: author.username,
GIT_AUTHOR_EMAIL: author.email || `${author.username}@users.noreply.gluecron`,
GIT_COMMITTER_NAME: author.username,
GIT_COMMITTER_EMAIL: author.email || `${author.username}@users.noreply.gluecron`,
};
const cleanup = async () => {
await unlink(tmpIndex).catch(() => {});
await rm(tmpWorkTree, { recursive: true, force: true }).catch(() => {});
};
const run = async (cmd: string[]): Promise<{ code: number; out: string }> => {
const proc = Bun.spawn(cmd, { cwd: repoDir, env, stdout: "pipe", stderr: "pipe" });
const out = await new Response(proc.stdout).text();
const code = await proc.exited;
return { code, out };
};
try {
// 1. Seed the index from the parent tree.
if (parentSha) {
const rt = await run(["git", "read-tree", parentSha]);
if (rt.code !== 0) {
await cleanup();
throw new McpError(ERR_INVALID_PARAMS, "read-tree failed");
}
}
// 2. Apply each change.
for (const change of changes) {
if (change.deleted) {
const ui = await run(["git", "update-index", "--remove", change.path]);
if (ui.code !== 0) {
await cleanup();
throw new McpError(
ERR_INVALID_PARAMS,
`delete failed: ${change.path}`
);
}
} else {
const blobSha = await writeBlob(owner, repo, change.bytes!);
if (!blobSha) {
await cleanup();
throw new McpError(ERR_INVALID_PARAMS, `write-blob failed: ${change.path}`);
}
const ui = await run([
"git",
"update-index",
"--add",
"--cacheinfo",
`100644,${blobSha},${change.path}`,
]);
if (ui.code !== 0) {
await cleanup();
throw new McpError(ERR_INVALID_PARAMS, `update-index failed: ${change.path}`);
}
}
}
// 3. write-tree → commit-tree → update-ref.
const wt = await run(["git", "write-tree"]);
const newTree = wt.out.trim();
if (wt.code !== 0 || !/^[0-9a-f]{40}$/.test(newTree)) {
await cleanup();
throw new McpError(ERR_INVALID_PARAMS, "write-tree failed");
}
const ctArgs = parentSha
? ["git", "commit-tree", newTree, "-p", parentSha, "-m", message]
: ["git", "commit-tree", newTree, "-m", message];
const ct = await run(ctArgs);
const commitSha = ct.out.trim();
if (ct.code !== 0 || !/^[0-9a-f]{40}$/.test(commitSha)) {
await cleanup();
throw new McpError(ERR_INVALID_PARAMS, "commit-tree failed");
}
const ok = await updateRef(owner, repo, fullRef, commitSha, parentSha || undefined);
await cleanup();
if (!ok) throw new McpError(ERR_INVALID_PARAMS, "update-ref failed");
return {
commitSha,
branch,
parentSha,
files: changes.map((c) => ({ path: c.path, deleted: c.deleted })),
};
} catch (err) {
await cleanup();
throw err;
}
},
};
// ---------------------------------------------------------------------------
// AI WORKFLOWS
// ---------------------------------------------------------------------------
const shipSpec: McpToolHandler = {
tool: {
name: "gluecron_ship_spec",
description:
"Drop a spec file in .gluecron/specs/ with status: ready so the autopilot picks it up. Wraps voice-to-pr.shipAsSpec — handle both voice + manual specs. Requires 'repo' scope.",
annotations: { title: "Ship spec", readOnlyHint: false, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
title: { type: "string" },
body: { type: "string", description: "Spec body (Markdown)" },
},
required: ["owner", "repo", "title", "body"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const title = mcpArgString(args, "title");
const body = mcpArgString(args, "body");
requireScope(ctx, "repo", "gluecron_ship_spec");
const gate = await mcpGateWriteAccess({ owner, repo }, ctx, "gluecron_ship_spec");
const { shipAsSpec } = await import("./voice-to-pr");
// We use voice-to-pr's `shipAsSpec` even for non-voice specs — it
// builds the front-matter + commits via createOrUpdateFileOnBranch.
const transcript = `${title}\n\n${body}`;
const res = await shipAsSpec({
repositoryId: gate.repoId,
userId: gate.userId,
transcript,
interpretation: { kind: "spec", title, body_markdown: body },
});
if (!res.ok) {
throw new McpError(ERR_INVALID_PARAMS, res.error);
}
return res;
},
};
const voiceToPr: McpToolHandler = {
tool: {
name: "gluecron_voice_to_pr",
description:
"Interpret a free-form voice transcript and either ship it as a spec or create an issue (caller picks via `as`). Wraps src/lib/voice-to-pr.ts. Requires 'repo' scope.",
annotations: { title: "Voice to PR", readOnlyHint: false, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
transcript: { type: "string" },
as: {
type: "string",
description: "'spec' or 'issue' (default: auto via interpretVoiceTranscript)",
},
},
required: ["owner", "repo", "transcript"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const transcript = mcpArgString(args, "transcript");
const as = mcpArgString(args, "as", "auto");
requireScope(ctx, "repo", "gluecron_voice_to_pr");
const gate = await mcpGateWriteAccess({ owner, repo }, ctx, "gluecron_voice_to_pr");
const { interpretVoiceTranscript, shipAsSpec, createIssueFromVoice } =
await import("./voice-to-pr");
let intent: "spec" | "issue";
let interpretation;
if (as === "spec" || as === "issue") {
const interp = await interpretVoiceTranscript({ transcript });
interpretation = interp.ok ? interp.suggestion : undefined;
intent = as;
} else {
const interp = await interpretVoiceTranscript({ transcript });
if (!interp.ok) {
throw new McpError(ERR_INVALID_PARAMS, interp.error);
}
interpretation = interp.suggestion;
intent = interp.suggestion.kind === "issue" ? "issue" : "spec";
}
if (intent === "spec") {
const res = await shipAsSpec({
repositoryId: gate.repoId,
userId: gate.userId,
transcript,
interpretation,
});
if (!res.ok) throw new McpError(ERR_INVALID_PARAMS, res.error);
return { kind: "spec", ...res };
}
const res = await createIssueFromVoice({
repositoryId: gate.repoId,
userId: gate.userId,
transcript,
interpretation,
});
if (!res.ok) throw new McpError(ERR_INVALID_PARAMS, res.error);
return { kind: "issue", ...res };
},
};
const refactorAcrossRepos: McpToolHandler = {
tool: {
name: "gluecron_refactor_across_repos",
description:
"Plan + execute a refactor that spans multiple repos owned by the caller. Wraps src/lib/multi-repo-refactor.ts. `dry_run: true` returns the plan only. Requires 'repo' scope.",
// Creates branches/PRs across repos; prior state stays in git history — not destructive.
annotations: { title: "Refactor across repos", readOnlyHint: false, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
description: { type: "string", description: "Natural-language description" },
repository_ids: {
type: "array",
description: "Optional explicit repo IDs to scope the refactor to.",
},
dry_run: {
type: "boolean",
description: "When true, returns the plan and does NOT execute.",
},
},
required: ["description"],
},
},
async run(args, ctx) {
const description = mcpArgString(args, "description");
const userId = mcpRequireAuthedCtx(ctx, "gluecron_refactor_across_repos");
requireScope(ctx, "repo", "gluecron_refactor_across_repos");
const dryRun = argBool(args, "dry_run", false);
const ids = argStringArray(args, "repository_ids");
const { planRefactor, executeRefactor } = await import("./multi-repo-refactor");
const planRes = await planRefactor({
userId,
description,
repositoryIds: ids.length ? ids : undefined,
});
if (!planRes.ok) throw new McpError(ERR_INVALID_PARAMS, planRes.error);
if (dryRun) return { plan: planRes.plan, refactor: planRes.refactor, executed: false };
const exec = await executeRefactor({ refactorId: planRes.refactor.id });
if (!exec.ok) throw new McpError(ERR_INVALID_PARAMS, exec.error);
return {
plan: planRes.plan,
refactor: exec.refactor,
children: exec.children,
executed: true,
};
},
};
const explainRepo: McpToolHandler = {
tool: {
name: "gluecron_explain_repo",
description:
"Return the cached AI 'explain this codebase' Markdown for a repo. Pure read — never triggers a new generation (use the web UI for that).",
annotations: { title: "Explain repository (cached)", readOnlyHint: true, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
},
required: ["owner", "repo"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
await mcpResolveAccessibleRepo(owner, repo, ctx.userId);
const { codebaseExplanations } = await import("../db/schema");
const [row] = await db
.select()
.from(codebaseExplanations)
.where(
eq(
codebaseExplanations.repositoryId,
(await mcpResolveAccessibleRepo(owner, repo, ctx.userId)).repoId
)
)
.orderBy(desc(codebaseExplanations.generatedAt))
.limit(1);
if (!row) return { explanation: null };
return {
commitSha: row.commitSha,
generatedAt: row.generatedAt,
markdown: row.markdown,
};
},
};
const chatWithRepo: McpToolHandler = {
tool: {
name: "gluecron_chat_with_repo",
description:
"Start a new chat with a repo: creates a chat row, sends the first user message, streams + persists the assistant reply. Returns {chat_id, reply}. Requires authentication.",
// Persists chat rows — a write, though a benign one.
annotations: { title: "Chat with repository", readOnlyHint: false, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
message: { type: "string", description: "Initial user message" },
title: { type: "string", description: "Chat title (optional)" },
},
required: ["owner", "repo", "message"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const userMessage = mcpArgString(args, "message");
const title = mcpArgString(args, "title", "");
const userId = mcpRequireAuthedCtx(ctx, "gluecron_chat_with_repo");
const info = await mcpResolveAccessibleRepo(owner, repo, userId);
const { createChat, appendUserMessage, streamAssistantReply } = await import(
"./repo-chat"
);
const chat = await createChat({
repositoryId: info.repoId,
ownerUserId: userId,
title: title || userMessage.slice(0, 80),
});
if (!chat) throw new McpError(ERR_INVALID_PARAMS, "chat creation failed");
await appendUserMessage(chat.id, userMessage);
const reply = await streamAssistantReply({
chatId: chat.id,
repoId: info.repoId,
userMessage,
});
return {
chat_id: chat.id,
reply: reply ? { id: reply.id, content: reply.content, citations: reply.citations } : null,
};
},
};
const chatContinue: McpToolHandler = {
tool: {
name: "gluecron_chat_continue",
description:
"Send another message to an existing repo chat. Returns the assistant's reply.",
annotations: { title: "Continue repository chat", readOnlyHint: false, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
chat_id: { type: "string" },
message: { type: "string" },
},
required: ["chat_id", "message"],
},
},
async run(args, ctx) {
const chatId = mcpArgString(args, "chat_id");
const userMessage = mcpArgString(args, "message");
const userId = mcpRequireAuthedCtx(ctx, "gluecron_chat_continue");
const { getChatForUser, appendUserMessage, streamAssistantReply } = await import(
"./repo-chat"
);
const chat = await getChatForUser(chatId, userId);
if (!chat) throw new McpError(ERR_METHOD_NOT_FOUND, "chat not found");
await appendUserMessage(chatId, userMessage);
const reply = await streamAssistantReply({
chatId,
repoId: chat.repositoryId,
userMessage,
});
return {
chat_id: chatId,
reply: reply ? { id: reply.id, content: reply.content, citations: reply.citations } : null,
};
},
};
const generateTests: McpToolHandler = {
tool: {
name: "gluecron_generate_tests",
description:
"Generate tests for a PR via Claude. Wraps src/lib/ai-test-generator.generateTestsForPr. Mode 'follow-up-pr' opens a new PR; 'append-commit' commits onto the head branch. Requires 'repo' scope.",
annotations: { title: "Generate tests for PR", readOnlyHint: false, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
number: { type: "number", description: "PR number" },
mode: { type: "string", description: "'follow-up-pr' or 'append-commit'" },
},
required: ["owner", "repo", "number"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const number = mcpArgNumber(args, "number");
const mode = mcpArgString(args, "mode", "follow-up-pr");
if (mode !== "follow-up-pr" && mode !== "append-commit") {
throw new McpError(ERR_INVALID_PARAMS, "mode must be follow-up-pr|append-commit");
}
requireScope(ctx, "repo", "gluecron_generate_tests");
const gate = await mcpGateWriteAccess({ owner, repo }, ctx, "gluecron_generate_tests");
const pr = await mcpLoadPrByNumber(gate.repoId, number);
if (!pr) throw new McpError(ERR_METHOD_NOT_FOUND, "pr not found");
const { generateTestsForPr } = await import("./ai-test-generator");
const res = await generateTestsForPr({ prId: pr.id, mode });
if (!res.ok) throw new McpError(ERR_INVALID_PARAMS, res.error || "test generation failed");
return res;
},
};
const generateCommitMessageTool: McpToolHandler = {
tool: {
name: "gluecron_generate_commit_message",
description:
"Generate a commit message for a diff. Same engine as gluecron_generate_pr_description but explicit for the commit-message use case.",
annotations: { title: "Generate commit message", readOnlyHint: true, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
diff: { type: "string" },
style: { type: "string", description: "'conventional' (default) or 'plain'" },
},
required: ["diff"],
},
},
async run(args) {
const diff = mcpArgString(args, "diff");
const style = mcpArgString(args, "style", "conventional");
const { generateCommitMessage } = await import("./ai-commit-message");
return await generateCommitMessage(diff, {
style: style === "plain" ? "plain" : "conventional",
});
},
};
const generateReleaseNotes: McpToolHandler = {
tool: {
name: "gluecron_generate_release_notes",
description:
"Generate release notes between two tags. Wraps src/lib/ai-release-notes.generateReleaseNotes. Returns the rendered Markdown + section data.",
// generateReleaseNotes only computes + returns; persistence lives in the separate backfill task.
annotations: { title: "Generate release notes", readOnlyHint: true, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
from_tag: { type: "string", description: "Previous tag (optional)" },
to_tag: { type: "string", description: "New tag" },
},
required: ["owner", "repo", "to_tag"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const toTag = mcpArgString(args, "to_tag");
const fromTag = mcpArgString(args, "from_tag", "");
const info = await mcpResolveAccessibleRepo(owner, repo, ctx.userId);
const { generateReleaseNotes: gen } = await import("./ai-release-notes");
return await gen({
repositoryId: info.repoId,
fromTag: fromTag || null,
toTag,
});
},
};
const proposeMigration: McpToolHandler = {
tool: {
name: "gluecron_propose_migration",
description:
"Propose a dependency-upgrade PR. Wraps src/lib/migration-assistant.proposeMajorMigration. Requires 'repo' scope.",
annotations: { title: "Propose migration PR", readOnlyHint: false, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
dependency: { type: "string" },
from_version: { type: "string" },
to_version: { type: "string" },
base_sha: { type: "string", description: "Commit sha to fork from" },
changelog: { type: "string", description: "Optional changelog text" },
},
required: ["owner", "repo", "dependency", "from_version", "to_version", "base_sha"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const dependency = mcpArgString(args, "dependency");
const fromVersion = mcpArgString(args, "from_version");
const toVersion = mcpArgString(args, "to_version");
const baseSha = mcpArgString(args, "base_sha");
const changelog = mcpArgString(args, "changelog", "");
requireScope(ctx, "repo", "gluecron_propose_migration");
const gate = await mcpGateWriteAccess({ owner, repo }, ctx, "gluecron_propose_migration");
const { proposeMajorMigration } = await import("./migration-assistant");
const res = await proposeMajorMigration({
repositoryId: gate.repoId,
dependency,
fromVersion,
toVersion,
baseSha,
changelog: changelog || null,
});
if (!res) {
throw new McpError(
ERR_INVALID_PARAMS,
"migration proposal returned null (no manifest, throttle, or AI failure)"
);
}
return res;
},
};
const proposeDocUpdate: McpToolHandler = {
tool: {
name: "gluecron_propose_doc_update",
description:
"Manual trigger for the AI doc-update flow: scans tracked sections on the default branch and opens a PR rewriting stale prose. Requires 'repo' scope.",
annotations: { title: "Propose doc update PR", readOnlyHint: false, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
},
required: ["owner", "repo"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
requireScope(ctx, "repo", "gluecron_propose_doc_update");
const gate = await mcpGateWriteAccess({ owner, repo }, ctx, "gluecron_propose_doc_update");
const { runDocDriftCheckForRepo } = await import("./ai-doc-updater");
const res = await runDocDriftCheckForRepo(gate.repoId);
return res ?? { proposed: 0, note: "no drift detected or AI unavailable" };
},
};
// ---------------------------------------------------------------------------
// CI / DEPLOYS
// ---------------------------------------------------------------------------
const triggerWorkflow: McpToolHandler = {
tool: {
name: "gluecron_trigger_workflow",
description:
"Dispatch a workflow_dispatch run. Mirrors POST /api/v2/repos/.../actions/workflows/:filename/dispatches. Requires 'repo' scope.",
annotations: { title: "Trigger workflow", readOnlyHint: false, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
filename: { type: "string", description: "Workflow filename (e.g. ci.yml)" },
ref: { type: "string", description: "Branch / tag / sha (default: repo default branch)" },
inputs: { type: "object", description: "Workflow inputs (object)" },
},
required: ["owner", "repo", "filename"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const filename = mcpArgString(args, "filename");
requireScope(ctx, "repo", "gluecron_trigger_workflow");
const gate = await mcpGateWriteAccess({ owner, repo }, ctx, "gluecron_trigger_workflow");
// Match the api-v2 helper: stored workflow path is
// `.gluecron/workflows/<filename>`; we match by trailing basename.
const candidates = await db
.select()
.from(workflows)
.where(eq(workflows.repositoryId, gate.repoId));
const wfRow = candidates.find((row) => {
const idx = row.path.lastIndexOf("/");
const base = idx >= 0 ? row.path.slice(idx + 1) : row.path;
return base === filename;
});
if (!wfRow) throw new McpError(ERR_METHOD_NOT_FOUND, `workflow not found: ${filename}`);
let parsedObj: Record<string, unknown> = {};
try {
const v = JSON.parse(wfRow.parsed);
if (v && typeof v === "object" && !Array.isArray(v)) {
parsedObj = v as Record<string, unknown>;
}
} catch {
/* */
}
// Inline-copy of the dispatch-spec extractor in src/routes/api-v2.ts
// (private to that module). Same shape, same semantics — keeping the
// logic local avoids an export-shuffle in the api-v2 module.
const rawOn = parsedObj.on as
| string
| string[]
| Record<string, unknown>
| null
| undefined;
type DispatchInputSpec = { required?: boolean; default?: unknown };
let dispatchEnabled = false;
let dispatchInputs: Record<string, DispatchInputSpec> | null = null;
if (typeof rawOn === "string") {
dispatchEnabled = rawOn === "workflow_dispatch";
} else if (Array.isArray(rawOn)) {
dispatchEnabled = rawOn.includes("workflow_dispatch");
} else if (rawOn && typeof rawOn === "object") {
const slot = (rawOn as Record<string, unknown>)["workflow_dispatch"];
if (slot !== undefined) {
dispatchEnabled = true;
if (slot && typeof slot === "object") {
const inputs = (slot as Record<string, unknown>).inputs;
if (inputs && typeof inputs === "object" && !Array.isArray(inputs)) {
dispatchInputs = inputs as Record<string, DispatchInputSpec>;
}
}
}
}
if (!dispatchEnabled) {
throw new McpError(ERR_INVALID_PARAMS, "workflow has no workflow_dispatch trigger");
}
const providedInputs =
args.inputs && typeof args.inputs === "object" && !Array.isArray(args.inputs)
? (args.inputs as Record<string, unknown>)
: undefined;
if (dispatchInputs) {
const missing: string[] = [];
for (const [n, spec] of Object.entries(dispatchInputs)) {
if (!spec || typeof spec !== "object") continue;
const typed = spec as DispatchInputSpec;
const has =
!!providedInputs &&
Object.prototype.hasOwnProperty.call(providedInputs, n) &&
providedInputs[n] !== undefined &&
providedInputs[n] !== null;
if (typed.required && !has && typed.default === undefined) {
missing.push(n);
}
}
if (missing.length) {
throw new McpError(
ERR_INVALID_PARAMS,
`missing required workflow inputs: ${missing.join(",")}`
);
}
}
const refIn = mcpArgString(args, "ref", gate.defaultBranch);
const commitSha = await resolveRef(owner, repo, refIn);
if (!commitSha) {
throw new McpError(ERR_INVALID_PARAMS, `ref not found: ${refIn}`);
}
const { enqueueRun } = await import("./workflow-runner");
const runId = await enqueueRun({
workflowId: wfRow.id,
repositoryId: gate.repoId,
event: "workflow_dispatch",
ref: refIn,
commitSha,
triggeredBy: gate.userId,
});
if (!runId) throw new McpError(ERR_INVALID_PARAMS, "enqueueRun failed");
return { runId, workflowName: wfRow.name, ref: refIn, commitSha };
},
};
const getWorkflowRun: McpToolHandler = {
tool: {
name: "gluecron_get_workflow_run",
description: "Fetch a workflow run's metadata + status. Mirrors GET /api/v2/repos/.../actions/runs/:id.",
annotations: { title: "Get workflow run", readOnlyHint: true, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
run_id: { type: "string" },
},
required: ["owner", "repo", "run_id"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const runId = mcpArgString(args, "run_id");
const info = await mcpResolveAccessibleRepo(owner, repo, ctx.userId);
const [run] = await db
.select()
.from(workflowRuns)
.where(eq(workflowRuns.id, runId))
.limit(1);
if (!run || run.repositoryId !== info.repoId) {
throw new McpError(ERR_METHOD_NOT_FOUND, "run not found");
}
return run;
},
};
const getWorkflowLogs: McpToolHandler = {
tool: {
name: "gluecron_get_workflow_logs",
description:
"Return concatenated per-job logs for a workflow run, plus per-job metadata. JSON-friendly companion to the ZIP-download endpoint.",
annotations: { title: "Get workflow logs", readOnlyHint: true, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
run_id: { type: "string" },
},
required: ["owner", "repo", "run_id"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const runId = mcpArgString(args, "run_id");
const info = await mcpResolveAccessibleRepo(owner, repo, ctx.userId);
const [run] = await db
.select()
.from(workflowRuns)
.where(eq(workflowRuns.id, runId))
.limit(1);
if (!run || run.repositoryId !== info.repoId) {
throw new McpError(ERR_METHOD_NOT_FOUND, "run not found");
}
const jobs = await db
.select()
.from(workflowJobs)
.where(eq(workflowJobs.runId, run.id))
.orderBy(asc(workflowJobs.jobOrder));
return {
runId: run.id,
status: run.status,
conclusion: run.conclusion,
jobs: jobs.map((j) => ({
id: j.id,
name: j.name,
status: j.status,
conclusion: j.conclusion,
logs: j.logs || "",
})),
};
},
};
const cancelWorkflowRun: McpToolHandler = {
tool: {
name: "gluecron_cancel_workflow_run",
description: "Cancel a queued/running workflow run. Requires 'repo' scope.",
// Cancellation kills in-flight work that cannot be resumed — destructive.
annotations: { title: "Cancel workflow run", readOnlyHint: false, destructiveHint: true },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
run_id: { type: "string" },
},
required: ["owner", "repo", "run_id"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const runId = mcpArgString(args, "run_id");
requireScope(ctx, "repo", "gluecron_cancel_workflow_run");
const gate = await mcpGateWriteAccess({ owner, repo }, ctx, "gluecron_cancel_workflow_run");
const [run] = await db
.select()
.from(workflowRuns)
.where(eq(workflowRuns.id, runId))
.limit(1);
if (!run || run.repositoryId !== gate.repoId) {
throw new McpError(ERR_METHOD_NOT_FOUND, "run not found");
}
if (run.status !== "queued" && run.status !== "running") {
return { cancelled: false, reason: `run is ${run.status}` };
}
const now = new Date();
await db
.update(workflowRuns)
.set({ status: "cancelled", conclusion: "cancelled", finishedAt: now })
.where(eq(workflowRuns.id, run.id));
await db
.update(workflowJobs)
.set({ status: "cancelled", conclusion: "cancelled", finishedAt: now })
.where(eq(workflowJobs.runId, run.id));
return { cancelled: true };
},
};
const getPreviewUrl: McpToolHandler = {
tool: {
name: "gluecron_get_preview_url",
description:
"Return the branch-preview URL + status for a (repo, branch) pair. Wraps branch-previews.getPreviewForBranch.",
annotations: { title: "Get preview URL", readOnlyHint: true, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
branch: { type: "string" },
},
required: ["owner", "repo", "branch"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const branch = mcpArgString(args, "branch");
const info = await mcpResolveAccessibleRepo(owner, repo, ctx.userId);
const { getPreviewForBranch, previewStatusLabel, formatExpiresIn, buildPreviewUrl } =
await import("./branch-previews");
const row = await getPreviewForBranch(info.repoId, branch);
if (!row) {
return {
exists: false,
url: buildPreviewUrl(owner, repo, branch),
status: "missing",
};
}
return {
exists: true,
url: row.previewUrl,
status: row.status,
statusLabel: previewStatusLabel(row.status),
expiresAt: row.expiresAt,
expiresIn: formatExpiresIn(row.expiresAt),
};
},
};
const provisionPrSandbox: McpToolHandler = {
tool: {
name: "gluecron_provision_pr_sandbox",
description:
"Provision (or re-provision) a sandbox for a PR. Wraps pr-sandbox.provisionSandbox. Requires 'repo' scope.",
// Re-provision replaces an ephemeral sandbox only — not destructive.
annotations: { title: "Provision PR sandbox", readOnlyHint: false, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
number: { type: "number" },
},
required: ["owner", "repo", "number"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const number = mcpArgNumber(args, "number");
requireScope(ctx, "repo", "gluecron_provision_pr_sandbox");
const gate = await mcpGateWriteAccess({ owner, repo }, ctx, "gluecron_provision_pr_sandbox");
const pr = await mcpLoadPrByNumber(gate.repoId, number);
if (!pr) throw new McpError(ERR_METHOD_NOT_FOUND, "pr not found");
const { provisionSandbox } = await import("./pr-sandbox");
const row = await provisionSandbox({ prId: pr.id });
if (!row) throw new McpError(ERR_INVALID_PARAMS, "provision failed");
return row;
},
};
// ---------------------------------------------------------------------------
// AGENTS
// ---------------------------------------------------------------------------
const createAgentSession: McpToolHandler = {
tool: {
name: "gluecron_create_agent_session",
description:
"Mint a new agent-multiplayer session. Returns the plaintext `token` exactly once (store it). Requires 'admin' scope.",
annotations: { title: "Create agent session", readOnlyHint: false, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
name: { type: "string", description: "Human-readable session name (unique per owner)" },
repository_id: { type: "string", description: "Optional repo to scope to" },
branch_namespace: { type: "string", description: "Optional branch namespace override" },
budget_cents_per_day: { type: "number", description: "Daily budget cap in cents (default 500)" },
},
required: ["name"],
},
},
async run(args, ctx) {
const userId = mcpRequireAuthedCtx(ctx, "gluecron_create_agent_session");
requireScope(ctx, "admin", "gluecron_create_agent_session");
const name = mcpArgString(args, "name");
const { createAgentSession } = await import("./agent-multiplayer");
const res = await createAgentSession({
ownerUserId: userId,
name,
repositoryId:
typeof args.repository_id === "string" ? args.repository_id : null,
branchNamespace:
typeof args.branch_namespace === "string" ? args.branch_namespace : undefined,
budgetCentsPerDay:
typeof args.budget_cents_per_day === "number"
? args.budget_cents_per_day
: undefined,
});
if (!res) throw new McpError(ERR_INVALID_PARAMS, "session creation failed");
return {
session: { id: res.session.id, name: res.session.name },
token: res.token,
warning: "Token is shown exactly once — store it now.",
};
},
};
const acquireLease: McpToolHandler = {
tool: {
name: "gluecron_acquire_lease",
description:
"Grab an exclusive lease on a target (e.g. a PR or branch) for an agent session. Returns null when another agent holds an active lease.",
annotations: { title: "Acquire lease", readOnlyHint: false, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
agent_session_id: { type: "string" },
target_type: { type: "string", description: "e.g. 'pull_request', 'branch'" },
target_id: { type: "string" },
duration_ms: { type: "number", description: "Lease duration (default 5 minutes)" },
},
required: ["agent_session_id", "target_type", "target_id"],
},
},
async run(args, ctx) {
mcpRequireAuthedCtx(ctx, "gluecron_acquire_lease");
requireScope(ctx, "repo", "gluecron_acquire_lease");
const sessionId = mcpArgString(args, "agent_session_id");
const targetType = mcpArgString(args, "target_type");
const targetId = mcpArgString(args, "target_id");
const durationMs =
typeof args.duration_ms === "number" ? args.duration_ms : undefined;
const { acquireLease } = await import("./agent-multiplayer");
const lease = await acquireLease(sessionId, targetType, targetId, durationMs);
return { lease };
},
};
const releaseLeaseTool: McpToolHandler = {
tool: {
name: "gluecron_release_lease",
description: "Release a lease by id. Idempotent. Returns {released}.",
annotations: { title: "Release lease", readOnlyHint: false, destructiveHint: false, idempotentHint: true },
inputSchema: {
type: "object",
properties: { lease_id: { type: "string" } },
required: ["lease_id"],
},
},
async run(args, ctx) {
mcpRequireAuthedCtx(ctx, "gluecron_release_lease");
requireScope(ctx, "repo", "gluecron_release_lease");
const leaseId = mcpArgString(args, "lease_id");
const { releaseLease } = await import("./agent-multiplayer");
return { released: await releaseLease(leaseId) };
},
};
const getAgentBudget: McpToolHandler = {
tool: {
name: "gluecron_get_agent_budget",
description: "Return spent / cap / remaining cents for an agent session.",
annotations: { title: "Get agent budget", readOnlyHint: true, destructiveHint: false },
inputSchema: {
type: "object",
properties: { agent_session_id: { type: "string" } },
required: ["agent_session_id"],
},
},
async run(args, ctx) {
mcpRequireAuthedCtx(ctx, "gluecron_get_agent_budget");
const sessionId = mcpArgString(args, "agent_session_id");
const { getAgentUsage } = await import("./agent-multiplayer");
return await getAgentUsage(sessionId);
},
};
// ---------------------------------------------------------------------------
// SEMANTIC
// ---------------------------------------------------------------------------
const semanticSearch: McpToolHandler = {
tool: {
name: "gluecron_semantic_search",
description:
"Query the per-repo vector index (Voyage embeddings when configured, hash fallback otherwise). Wraps src/lib/semantic-search.searchRepository.",
annotations: { title: "Semantic search", readOnlyHint: true, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
query: { type: "string" },
limit: { type: "number" },
},
required: ["owner", "repo", "query"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const query = mcpArgString(args, "query");
const limit = mcpArgNumber(args, "limit", 20);
const info = await mcpResolveAccessibleRepo(owner, repo, ctx.userId);
const { searchRepository } = await import("./semantic-search");
const hits = await searchRepository({
repositoryId: info.repoId,
query,
limit,
});
return { hits };
},
};
const findSymbol: McpToolHandler = {
tool: {
name: "gluecron_find_symbol",
description:
"Find definitions of a symbol by name within a repo. Wraps src/lib/symbols.findDefinitions.",
annotations: { title: "Find symbol", readOnlyHint: true, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
name: { type: "string", description: "Symbol name" },
},
required: ["owner", "repo", "name"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const name = mcpArgString(args, "name");
const info = await mcpResolveAccessibleRepo(owner, repo, ctx.userId);
const { findDefinitions } = await import("./symbols");
const defs = await findDefinitions(info.repoId, name);
return { definitions: defs };
},
};
// ---------------------------------------------------------------------------
// INSIGHTS
// ---------------------------------------------------------------------------
const prStatusSummary: McpToolHandler = {
tool: {
name: "gluecron_pr_status_summary",
description:
"Compute a one-shot status summary for a PR: state, risk score, AI-review verdicts (trio), gate signals. Read-only.",
annotations: { title: "PR status summary", readOnlyHint: true, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
owner: { type: "string" },
repo: { type: "string" },
number: { type: "number" },
},
required: ["owner", "repo", "number"],
},
},
async run(args, ctx) {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const number = mcpArgNumber(args, "number");
const info = await mcpResolveAccessibleRepo(owner, repo, ctx.userId);
const pr = await mcpLoadPrByNumber(info.repoId, number);
if (!pr) throw new McpError(ERR_METHOD_NOT_FOUND, "pr not found");
const { getLatestCachedPrRisk } = await import("./pr-risk");
const risk = await getLatestCachedPrRisk(pr.id);
const aiComments = await db
.select({ body: prComments.body, isAiReview: prComments.isAiReview })
.from(prComments)
.where(and(eq(prComments.pullRequestId, pr.id), eq(prComments.isAiReview, true)));
const { TRIO_SUMMARY_MARKER } = await import("./ai-review-trio");
const trioSummary = aiComments.find((c) => c.body.includes(TRIO_SUMMARY_MARKER));
return {
number: pr.number,
title: pr.title,
state: pr.state,
isDraft: pr.isDraft,
baseBranch: pr.baseBranch,
headBranch: pr.headBranch,
risk: risk
? { score: risk.score, band: risk.band, summary: risk.aiSummary }
: null,
aiReviewCount: aiComments.length,
trioSummary: trioSummary ? trioSummary.body : null,
url: mcpPrUrl(owner, repo, pr.number),
};
},
};
const aiCostSummary: McpToolHandler = {
tool: {
name: "gluecron_ai_cost_summary",
description:
"Return AI spend rollups. Scope by one of: user_id (self), repo {owner,repo}, or agent_session_id. Defaults to caller's user spend.",
annotations: { title: "AI cost summary", readOnlyHint: true, destructiveHint: false },
inputSchema: {
type: "object",
properties: {
scope: { type: "string", description: "'user' (default) | 'repo' | 'agent'" },
owner: { type: "string" },
repo: { type: "string" },
agent_session_id: { type: "string" },
},
},
},
async run(args, ctx) {
const scope = mcpArgString(args, "scope", "user");
const userId = mcpRequireAuthedCtx(ctx, "gluecron_ai_cost_summary");
const {
summarizeCostsForUser,
summarizeCostsForRepo,
summarizeCostsForAgent,
} = await import("./ai-cost-tracker");
if (scope === "repo") {
const owner = mcpArgString(args, "owner");
const repo = mcpArgString(args, "repo");
const info = await mcpResolveAccessibleRepo(owner, repo, userId);
return await summarizeCostsForRepo(info.repoId);
}
if (scope === "agent") {
const sessionId = mcpArgString(args, "agent_session_id");
return await summarizeCostsForAgent(sessionId);
}
return await summarizeCostsForUser(userId);
},
};
// ---------------------------------------------------------------------------
// Registry
// ---------------------------------------------------------------------------
/**
* Every expanded tool keyed by name. Merged into `defaultTools()` in
* `mcp-tools.ts` so the MCP HTTP route advertises all of them.
*/
export function expandedTools(): Record<string, McpToolHandler> {
return {
[forkRepo.tool.name]: forkRepo,
[deleteRepo.tool.name]: deleteRepo,
[updateRepo.tool.name]: updateRepo,
[searchRepos.tool.name]: searchRepos,
[cloneUrl.tool.name]: cloneUrl,
[labelIssue.tool.name]: labelIssue,
[unlabelIssue.tool.name]: unlabelIssue,
[assignIssue.tool.name]: assignIssue,
[searchIssues.tool.name]: searchIssues,
[requestChanges.tool.name]: requestChanges,
[searchPrs.tool.name]: searchPrs,
[openDraftPr.tool.name]: openDraftPr,
[generatePrDescription.tool.name]: generatePrDescription,
[readFile.tool.name]: readFile,
[writeFile.tool.name]: writeFile,
[deleteFile.tool.name]: deleteFile,
[listTree.tool.name]: listTree,
[getCommitTool.tool.name]: getCommitTool,
[createBranch.tool.name]: createBranch,
[atomicMultiFileCommit.tool.name]: atomicMultiFileCommit,
[shipSpec.tool.name]: shipSpec,
[voiceToPr.tool.name]: voiceToPr,
[refactorAcrossRepos.tool.name]: refactorAcrossRepos,
[explainRepo.tool.name]: explainRepo,
[chatWithRepo.tool.name]: chatWithRepo,
[chatContinue.tool.name]: chatContinue,
[generateTests.tool.name]: generateTests,
[generateCommitMessageTool.tool.name]: generateCommitMessageTool,
[generateReleaseNotes.tool.name]: generateReleaseNotes,
[proposeMigration.tool.name]: proposeMigration,
[proposeDocUpdate.tool.name]: proposeDocUpdate,
[triggerWorkflow.tool.name]: triggerWorkflow,
[getWorkflowRun.tool.name]: getWorkflowRun,
[getWorkflowLogs.tool.name]: getWorkflowLogs,
[cancelWorkflowRun.tool.name]: cancelWorkflowRun,
[getPreviewUrl.tool.name]: getPreviewUrl,
[provisionPrSandbox.tool.name]: provisionPrSandbox,
[createAgentSession.tool.name]: createAgentSession,
[acquireLease.tool.name]: acquireLease,
[releaseLeaseTool.tool.name]: releaseLeaseTool,
[getAgentBudget.tool.name]: getAgentBudget,
[semanticSearch.tool.name]: semanticSearch,
[findSymbol.tool.name]: findSymbol,
[prStatusSummary.tool.name]: prStatusSummary,
[aiCostSummary.tool.name]: aiCostSummary,
};
}
/** Test-only export of the per-tool handlers. */
export const __expandedTest = {
forkRepo,
deleteRepo,
updateRepo,
searchRepos,
cloneUrl,
labelIssue,
unlabelIssue,
assignIssue,
searchIssues,
requestChanges,
searchPrs,
openDraftPr,
generatePrDescription,
readFile,
writeFile,
deleteFile,
listTree,
getCommitTool,
createBranch,
atomicMultiFileCommit,
shipSpec,
voiceToPr,
refactorAcrossRepos,
explainRepo,
chatWithRepo,
chatContinue,
generateTests,
generateCommitMessageTool,
generateReleaseNotes,
proposeMigration,
proposeDocUpdate,
triggerWorkflow,
getWorkflowRun,
getWorkflowLogs,
cancelWorkflowRun,
getPreviewUrl,
provisionPrSandbox,
createAgentSession,
acquireLease,
releaseLeaseTool,
getAgentBudget,
semanticSearch,
findSymbol,
prStatusSummary,
aiCostSummary,
requireScope,
};
|