vissue-mcp 0.9.3

Model Context Protocol server exposing vissue issue tracking to agents
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
//! The MCP tool surface, calling vissue-core in process.

use rmcp::{
    ErrorData as McpError, handler::server::ServerHandler, handler::server::wrapper::Json,
    handler::server::wrapper::Parameters, model::*, tool, tool_handler, tool_router,
};

use vissue_core::config::Layout;
use vissue_core::error::Error;
use vissue_core::mirror::{self, Format};
use vissue_core::ops::{self, CreateOpts, RejectOpts, UpdatePred};
use vissue_core::router::Router;
use vissue_core::views::{IssueDetail, IssueRow};
use vissue_core::{agent, events, report};

/// A structured answer, or the error as the protocol carries one.
///
/// Four tools return data rather than prose, and a client that has to parse a
/// pretty-printed string back into the object it already was is doing work the
/// protocol has a field for. `Json` fills `structuredContent` and leaves the
/// serialized text beside it, so a caller that reads either still works.
fn structured<T, E: std::fmt::Display>(result: Result<T, E>) -> Result<Json<T>, McpError> {
    result
        .map(Json)
        .map_err(|e| McpError::internal_error(format!("{e}"), None))
}

use crate::tools::*;
use std::path::PathBuf;

/// The tool router is built by `#[tool_handler]` through `Self::tool_router()`,
/// so the server carries the default layout and the user-level project router.
#[derive(Clone)]
pub struct VissueServer {
    layout: Layout,
    router: Router,
}

/// Where a `reject` should put its successor.
struct RejectDest {
    layout: Layout,
    project: Option<String>,
    extra_id_paths: Vec<PathBuf>,
}

fn text<E: std::fmt::Display>(result: Result<String, E>) -> Result<CallToolResult, McpError> {
    match result {
        Ok(s) => Ok(CallToolResult::success(vec![ContentBlock::text(s)])),
        Err(e) => Err(McpError::internal_error(format!("{e}"), None)),
    }
}

#[tool_router]
impl VissueServer {
    /// Resolve the layout from `VISSUE_ROOT` and `VISSUE_PREFIX`, or the
    /// current directory, then load the user-level route table.
    pub fn from_env() -> anyhow::Result<Self> {
        let layout = Layout::resolve(None, None)?;
        let router = Router::load(layout.clone())?;
        Ok(Self { layout, router })
    }

    #[cfg(test)]
    pub fn with_layout(layout: Layout) -> Self {
        Self {
            router: Router::unrouted(layout.clone()),
            layout,
        }
    }

    fn layout_for_id(&self, id: &str) -> vissue_core::Result<Layout> {
        Ok(self.router.find_by_id(id)?.layout)
    }

    /// A known id routes to its own layout. An accession names a product
    /// rather than a heading, so it has no layout of its own and every tracker
    /// in reach can cite it.
    ///
    /// Only "no such heading" falls through to the accession walk. A duplicate
    /// id or an unreadable file is a fault in the corpus, and answering it with
    /// a citation list would report that fault as an empty result.
    fn backlinks_text(&self, id: &str) -> vissue_core::Result<String> {
        match self.layout_for_id(id) {
            Ok(layout) => report::backlinks(&layout, id),
            Err(Error::IssueNotFound { .. }) if ops::is_deed_accession(id) => {
                let mut out = String::new();
                for layout in self.router.unique_layouts() {
                    out.push_str(&report::backlinks(layout, id)?);
                }
                Ok(out)
            }
            Err(err) => Err(err),
        }
    }

    /// `to` names an existing heading, so its own layout wins. Otherwise the
    /// create project is routed, which keeps a bounce onto a routed name off
    /// the server's own root.
    fn reject_destination(
        &self,
        src: &Layout,
        to: Option<&str>,
        project: Option<&str>,
    ) -> vissue_core::Result<RejectDest> {
        if let Some(to) = to {
            return Ok(RejectDest {
                layout: self.layout_for_id(to)?,
                project: project.map(str::to_string),
                extra_id_paths: Vec::new(),
            });
        }
        let Some(project) = project else {
            return Ok(RejectDest {
                layout: src.clone(),
                project: None,
                extra_id_paths: Vec::new(),
            });
        };
        let pref = self.router.route(project);
        let extra_id_paths = self.router.extra_id_paths_for(&pref.dir);
        Ok(RejectDest {
            layout: pref.layout,
            project: Some(pref.dir),
            extra_id_paths,
        })
    }

    #[tool(
        description = "List the projects that hold an issues.org under the tracker root.",
        annotations(
            title = "List projects",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_projects(&self) -> Result<CallToolResult, McpError> {
        text(self.router.visible_projects().map(|ps| {
            format!(
                "{}\n",
                ps.into_iter().map(|p| p.key).collect::<Vec<_>>().join("\n")
            )
        }))
    }

    #[tool(
        description = "List issues, optionally filtered by project and state.",
        annotations(title = "List issues", read_only_hint = true, open_world_hint = false)
    )]
    async fn vissue_list(
        &self,
        Parameters(args): Parameters<ListArgs>,
    ) -> Result<Json<Vec<IssueRow>>, McpError> {
        structured(issue_rows_routed(
            &self.router,
            args.project.as_deref(),
            args.state.as_deref(),
            false,
        ))
    }

    #[tool(
        description = "List actionable issues: TODO or STARTED with no open blocker.",
        annotations(
            title = "Actionable issues",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_ready(
        &self,
        Parameters(args): Parameters<ProjectArgs>,
    ) -> Result<Json<Vec<IssueRow>>, McpError> {
        structured(issue_rows_routed(
            &self.router,
            args.project.as_deref(),
            None,
            true,
        ))
    }

    #[tool(
        description = "Show one issue's metadata and file range. Never returns body prose.",
        annotations(
            title = "Show an issue",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_show(
        &self,
        Parameters(args): Parameters<IdArgs>,
    ) -> Result<Json<IssueDetail>, McpError> {
        structured(
            self.layout_for_id(&args.issue_id)
                .and_then(|layout| agent::show_detail(&layout, &args.issue_id)),
        )
    }

    #[tool(
        description = "Create an issue in a project's issues.org.",
        annotations(
            title = "Create an issue",
            read_only_hint = false,
            destructive_hint = false,
            idempotent_hint = false,
            open_world_hint = false
        )
    )]
    async fn vissue_create(
        &self,
        Parameters(args): Parameters<CreateArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(create_routed(
            &self.router,
            &args.project,
            &args.title,
            CreateOpts {
                priority: priority_char(args.priority.as_ref()),
                issue_type: args.issue_type.as_deref(),
                tags: args.tags.as_deref(),
                parent: args.parent.as_deref(),
                body: args.body.as_deref(),
                deadline: args.deadline.as_deref(),
                scheduled: args.scheduled.as_deref(),
                ..Default::default()
            },
        ))
    }

    #[tool(
        description = "Reject an issue by redirecting it to an existing destination (`to`) or a newly created replacement (`project` + `title`).",
        annotations(
            title = "Reject an issue",
            read_only_hint = false,
            destructive_hint = true,
            idempotent_hint = false,
            open_world_hint = false
        )
    )]
    async fn vissue_reject(
        &self,
        Parameters(args): Parameters<RejectArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(self.layout_for_id(&args.issue_id).and_then(|layout| {
            let dest =
                self.reject_destination(&layout, args.to.as_deref(), args.project.as_deref())?;
            ops::reject(
                &layout,
                &args.issue_id,
                RejectOpts {
                    to: args.to.as_deref(),
                    project: dest.project.as_deref(),
                    title: args.title.as_deref(),
                    reason: args.reason.as_deref(),
                    dst_layout: Some(&dest.layout),
                    dst_extra_id_paths: &dest.extra_id_paths,
                },
            )
        }))
    }

    #[tool(
        description = "Pick one terminal after a sibling close (DONE or CANCELLED).",
        annotations(
            title = "Resolve a sibling close",
            read_only_hint = false,
            destructive_hint = true,
            idempotent_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_resolve(
        &self,
        Parameters(args): Parameters<ResolveArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(
            self.layout_for_id(&args.issue_id)
                .and_then(|layout| ops::resolve_terminal(&layout, &args.issue_id, &args.state)),
        )
    }

    #[tool(
        description = "Update an issue's state, priority, or blocker edges.",
        annotations(
            title = "Update an issue",
            read_only_hint = false,
            destructive_hint = true,
            idempotent_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_update(
        &self,
        Parameters(args): Parameters<UpdateArgs>,
    ) -> Result<CallToolResult, McpError> {
        let outcome = self.layout_for_id(&args.issue_id).and_then(|layout| {
            ops::update_pred(
                &layout,
                &args.issue_id,
                args.state.as_deref(),
                priority_char(args.priority.as_ref()),
                args.block.as_deref(),
                args.unblock.as_deref(),
                UpdatePred {
                    if_state: args.if_state.as_deref(),
                    if_gen: args.if_gen,
                },
            )
        });
        text(outcome.map(|o| {
            let mut s = o.report;
            for hint in o.hints {
                s.push_str(&format!("[hint] {hint}\n"));
            }
            s
        }))
    }

    #[tool(
        description = "Claim an issue: move it to STARTED and stamp the claiming identity.",
        annotations(
            title = "Claim an issue",
            read_only_hint = false,
            destructive_hint = false,
            idempotent_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_claim(
        &self,
        Parameters(args): Parameters<ClaimArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(
            self.layout_for_id(&args.issue_id).and_then(|layout| {
                agent::claim(&layout, &args.issue_id, args.force.unwrap_or(false))
            }),
        )
    }

    #[tool(
        description = "Append a dated report to an issue's body. Use this to record work that was done: the logbook holds one line per event, so a written report belongs in the body. Markdown is safe.",
        annotations(
            title = "Append a report",
            read_only_hint = false,
            destructive_hint = false,
            idempotent_hint = false,
            open_world_hint = false
        )
    )]
    async fn vissue_append(
        &self,
        Parameters(args): Parameters<AppendArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(
            self.layout_for_id(&args.issue_id)
                .and_then(|layout| ops::append_body(&layout, &args.issue_id, &args.text)),
        )
    }

    #[tool(
        description = "Add a dated note to an issue's logbook without touching state or claim.",
        annotations(
            title = "Add a logbook note",
            read_only_hint = false,
            destructive_hint = false,
            idempotent_hint = false,
            open_world_hint = false
        )
    )]
    async fn vissue_note(
        &self,
        Parameters(args): Parameters<NoteArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(
            self.layout_for_id(&args.issue_id)
                .and_then(|layout| ops::note(&layout, &args.issue_id, &args.text)),
        )
    }

    #[tool(
        description = "Cast this agent's vote on an issue, or read the tally when no choice is given. One ballot per identity: voting again replaces your own ballot and never another agent's. The tally separates a majority from a plurality and from a tie, so consult it before acting on what looks like agreement.",
        annotations(
            title = "Cast a ballot",
            read_only_hint = false,
            destructive_hint = false,
            idempotent_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_vote(
        &self,
        Parameters(args): Parameters<VoteArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(self.layout_for_id(&args.issue_id).and_then(|layout| {
            let who = vissue_core::config::identity(&layout);
            ops::vote(&layout, &args.issue_id, args.choice.as_deref(), &who)
        }))
    }

    #[tool(
        description = "Cite, drop, or list the deeds this issue's work produced. A deed is deedar's frozen record of a product: name the accession here when work finishes, and the next unit opens it with `deedar get` instead of rereading a transcript. Omit both lists to read the citations. Accessions are `deed-<kind>-<slug>`, or a `sha256:` of the deed or of one product path.",
        annotations(
            title = "Cite or drop deeds",
            read_only_hint = false,
            destructive_hint = true,
            idempotent_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_deed(
        &self,
        Parameters(args): Parameters<DeedArgs>,
    ) -> Result<CallToolResult, McpError> {
        let add = args.add.unwrap_or_default();
        let remove = args.remove.unwrap_or_default();
        text(
            self.layout_for_id(&args.issue_id)
                .and_then(|layout| ops::deed(&layout, &args.issue_id, &add, &remove)),
        )
    }

    #[tool(
        description = "The working set for an issue: the plan it sits in, the deeds produced by what blocks it, the issue it was bounced from, and what it has produced itself. Read this before starting work on a node. Assembled from the declared edges rather than by resemblance, so it is what the plan says the work stands on and not a ranked guess; `vissue_related` answers the resemblance question. Set `excerpts` to splice in what each input concluded, which is in its body rather than in the deed it named.",
        annotations(
            title = "Working set for an issue",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_recall(
        &self,
        Parameters(args): Parameters<RecallArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(self.layout_for_id(&args.issue_id).and_then(|layout| {
            report::recall(
                &layout,
                &args.issue_id,
                args.depth.unwrap_or(1),
                args.excerpts.unwrap_or(false),
            )
        }))
    }

    #[tool(
        description = "Weigh an issue's ballots by who the group listens to (DeGroot averaging over the configured trust graph). Reports the count and the weighted position side by side, each agent's social power, and the two ways there is no consensus to report: a trust graph with more than one closed group, or one that never settles. Use it before acting on what a plurality looks like. Set `children` to roll up over a plan's children instead: that answers whether an epic can close, and it reports the children row by row rather than averaging them, because a split child has no position to fold in and an unvoted child is absent rather than neutral.",
        annotations(
            title = "Weighted consensus",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_consensus(
        &self,
        Parameters(args): Parameters<ConsensusArgs>,
    ) -> Result<CallToolResult, McpError> {
        let children = args.children.unwrap_or(false);
        text(self.layout_for_id(&args.issue_id).and_then(|layout| {
            if children {
                report::plan_consensus(&layout, &args.issue_id)
            } else {
                report::consensus(&layout, &args.issue_id)
            }
        }))
    }

    #[tool(
        description = "Every live claim, oldest first: who holds what issue, and for how long.",
        annotations(title = "Live claims", read_only_hint = true, open_world_hint = false)
    )]
    async fn vissue_claims(
        &self,
        Parameters(args): Parameters<ClaimsArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(report::claims(
            &self.layout,
            args.holder.as_deref(),
            args.project.as_deref(),
            args.json.unwrap_or(false),
        ))
    }

    #[tool(
        description = "Dated open work: deadlines and scheduled starts inside a horizon, overdue first.",
        annotations(
            title = "Dated open work",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_agenda(
        &self,
        Parameters(args): Parameters<AgendaArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(report::agenda(
            &self.layout,
            args.days.unwrap_or(14),
            args.project.as_deref(),
        ))
    }

    #[tool(
        description = "Fold an inbox org file: each unstamped `* TODO` heading becomes an issue and the heading is stamped with the id in place.",
        annotations(
            title = "Fold an inbox file",
            read_only_hint = false,
            destructive_hint = false,
            idempotent_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_fold(
        &self,
        Parameters(args): Parameters<FoldArgs>,
    ) -> Result<CallToolResult, McpError> {
        text({
            let pref = self.router.route(&args.project);
            ops::fold(&pref.layout, std::path::Path::new(&args.file), &pref.dir)
        })
    }

    #[tool(
        description = "Count issues, optionally filtered by project, state, or readiness.",
        annotations(title = "Count issues", read_only_hint = true, open_world_hint = false)
    )]
    async fn vissue_count(
        &self,
        Parameters(args): Parameters<CountArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(report::count(
            &self.layout,
            args.project.as_deref(),
            args.state.as_deref(),
            args.ready.unwrap_or(false),
        ))
    }

    #[tool(
        description = "Substring search over ids, titles, properties, and bodies.",
        annotations(
            title = "Search the corpus",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_search(
        &self,
        Parameters(args): Parameters<SearchArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(report::search(
            &self.layout,
            &args.query,
            args.limit.unwrap_or(20),
        ))
    }

    #[tool(
        description = "Explain bounded Org and lexical connections around an issue.",
        annotations(
            title = "Related issues",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_related(
        &self,
        Parameters(args): Parameters<RelatedArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(self.layout_for_id(&args.issue_id).and_then(|layout| {
            report::related(
                &layout,
                &args.issue_id,
                args.depth.unwrap_or(2),
                args.limit.unwrap_or(20),
                args.format.as_deref().unwrap_or("text"),
            )
        }))
    }

    #[tool(
        description = "List issues whose PARENT property matches this id.",
        annotations(
            title = "Children of an issue",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_children(
        &self,
        Parameters(args): Parameters<IdArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(
            self.layout_for_id(&args.issue_id)
                .and_then(|layout| report::children(&layout, &args.issue_id)),
        )
    }

    #[tool(
        description = "List issues that refer to this id through any relation, or that cite this deed accession.",
        annotations(title = "Backlinks", read_only_hint = true, open_world_hint = false)
    )]
    async fn vissue_backlinks(
        &self,
        Parameters(args): Parameters<IdArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(self.backlinks_text(&args.issue_id))
    }

    #[tool(
        description = "Issues waiting on this id. Dependency hygiene alias for backlinks.",
        annotations(
            title = "Issues waiting on this",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_waiting_on(
        &self,
        Parameters(args): Parameters<IdArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(
            self.layout_for_id(&args.issue_id)
                .and_then(|layout| agent::waiting_on(&layout, &args.issue_id)),
        )
    }

    #[tool(
        description = "The first lines of an issue's file range, screened for secrets.",
        annotations(title = "Body excerpt", read_only_hint = true, open_world_hint = false)
    )]
    async fn vissue_body_excerpt(
        &self,
        Parameters(args): Parameters<IdArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(
            self.layout_for_id(&args.issue_id)
                .and_then(|layout| agent::body_excerpt(&layout, &args.issue_id)),
        )
    }

    #[tool(
        description = "One issue's org text in full, untruncated, screened for secrets. Use this when handing an issue to someone as the thing to work from; body_excerpt is a capped preview.",
        annotations(
            title = "Full Org text",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_org(
        &self,
        Parameters(args): Parameters<IdArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(
            self.layout_for_id(&args.issue_id)
                .and_then(|layout| agent::org_text(&layout, &args.issue_id)),
        )
    }

    #[tool(
        description = "Children and blockers below an id, as ascii indent or Graphviz DOT.",
        annotations(
            title = "Tree below an id",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_tree(
        &self,
        Parameters(args): Parameters<TreeArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(self.layout_for_id(&args.issue_id).and_then(|layout| {
            report::tree(
                &layout,
                &args.issue_id,
                args.format.as_deref().unwrap_or("ascii"),
            )
        }))
    }

    #[tool(
        description = "The blocker and parent graph as Graphviz DOT.",
        annotations(title = "Graph as DOT", read_only_hint = true, open_world_hint = false)
    )]
    async fn vissue_graph(
        &self,
        Parameters(args): Parameters<ProjectArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(report::graph(&self.layout, args.project.as_deref()))
    }

    #[tool(
        description = "A markdown roadmap of active and closed work.",
        annotations(title = "Roadmap", read_only_hint = true, open_world_hint = false)
    )]
    async fn vissue_roadmap(
        &self,
        Parameters(args): Parameters<ProjectArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(report::roadmap(&self.layout, args.project.as_deref()))
    }

    #[tool(
        description = "One JSON object per issue per line.",
        annotations(
            title = "Export as JSON lines",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_export(
        &self,
        Parameters(args): Parameters<ProjectArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(report::export(&self.layout, args.project.as_deref()))
    }

    #[tool(
        description = "Validate the corpus: dangling edges, bad dates, duplicate ids.",
        annotations(
            title = "Validate the corpus",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_check(&self) -> Result<CallToolResult, McpError> {
        text(report::check(&self.layout).map(|r| r.text))
    }

    #[tool(
        description = "Rewrite files onto the Org / ELPA / vissue property split. Dry-run by default when dry_run is true.",
        annotations(
            title = "Rewrite property split",
            read_only_hint = false,
            destructive_hint = true,
            idempotent_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_normalize(
        &self,
        Parameters(args): Parameters<NormalizeArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(ops::normalize(
            &self.layout,
            args.project.as_deref(),
            args.dry_run.unwrap_or(false),
        ))
    }

    #[tool(
        description = "Checklist for agents and CI: stalled claims plus corpus validation.",
        annotations(
            title = "Hygiene checklist",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_hygiene(
        &self,
        Parameters(args): Parameters<HygieneArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(agent::hygiene(&self.layout, args.stale_days))
    }

    #[tool(
        description = "Content digest of the corpus: combined, per-project, issue count, generation.",
        annotations(
            title = "Corpus digest",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_digest(
        &self,
        Parameters(args): Parameters<DigestArgs>,
    ) -> Result<Json<vissue_core::digest::CorpusDigest>, McpError> {
        structured(vissue_core::digest::corpus_digest(
            &self.layout,
            &args.projects.unwrap_or_default(),
        ))
    }

    #[tool(
        description = "Check whether a mirror file's SYNC stamp still matches the tracker.",
        annotations(
            title = "Check a mirror stamp",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_mirror_check(
        &self,
        Parameters(args): Parameters<MirrorCheckArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(
            mirror::check(
                &self.layout,
                std::path::Path::new(&args.path),
                &args.projects.unwrap_or_default(),
            )
            .map(|v| v.report),
        )
    }

    #[tool(
        description = "Render a read-only projection of selected projects.",
        annotations(
            title = "Render a projection",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_mirror(
        &self,
        Parameters(args): Parameters<MirrorArgs>,
    ) -> Result<CallToolResult, McpError> {
        let format = match Format::parse(args.format.as_deref().unwrap_or("org")) {
            Ok(f) => f,
            Err(e) => return Err(McpError::invalid_params(format!("{e:#}"), None)),
        };
        text(mirror::render(
            &self.layout,
            &args.projects.unwrap_or_default(),
            format,
            args.state.as_deref(),
        ))
    }

    #[tool(
        description = "Change events with a sequence above `since`, plus the current generation.",
        annotations(
            title = "Change events",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_events(
        &self,
        Parameters(args): Parameters<EventsArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(events::since_report(
            &self.layout,
            args.since.unwrap_or(0),
            args.limit.unwrap_or(50),
        ))
    }

    #[tool(
        description = "Append a manual event, waking pollers without editing an issue.",
        annotations(
            title = "Append an event",
            read_only_hint = false,
            destructive_hint = false,
            idempotent_hint = false,
            open_world_hint = false
        )
    )]
    async fn vissue_ping(
        &self,
        Parameters(args): Parameters<PingArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(events::ping_report(&self.layout, args.detail.as_deref()))
    }

    #[tool(
        description = "The generation counter. Compare against the last value seen.",
        annotations(
            title = "Generation counter",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_gen(&self) -> Result<CallToolResult, McpError> {
        text(Ok::<_, vissue_core::error::Error>(format!(
            "{}\n",
            events::generation(&self.layout)
        )))
    }

    #[tool(
        description = "Report the server version and the resolved root and prefix.",
        annotations(
            title = "Server identity",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_identity(&self) -> Result<CallToolResult, McpError> {
        text(Ok::<_, vissue_core::error::Error>(identity_report(
            &self.layout,
            &self.router,
        )))
    }

    #[tool(
        description = "Transitive blocker ancestors, bounded by hop depth.",
        annotations(
            title = "Blocker ancestors",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_ancestors(
        &self,
        Parameters(args): Parameters<DepthArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(
            self.layout_for_id(&args.issue_id).and_then(|layout| {
                report::ancestors(&layout, &args.issue_id, args.depth.unwrap_or(3))
            }),
        )
    }

    #[tool(
        description = "Issues transitively waiting on this id, bounded by hop depth.",
        annotations(
            title = "Transitive impact",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_impact(
        &self,
        Parameters(args): Parameters<DepthArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(
            self.layout_for_id(&args.issue_id).and_then(|layout| {
                report::impact(&layout, &args.issue_id, args.depth.unwrap_or(3))
            }),
        )
    }

    #[tool(
        description = "Cycles in the blocker graph, or a line saying there are none.",
        annotations(
            title = "Blocker cycles",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_cycles(&self) -> Result<CallToolResult, McpError> {
        text(report::cycles(&self.layout))
    }

    #[tool(
        description = "Pack a slice of the tracker into a directory somebody else can open: the issues named, everything they stand on, and the deed accessions their work produced. Deeds are named and not enclosed, because only the deed store can vouch for them; fill them with `deedar export --into <dir>/data/deeds -` and then seal. Reports what was packed and what came along that was not asked for.",
        annotations(
            title = "Pack a satchel",
            read_only_hint = false,
            destructive_hint = false,
            idempotent_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_satchel(
        &self,
        Parameters(args): Parameters<SatchelArgs>,
    ) -> Result<CallToolResult, McpError> {
        let slice = vissue_core::satchel::Slice {
            projects: args.projects.unwrap_or_default(),
            issues: args.issues.unwrap_or_default(),
        };
        text(
            vissue_core::satchel::pack(&self.layout, &slice, std::path::Path::new(&args.out))
                .map(|report| report.render()),
        )
    }

    #[tool(
        description = "Re-manifest a satchel over everything now in its payload. Run this after the deed store has filled in the deeds, because the manifest written at pack time covers only what the tracker wrote.",
        annotations(
            title = "Seal a satchel",
            read_only_hint = false,
            destructive_hint = false,
            idempotent_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_satchel_seal(
        &self,
        Parameters(args): Parameters<SatchelDirArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(
            vissue_core::satchel::seal(std::path::Path::new(&args.dir))
                .map(|report| report.render()),
        )
    }

    #[tool(
        description = "Check a satchel that arrived: every file the manifest names is present and unchanged, and nothing in the payload is unaccounted for. Fails with what is wrong rather than a verdict.",
        annotations(
            title = "Check a satchel",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_satchel_verify(
        &self,
        Parameters(args): Parameters<SatchelDirArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(
            vissue_core::satchel::verify(std::path::Path::new(&args.dir))
                .map(|report| report.render()),
        )
    }

    #[tool(
        description = "Move an issue heading to another project file.",
        annotations(
            title = "Move to another project",
            read_only_hint = false,
            destructive_hint = true,
            idempotent_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_refile(
        &self,
        Parameters(args): Parameters<RefileArgs>,
    ) -> Result<CallToolResult, McpError> {
        text(self.layout_for_id(&args.issue_id).and_then(|layout| {
            let dest = self.router.route(&args.to);
            ops::refile_to(&layout, &args.issue_id, &dest.layout, &dest.dir)
        }))
    }

    #[tool(
        description = "Block until the generation counter passes last, or until an issue is DONE or CANCELLED when until_terminal and id are set.",
        annotations(
            title = "Wait for a change",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_wait(
        &self,
        Parameters(args): Parameters<WaitArgs>,
    ) -> Result<CallToolResult, McpError> {
        if args.until_terminal.unwrap_or(false) {
            let Some(id) = args.id.as_deref() else {
                return Err(McpError::invalid_params(
                    "--until-terminal requires id",
                    None,
                ));
            };
            return text(
                events::wait_until_terminal(
                    &match self.layout_for_id(id) {
                        Ok(layout) => layout,
                        Err(e) => return text(Err(e)),
                    },
                    id,
                    args.poll_ms.unwrap_or(200),
                    args.timeout_ms.unwrap_or(10_000),
                )
                .map(|outcome| match outcome {
                    events::TerminalWait::Done { generation } => {
                        format!("DONE {generation}\n")
                    }
                    events::TerminalWait::Cancelled { generation } => {
                        format!("CANCELLED {generation}\n")
                    }
                    events::TerminalWait::Timeout { generation, state } => {
                        format!("TIMEOUT {state} {generation}\n")
                    }
                }),
            );
        }
        let last = args.last.unwrap_or(0);
        text(
            events::wait_generation(
                &self.layout,
                last,
                args.poll_ms.unwrap_or(200),
                args.timeout_ms.unwrap_or(10_000),
            )
            .map(|generation| {
                let timed_out = if generation <= last { " timeout" } else { "" };
                format!("{generation}{timed_out}\n")
            }),
        )
    }

    #[tool(
        description = "The identity a claim would record.",
        annotations(
            title = "Claiming identity",
            read_only_hint = true,
            open_world_hint = false
        )
    )]
    async fn vissue_whoami(&self) -> Result<CallToolResult, McpError> {
        text(Ok::<_, vissue_core::error::Error>(format!(
            "{}\n",
            vissue_core::config::identity(&self.layout)
        )))
    }
}

fn create_routed(
    router: &Router,
    project: &str,
    title: &str,
    opts: CreateOpts<'_>,
) -> vissue_core::Result<String> {
    let pref = router.route(project);
    let twins = router.extra_id_paths_for(&pref.dir);
    let opts = CreateOpts {
        extra_id_paths: &twins,
        ..opts
    };
    ops::create(&pref.layout, &pref.dir, title, opts)
}

fn issue_rows_routed(
    router: &Router,
    project: Option<&str>,
    state: Option<&str>,
    ready_only: bool,
) -> vissue_core::Result<Vec<IssueRow>> {
    if let Some(p) = project {
        let pref = router.route(p);
        return agent::issues_rows(&pref.layout, Some(&pref.dir), state, ready_only);
    }
    let mut rows = Vec::new();
    for pref in router.visible_projects()? {
        rows.extend(agent::issues_rows(
            &pref.layout,
            Some(&pref.dir),
            state,
            ready_only,
        )?);
    }
    Ok(rows)
}

fn identity_report(layout: &Layout, router: &Router) -> String {
    let mut out = format!(
        "vissue-mcp {}\nprotocol: {}\nroot:   {}\nprefix: {}\nroot={}\nprefix={}\n",
        env!("CARGO_PKG_VERSION"),
        vissue_core::org::PROTOCOL_VERSION,
        layout.root().display(),
        layout.prefix(),
        layout.root().display(),
        layout.prefix()
    );
    if let Ok(prefs) = router.visible_projects() {
        for pref in prefs {
            if pref.key == pref.dir
                && pref.layout.root() == layout.root()
                && pref.layout.prefix() == layout.prefix()
            {
                continue;
            }
            out.push_str(&format!(
                "route: {} -> {} {} {}\n",
                pref.key,
                pref.layout.root().display(),
                pref.layout.prefix(),
                pref.dir
            ));
        }
    }
    out
}

/// The scheme issues are addressable under.
const SCHEME: &str = "vissue";

/// Org text, which is what every resource here is.
const ORG: &str = "text/x-org";

impl VissueServer {
    /// One issue's org text, addressed rather than queried.
    fn read_issue(&self, id: &str) -> Result<String, McpError> {
        self.layout_for_id(id)
            .and_then(|layout| agent::org_text(&layout, id))
            .map_err(|e| McpError::resource_not_found(format!("{e}"), None))
    }

    /// Ids matching what has been typed, by id prefix then by title.
    ///
    /// Split out from the protocol handler so the matching can be tested
    /// without standing up a session.
    fn complete_issue_ids(&self, typed: &str) -> Result<Vec<String>, McpError> {
        let typed = typed.to_ascii_lowercase();
        let mut hit: Vec<String> = Vec::new();
        for pref in self
            .router
            .visible_projects()
            .map_err(|e| McpError::internal_error(format!("{e}"), None))?
        {
            let rows = agent::issues_rows(&pref.layout, Some(&pref.dir), None, false)
                .map_err(|e| McpError::internal_error(format!("{e}"), None))?;
            for row in rows {
                let id = row.id.to_ascii_lowercase();
                if typed.is_empty()
                    || id.starts_with(&typed)
                    || row.title.to_ascii_lowercase().contains(&typed)
                {
                    hit.push(row.id);
                }
            }
        }
        hit.sort_unstable();
        hit.dedup();
        Ok(hit)
    }

    /// One project's issues, as the org a reader would open.
    fn read_project(&self, project: &str) -> Result<String, McpError> {
        let pref = self.router.route(project);
        mirror::render(
            &pref.layout,
            std::slice::from_ref(&pref.dir),
            Format::Org,
            None,
        )
        .map_err(|e| McpError::resource_not_found(format!("{e}"), None))
    }
}

#[tool_handler]
impl ServerHandler for VissueServer {
    fn get_info(&self) -> ServerInfo {
        ServerInfo::new(
            ServerCapabilities::builder()
                .enable_tools()
                .enable_resources()
                .enable_completions()
                .build(),
        )
        .with_server_info(Implementation::new("vissue", env!("CARGO_PKG_VERSION")))
        .with_instructions(
            "An issue is addressable at vissue://issue/<id> and a project at \
             vissue://project/<name>. Read those rather than calling a tool when \
             what you want is the text; the tools answer questions the text does \
             not, like what is ready or what blocks what.",
        )
    }

    /// The projects, which are the resources that exist without being named.
    ///
    /// Issues are not listed. There are hundreds and they arrive through a
    /// template instead: a list a client has to page through to find one id is
    /// worse than a pattern it can fill in, and the ids come back from every
    /// tool that answers a question.
    async fn list_resources(
        &self,
        _request: Option<PaginatedRequestParams>,
        _context: rmcp::service::RequestContext<rmcp::RoleServer>,
    ) -> Result<ListResourcesResult, McpError> {
        let projects = self
            .router
            .visible_projects()
            .map_err(|e| McpError::internal_error(format!("{e}"), None))?;
        Ok(ListResourcesResult::with_all_items(
            projects
                .into_iter()
                .map(|p| {
                    let mut resource =
                        Resource::new(format!("{SCHEME}://project/{}", p.key), p.key.clone());
                    resource.title = Some(format!("{} issues", p.key));
                    resource.description = Some(format!("Every issue in the {} project.", p.key));
                    resource.mime_type = Some(ORG.to_string());
                    resource
                })
                .collect(),
        ))
    }

    /// The pattern one issue is addressed by.
    async fn list_resource_templates(
        &self,
        _request: Option<PaginatedRequestParams>,
        _context: rmcp::service::RequestContext<rmcp::RoleServer>,
    ) -> Result<ListResourceTemplatesResult, McpError> {
        let mut template =
            ResourceTemplate::new(format!("{SCHEME}://issue/{{id}}"), "issue".to_string());
        template.title = Some("One issue".to_string());
        template.description =
            Some("The org text of one issue, by id, with secrets screened out.".to_string());
        template.mime_type = Some(ORG.to_string());
        Ok(ListResourceTemplatesResult::with_all_items(vec![template]))
    }

    /// Fill in the id a resource template asks for.
    ///
    /// The spec completes resource template and prompt arguments, not tool
    /// arguments, which is the right shape here anyway: the template is the
    /// one place a caller has to produce an id from nothing. Every tool that
    /// answers a question hands ids back, so a caller working from an answer
    /// already has them; a caller starting from the template does not.
    ///
    /// Matching is a prefix on the id, then anywhere in the title, because a
    /// person completing an issue remembers what it was about more often than
    /// what it was called. Capped at the hundred the spec allows, with
    /// `has_more` set so a client can say the list is a window rather than the
    /// answer.
    async fn complete(
        &self,
        request: CompleteRequestParams,
        _context: rmcp::service::RequestContext<rmcp::RoleServer>,
    ) -> Result<CompleteResult, McpError> {
        let Reference::Resource(template) = &request.r#ref else {
            return Ok(CompleteResult::default());
        };
        if !template.uri.starts_with(&format!("{SCHEME}://issue/")) || request.argument.name != "id"
        {
            return Ok(CompleteResult::default());
        }
        let mut hit = self.complete_issue_ids(&request.argument.value)?;
        let total = hit.len();
        hit.truncate(CompletionInfo::MAX_VALUES);
        let more = total > hit.len();
        let mut completion =
            CompletionInfo::new(hit).map_err(|e| McpError::internal_error(e, None))?;
        completion.total = u32::try_from(total).ok();
        completion.has_more = Some(more);
        Ok(CompleteResult::new(completion))
    }

    async fn read_resource(
        &self,
        request: ReadResourceRequestParams,
        _context: rmcp::service::RequestContext<rmcp::RoleServer>,
    ) -> Result<ReadResourceResponse, McpError> {
        let uri = request.uri.clone();
        let rest = uri.strip_prefix(&format!("{SCHEME}://")).ok_or_else(|| {
            McpError::resource_not_found(format!("not a {SCHEME} uri: {uri}"), None)
        })?;
        let text = match rest.split_once('/') {
            Some(("issue", id)) if !id.is_empty() => self.read_issue(id)?,
            Some(("project", project)) if !project.is_empty() => self.read_project(project)?,
            _ => {
                return Err(McpError::resource_not_found(
                    format!("{uri} names neither an issue nor a project"),
                    None,
                ));
            }
        };
        Ok(
            ReadResourceResult::new(vec![ResourceContents::TextResourceContents {
                uri,
                mime_type: Some(ORG.to_string()),
                text,
                meta: None,
            }])
            .into(),
        )
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use vissue_core::config::DEFAULT_PREFIX;

    /// The tools an agent uses to work a node: recall before, deed after.
    ///
    /// Over the tool surface rather than the library, because this is the one an
    /// agent actually reaches for, and a working set it cannot ask for is a
    /// working set it will not use.
    #[tokio::test]
    async fn the_working_set_reaches_the_tool_surface() {
        let dir = tempfile::tempdir().unwrap();
        let layout = Layout::new(dir.path(), DEFAULT_PREFIX);
        std::fs::create_dir_all(layout.projects_dir()).unwrap();
        ops::create(
            &layout,
            "keys",
            "catalog the actions",
            CreateOpts::default(),
        )
        .unwrap();
        ops::create(&layout, "keys", "write the schema", CreateOpts::default()).unwrap();
        let id_of = |title: &str| -> String {
            vissue_core::store::load_all(&layout)
                .unwrap()
                .into_iter()
                .find(|(_, h)| h.title == title)
                .map(|(_, h)| h.id)
                .expect("issue")
        };
        let first = id_of("catalog the actions");
        let second = id_of("write the schema");
        ops::update(&layout, &second, None, None, Some(&first), None).unwrap();

        let server = VissueServer::with_layout(layout.clone());
        let cited = server
            .vissue_deed(Parameters(DeedArgs {
                issue_id: first.clone(),
                add: Some(vec!["deed-file-catalog".into()]),
                remove: None,
            }))
            .await
            .unwrap();
        assert_eq!(cited.is_error, Some(false));

        let recalled = server
            .vissue_recall(Parameters(RecallArgs {
                issue_id: second.clone(),
                depth: None,
                excerpts: None,
            }))
            .await
            .unwrap();
        assert_eq!(recalled.is_error, Some(false));
        let rendered = format!("{:?}", recalled.content);
        assert!(
            rendered.contains("deed-file-catalog"),
            "the input's product is what the next unit opens: {rendered}"
        );

        // A citation nothing can resolve is an error the agent sees, not a
        // value the heading quietly keeps.
        let refused = server
            .vissue_deed(Parameters(DeedArgs {
                issue_id: first,
                add: Some(vec!["/tmp/note.md".into()]),
                remove: None,
            }))
            .await;
        let message = refused.expect_err("a path is not an accession").message;
        assert!(message.contains("not a deed accession"), "{message}");
    }

    /// The consensus tool answers on an unconfigured tracker, where it is the
    /// tally as shares, and says so.
    #[tokio::test]
    async fn the_consensus_tool_answers_without_trust_configured() {
        let dir = tempfile::tempdir().unwrap();
        let layout = Layout::new(dir.path(), DEFAULT_PREFIX);
        std::fs::create_dir_all(layout.projects_dir()).unwrap();
        ops::create(&layout, "api", "ship it?", CreateOpts::default()).unwrap();
        let id = vissue_core::store::load_all(&layout).unwrap()[0]
            .1
            .id
            .clone();
        for (agent, choice) in [("a", "ship"), ("b", "ship"), ("c", "hold")] {
            ops::vote(&layout, &id, Some(choice), agent).unwrap();
        }

        let server = VissueServer::with_layout(layout);
        let weighed = server
            .vissue_consensus(Parameters(ConsensusArgs {
                issue_id: id,
                children: None,
            }))
            .await
            .unwrap();
        assert_eq!(weighed.is_error, Some(false));
        let rendered = format!("{:?}", weighed.content);
        assert!(rendered.contains("trust default"), "{rendered}");
        assert!(rendered.contains("holds: ship"), "{rendered}");
    }

    #[tokio::test]
    async fn tools_answer_against_a_temporary_layout() {
        let dir = tempfile::tempdir().unwrap();
        let layout = Layout::new(dir.path(), DEFAULT_PREFIX);
        std::fs::create_dir_all(layout.projects_dir()).unwrap();
        ops::create(&layout, "sample", "first", CreateOpts::default()).unwrap();

        let server = VissueServer::with_layout(layout);
        // The rows come back as rows. Reading a field is a stronger check
        // than an error flag: it fails if the shape moves, not only if the
        // call does.
        let listed = server
            .vissue_list(Parameters(ListArgs {
                project: None,
                state: None,
            }))
            .await
            .unwrap();
        assert_eq!(listed.0.len(), 1, "{:?}", listed.0);
        assert_eq!(listed.0[0].project, "sample");
        assert_eq!(listed.0[0].state, "TODO");

        let counted = server
            .vissue_count(Parameters(CountArgs {
                project: None,
                state: None,
                ready: Some(true),
            }))
            .await
            .unwrap();
        assert_eq!(counted.is_error, Some(false));
    }

    /// The tools that write, exercised in the order an agent uses them.
    ///
    /// The read-only surface is covered above; the create/update/claim/note
    /// path was not, and it is the half that changes the corpus.
    #[tokio::test]
    async fn the_write_tools_carry_their_arguments_through_to_the_file() {
        let dir = tempfile::tempdir().unwrap();
        let layout = Layout::new(dir.path(), DEFAULT_PREFIX);
        std::fs::create_dir_all(layout.projects_dir()).unwrap();
        let server = VissueServer::with_layout(layout.clone());

        let made = server
            .vissue_create(Parameters(CreateArgs {
                project: "atlas".into(),
                title: "Rotate the signing key".into(),
                priority: Some("A".into()),
                issue_type: Some("chore".into()),
                tags: Some("ops,security".into()),
                parent: None,
                body: Some("The old one expires this quarter.".into()),
                deadline: Some("[2026-06-30]".into()),
                scheduled: None,
            }))
            .await
            .unwrap();
        assert_eq!(made.is_error, Some(false));

        let file = std::fs::read_to_string(layout.project_issues_path("atlas")).unwrap();
        assert!(
            file.contains("DEADLINE") && file.contains("2026-06-30"),
            "the tool accepted a deadline and did not write it: {file}"
        );
        assert!(file.contains("Rotate the signing key"), "{file}");
        assert!(file.contains("[#A]"), "priority not carried: {file}");
        assert!(file.contains(":TYPE:       chore"), "{file}");
        assert!(
            file.contains("expires this quarter"),
            "body missing: {file}"
        );
        assert!(
            file.contains(":ops:") && file.contains(":security:"),
            "{file}"
        );

        let id = file
            .lines()
            .find_map(|l| l.trim().strip_prefix(":ID:"))
            .map(|s| s.trim().to_string())
            .expect("an id");

        // Claim, then note: neither may disturb the other's stamp.
        assert_eq!(
            server
                .vissue_claim(Parameters(ClaimArgs {
                    issue_id: id.clone(),
                    force: None,
                }))
                .await
                .unwrap()
                .is_error,
            Some(false)
        );
        assert_eq!(
            server
                .vissue_note(Parameters(NoteArgs {
                    issue_id: id.clone(),
                    text: "waiting on the vault rotation window".into(),
                }))
                .await
                .unwrap()
                .is_error,
            Some(false)
        );
        // A written report goes into the body, where markdown is safe.
        assert_eq!(
            server
                .vissue_append(Parameters(AppendArgs {
                    issue_id: id.clone(),
                    text: "## What changed\n\n* rotated the key\n".into(),
                }))
                .await
                .unwrap()
                .is_error,
            Some(false)
        );

        let after = std::fs::read_to_string(layout.project_issues_path("atlas")).unwrap();
        assert!(after.contains("## What changed"), "{after}");
        assert!(after.contains(":CLAIMED_BY:"), "{after}");
        assert!(after.contains("vault rotation window"), "{after}");

        // Closing reports the change; the tool surfaces hints alongside it.
        let closed = server
            .vissue_update(Parameters(UpdateArgs {
                issue_id: id.clone(),
                state: Some("DONE".into()),
                priority: Some("C".into()),
                block: None,
                unblock: None,
                if_state: None,
                if_gen: None,
            }))
            .await
            .unwrap();
        assert_eq!(closed.is_error, Some(false));
        let done = std::fs::read_to_string(layout.project_issues_path("atlas")).unwrap();
        assert!(done.contains("DONE"), "{done}");
        assert!(done.contains("[#C]"), "{done}");
    }

    #[tokio::test]
    async fn a_write_tool_reports_an_unknown_id_as_an_error() {
        let dir = tempfile::tempdir().unwrap();
        let layout = Layout::new(dir.path(), DEFAULT_PREFIX);
        std::fs::create_dir_all(layout.projects_dir()).unwrap();
        let server = VissueServer::with_layout(layout);

        let err = server
            .vissue_note(Parameters(NoteArgs {
                issue_id: "atlas-zzzz".into(),
                text: "into the void".into(),
            }))
            .await
            .unwrap_err();
        assert!(format!("{err:?}").contains("atlas-zzzz"), "{err:?}");
    }

    #[tokio::test]
    async fn an_unknown_mirror_format_is_an_invalid_parameter() {
        let dir = tempfile::tempdir().unwrap();
        let layout = Layout::new(dir.path(), DEFAULT_PREFIX);
        let server = VissueServer::with_layout(layout);
        let err = server
            .vissue_mirror(Parameters(MirrorArgs {
                projects: None,
                format: Some("pdf".into()),
                state: None,
            }))
            .await
            .unwrap_err();
        assert!(format!("{err:?}").contains("pdf"), "{err:?}");
    }

    /// Every tool says whether it reads or writes, and a new one cannot ship
    /// without saying.
    ///
    /// The hints are what a client uses to decide whether a call is safe to
    /// make on its own, retry, or batch. A surface where the tool that lists
    /// projects and the tool that rewrites every file look alike gives a
    /// caller nothing to reason with, and forty-six unannotated tools is a
    /// surface that says nothing forty-six times.
    ///
    /// The read-only set is written out rather than derived, so adding a tool
    /// fails here until somebody decides which side it is on.
    #[test]
    fn every_tool_declares_what_it_does_to_the_tracker() {
        const READS: &[&str] = &[
            "vissue_agenda",
            "vissue_ancestors",
            "vissue_backlinks",
            "vissue_body_excerpt",
            "vissue_check",
            "vissue_children",
            "vissue_claims",
            "vissue_consensus",
            "vissue_count",
            "vissue_cycles",
            "vissue_digest",
            "vissue_events",
            "vissue_export",
            "vissue_gen",
            "vissue_graph",
            "vissue_hygiene",
            "vissue_identity",
            "vissue_impact",
            "vissue_list",
            "vissue_mirror",
            "vissue_mirror_check",
            "vissue_org",
            "vissue_projects",
            "vissue_ready",
            "vissue_recall",
            "vissue_related",
            "vissue_roadmap",
            "vissue_satchel_verify",
            "vissue_search",
            "vissue_show",
            "vissue_tree",
            "vissue_wait",
            "vissue_waiting_on",
            "vissue_whoami",
        ];

        let tools = VissueServer::tool_router().list_all();
        assert!(tools.len() >= READS.len(), "{} tools", tools.len());

        let mut reads: Vec<&str> = Vec::new();
        for tool in &tools {
            let hints = tool
                .annotations
                .as_ref()
                .unwrap_or_else(|| panic!("{} carries no annotations", tool.name));
            assert!(
                hints.title.as_ref().is_some_and(|t| !t.is_empty()),
                "{} has no title",
                tool.name
            );
            // Everything here reads files under one root. A tool that reached
            // outside it would be a different kind of thing and should say so.
            assert_eq!(
                hints.open_world_hint,
                Some(false),
                "{} claims an open world",
                tool.name
            );
            match hints.read_only_hint {
                Some(true) => reads.push(&tool.name),
                Some(false) => {
                    // The other two hints are meaningful only for a writer,
                    // and a writer that leaves them unset takes the spec's
                    // defaults: destructive, not idempotent. Say it instead.
                    assert!(
                        hints.destructive_hint.is_some(),
                        "{} does not say whether it is destructive",
                        tool.name
                    );
                    assert!(
                        hints.idempotent_hint.is_some(),
                        "{} does not say whether it is idempotent",
                        tool.name
                    );
                }
                None => panic!("{} does not say whether it writes", tool.name),
            }
        }
        reads.sort_unstable();
        assert_eq!(reads, READS, "the read-only set moved");
    }

    /// An issue is a thing with an identity and text, which is what a
    /// resource is. A question about issues is what a tool is for.
    #[tokio::test]
    async fn an_issue_is_addressable_without_a_tool_call() {
        let root =
            std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../tests/fixture_vault");
        let server = VissueServer::with_layout(Layout::new(&root, DEFAULT_PREFIX));

        let one = server.read_issue("atlas-2c3d").expect("the issue reads");
        assert!(one.contains("atlas-2c3d"), "{one}");

        let project = server.read_project("atlas").expect("the project reads");
        assert!(project.contains("atlas-2c3d"), "{project}");

        // A uri that names nothing is not found rather than empty, which is
        // the same distinction the tracker root makes.
        assert!(server.read_issue("atlas-nosuch").is_err());
    }

    /// The template's id completes from the corpus, by id and by title.
    ///
    /// A caller working from any tool's answer already has ids. A caller
    /// starting from the template has nothing, which is the case this exists
    /// for, and remembering what an issue was about is more common than
    /// remembering its suffix.
    #[tokio::test]
    async fn the_issue_template_completes_its_id() {
        let root =
            std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../tests/fixture_vault");
        let server = VissueServer::with_layout(Layout::new(&root, DEFAULT_PREFIX));

        let ids = server.complete_issue_ids("atlas-2c").expect("completes");
        assert!(ids.contains(&"atlas-2c3d".to_string()), "{ids:?}");

        // Empty offers the corpus rather than nothing, which is what a client
        // opening a picker wants.
        let all = server.complete_issue_ids("").expect("completes");
        assert!(all.len() >= ids.len(), "{} vs {}", all.len(), ids.len());

        // A suffix nobody has completes to nothing rather than everything.
        assert!(
            server
                .complete_issue_ids("zzzz-nope")
                .expect("completes")
                .is_empty()
        );
    }

    /// The tools that answer with data publish the shape of it.
    ///
    /// A schema is what lets a caller check a reply rather than hope, and it
    /// is derived from the type that is returned, so this also fails if the
    /// core stops deriving it and the tool silently goes back to handing over
    /// a string.
    #[test]
    fn the_tools_that_return_data_publish_its_shape() {
        const SHAPED: &[&str] = &[
            "vissue_digest",
            "vissue_list",
            "vissue_ready",
            "vissue_show",
        ];
        let tools = VissueServer::tool_router().list_all();
        let mut shaped: Vec<&str> = tools
            .iter()
            .filter(|t| t.output_schema.is_some())
            .map(|t| t.name.as_ref())
            .collect();
        shaped.sort_unstable();
        assert_eq!(shaped, SHAPED, "the tools answering with data moved");

        let rows = tools
            .iter()
            .find(|t| t.name == "vissue_list")
            .and_then(|t| t.output_schema.clone())
            .expect("a schema for the rows");
        // An array of issue rows, and the row names the fields a board paints.
        let rendered = serde_json::to_string(&rows).expect("schema serializes");
        for field in ["id", "state", "priority", "title", "project", "blocked_by"] {
            assert!(rendered.contains(field), "{field} is not in {rendered}");
        }
    }

    #[tokio::test]
    async fn read_only_tools_cover_the_fixture_tracker_surface() {
        let root =
            std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../tests/fixture_vault");
        let server = VissueServer::with_layout(Layout::new(&root, DEFAULT_PREFIX));

        assert!(
            !server
                .vissue_projects()
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        let listed = server
            .vissue_list(Parameters(ListArgs {
                project: Some("atlas".into()),
                state: Some("TODO".into()),
            }))
            .await
            .unwrap();
        assert!(listed.0.iter().all(|row| row.state == "TODO"));
        let ready = server
            .vissue_ready(Parameters(ProjectArgs {
                project: Some("atlas".into()),
            }))
            .await
            .unwrap();
        assert!(ready.0.iter().all(|row| row.blocked_by.is_empty()));
        let shown = server
            .vissue_show(Parameters(IdArgs {
                issue_id: "atlas-2c3d".into(),
            }))
            .await
            .unwrap();
        assert_eq!(shown.0.id, "atlas-2c3d");
        assert!(
            !server
                .vissue_claims(Parameters(ClaimsArgs {
                    holder: None,
                    project: Some("atlas".into()),
                    json: Some(true),
                }))
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        assert!(
            !server
                .vissue_agenda(Parameters(AgendaArgs {
                    days: Some(7),
                    project: Some("atlas".into()),
                }))
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        assert!(
            !server
                .vissue_search(Parameters(SearchArgs {
                    query: "fixture".into(),
                    limit: Some(5),
                }))
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        assert!(
            !server
                .vissue_related(Parameters(RelatedArgs {
                    issue_id: "atlas-1a2b".into(),
                    depth: Some(2),
                    limit: Some(5),
                    format: Some("org".into()),
                }))
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        assert!(
            !server
                .vissue_children(Parameters(IdArgs {
                    issue_id: "atlas-1a2b".into(),
                }))
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        assert!(
            !server
                .vissue_backlinks(Parameters(IdArgs {
                    issue_id: "atlas-1a2b".into(),
                }))
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        assert!(
            !server
                .vissue_waiting_on(Parameters(IdArgs {
                    issue_id: "atlas-1a2b".into(),
                }))
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        assert!(
            !server
                .vissue_org(Parameters(IdArgs {
                    issue_id: "atlas-2c3d".into(),
                }))
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        assert!(
            !server
                .vissue_body_excerpt(Parameters(IdArgs {
                    issue_id: "atlas-2c3d".into(),
                }))
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        assert!(
            !server
                .vissue_tree(Parameters(TreeArgs {
                    issue_id: "atlas-1a2b".into(),
                    format: Some("ascii".into()),
                }))
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        assert!(
            !server
                .vissue_graph(Parameters(ProjectArgs {
                    project: Some("atlas".into()),
                }))
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        assert!(
            !server
                .vissue_roadmap(Parameters(ProjectArgs {
                    project: Some("atlas".into()),
                }))
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        assert!(
            !server
                .vissue_export(Parameters(ProjectArgs {
                    project: Some("atlas".into()),
                }))
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        assert!(
            !server
                .vissue_check()
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        assert!(
            !server
                .vissue_hygiene(Parameters(HygieneArgs {
                    stale_days: Some(30)
                }))
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        let digested = server
            .vissue_digest(Parameters(DigestArgs {
                projects: Some(vec!["atlas".into()]),
            }))
            .await
            .unwrap();
        assert_eq!(digested.0.combined.len(), 16, "{}", digested.0.combined);
        assert!(
            !server
                .vissue_mirror(Parameters(MirrorArgs {
                    projects: Some(vec!["atlas".into()]),
                    format: Some("markdown".into()),
                    state: Some("TODO".into()),
                }))
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        assert!(
            !server
                .vissue_events(Parameters(EventsArgs {
                    since: Some(0),
                    limit: Some(10),
                }))
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        assert!(!server.vissue_gen().await.unwrap().is_error.unwrap_or(false));
        assert!(
            !server
                .vissue_identity()
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        assert!(
            !server
                .vissue_ancestors(Parameters(DepthArgs {
                    issue_id: "atlas-3e4f".into(),
                    depth: Some(2),
                }))
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        assert!(
            !server
                .vissue_impact(Parameters(DepthArgs {
                    issue_id: "atlas-1a2b".into(),
                    depth: Some(2),
                }))
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        assert!(
            !server
                .vissue_cycles()
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        assert!(
            !server
                .vissue_whoami()
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        assert!(
            !server
                .vissue_wait(Parameters(WaitArgs {
                    last: Some(0),
                    id: None,
                    until_terminal: None,
                    poll_ms: Some(10),
                    timeout_ms: Some(30),
                }))
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        assert!(
            !server
                .vissue_wait(Parameters(WaitArgs {
                    last: None,
                    id: Some("atlas-4g5h".into()),
                    until_terminal: Some(true),
                    poll_ms: Some(10),
                    timeout_ms: Some(200),
                }))
                .await
                .unwrap()
                .is_error
                .unwrap_or(false)
        );
        let info = server.get_info();
        assert!(info.capabilities.tools.is_some());
    }
}