shohei 2.4.1

Infrastructure diagnostics library: DNS, DNSSEC, TLS certificate inspection, email security, DNS propagation, and MCP-integrated AI agent support
Documentation
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
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
//! shohei MCP server — expose shohei library API as Claude tools.
//!
//! This binary makes shohei's DNS/TLS/email/propagation/latency APIs available
//! to Claude and other AI agents via the Model Context Protocol (MCP).
//!
//! Run with: shohei-mcp (reads JSON-RPC 2.0 on stdin, writes on stdout)

use rmcp::{ServiceExt, handler::server::wrapper::Parameters, tool_router, tool, schemars};
use serde::Deserialize;
use shohei::api::*;

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckDnsParams {
    /// Domain to query
    domain: String,
    /// Record types (A, AAAA, MX, TXT, etc)
    #[serde(default)]
    record_types: Option<Vec<String>>,
    /// Transport to use: System, DoH, DoT, DoQ, or server IP (default: System)
    #[serde(default)]
    transport: Option<String>,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckHttpParams {
    /// URL to check (http:// or https://)
    url: String,
    /// Follow redirects (default: true)
    #[serde(default = "default_true")]
    follow_redirects: bool,
}

fn default_true() -> bool { true }

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckTlsChainParams {
    /// Hostname to inspect
    hostname: String,
    /// Port (default 443)
    #[serde(default)]
    port: Option<u16>,
    /// Check DANE/TLSA records
    #[serde(default)]
    check_dane: Option<bool>,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckEmailSecurityParams {
    /// Domain to check
    domain: String,
    /// Custom DKIM selectors to check (default: ["default", "google", "selector1", "selector2"])
    #[serde(default)]
    dkim_selectors: Option<Vec<String>>,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckMtaStsParams {
    /// Domain to check
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckPropagationGlobalParams {
    /// Domain to check
    domain: String,
    /// Record type to check (default: A)
    #[serde(default = "default_record_type")]
    record_type: String,
}

fn default_record_type() -> String { "A".to_string() }

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckPropagationParams {
    /// Domain to check
    domain: String,
    /// Record type to check
    #[serde(default = "default_record_type")]
    record_type: String,
    /// Resolvers (comma-separated IP addresses, optional)
    #[serde(default)]
    resolvers: Option<String>,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckDnssecParams {
    /// Domain to check
    domain: String,
    /// Record type (default: A)
    #[serde(default = "default_record_type")]
    record_type: String,
    /// Custom resolver IP (optional)
    #[serde(default)]
    resolver_ip: Option<String>,
    /// Verbose output
    #[serde(default)]
    verbose: bool,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct TraceResolutionParams {
    /// Domain to trace
    domain: String,
    /// Record type (default: A)
    #[serde(default = "default_record_type")]
    record_type: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckOcspParams {
    /// Hostname to check
    hostname: String,
    /// Port (default 443)
    #[serde(default = "default_port")]
    port: u16,
}

fn default_port() -> u16 { 443 }

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckStartTlsParams {
    /// Hostname to check
    hostname: String,
    /// Port (25 for SMTP, 143 for IMAP, 110 for POP3)
    port: u16,
    /// Protocol (Smtp, Imap, Pop3)
    protocol: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckDomainHealthParams {
    /// Domain to assess
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckCaaParams {
    /// Domain to check
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckBimiParams {
    /// Domain to check
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckCtParams {
    /// Hostname to check
    hostname: String,
    /// Port (default 443)
    #[serde(default = "default_port")]
    port: u16,
    /// Expected CAs for unexpected cert detection (optional)
    #[serde(default)]
    expected_cas: Option<Vec<String>>,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct BenchmarkLatencyParams {
    /// Domain to benchmark
    domain: String,
    /// Transports to test (comma-separated: System, DoH, DoT, DoQ, or IP address) (optional)
    #[serde(default)]
    transports: Option<String>,
    /// Record type to query (default: "A")
    #[serde(default)]
    record_type: Option<String>,
    /// Number of rounds to run (default: 3)
    #[serde(default)]
    rounds: Option<u32>,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckWhoisParams {
    /// Domain to check
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckSubdomainsParams {
    /// Domain to check for subdomains
    domain: String,
    /// Extra subdomains to check in addition to default list
    #[serde(default)]
    extra_subdomains: Option<Vec<String>>,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckPortsParams {
    /// Host to check ports on
    host: String,
    /// Custom ports to check (comma-separated, optional)
    #[serde(default)]
    ports: Option<String>,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckRdnsParams {
    /// IP address to check (IPv4 or IPv6)
    ip: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckDnsblParams {
    /// IP address to check against DNSBL services (IPv4 or IPv6)
    ip: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct DetectCdnParams {
    /// URL to check for CDN/WAF headers
    url: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckDelegationParams {
    /// Domain to audit
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckIpInfoParams {
    /// IP address to check (IPv4 or IPv6)
    ip: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckTlsVulnsParams {
    /// Hostname to check
    hostname: String,
    /// Port (default 443)
    #[serde(default)]
    port: Option<u16>,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckTlsRptParams {
    /// Domain to check
    domain: String,
    /// Validate DNSSEC (default: false)
    #[serde(default)]
    dnssec: Option<bool>,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckIpv6Params {
    /// Domain to check
    domain: String,
    /// Port to check (default 443)
    #[serde(default)]
    port: Option<u16>,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckArcParams {
    /// Domain to check ARC records for
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckCipherSuitesParams {
    /// Hostname to check
    hostname: String,
    /// Port (default 443)
    #[serde(default = "default_port")]
    port: u16,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckRpkiParams {
    /// IP address or CIDR prefix to check
    ip: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckDnsAmplificationParams {
    /// Domain to check
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckTracerouteParams {
    /// Host to trace route to
    host: String,
    /// Maximum hops (default 30)
    #[serde(default)]
    max_hops: Option<u32>,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckWildcardDnsParams {
    /// Domain to check for wildcard DNS
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckZoneTransferParams {
    /// Domain to attempt zone transfer on
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckIpNoiseParams {
    /// IP address to check
    ip: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckDomainRiskParams {
    /// Domain to assess for registration risk
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckTechStackParams {
    /// URL to check for technology fingerprints
    url: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckCveParams {
    /// Software/version keyword to search for (e.g. "Apache 2.4", "WordPress 6.5")
    keyword: String,
    /// Maximum number of results to return (default 10, max 20)
    #[serde(default)]
    max_results: Option<u32>,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckTyposquattingParams {
    /// Domain to check for typosquatting variants (e.g. "google.com")
    domain: String,
    /// Maximum mutations to generate (default 200, max 500)
    #[serde(default)]
    max_mutations: Option<u32>,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckRedirectChainParams {
    /// URL to trace redirects for
    url: String,
    /// Maximum hops to follow (default 20)
    #[serde(default)]
    max_hops: Option<u32>,
    /// Check domain age for each redirect hop (opt-in due to latency)
    #[serde(default)]
    check_domain_age: Option<bool>,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckParkedDomainParams {
    /// Domain to check for parking indicators
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckBrandImpersonationParams {
    /// Domain to check for brand impersonation
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckUrlReputationParams {
    /// URL to check against URLhaus malware/phishing database
    url: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckUrlAnalysisParams {
    /// URL to analyze for phishing and brand impersonation signals
    url: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckShodanIpParams {
    /// IP address to query (e.g. "8.8.8.8")
    ip: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckSshFingerprintParams {
    /// Host to connect to (e.g. "github.com")
    host: String,
    /// SSH port (default 22)
    #[serde(default)]
    port: Option<u16>,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckComplianceParams {
    /// Domain to assess
    domain: String,
    /// URL for HTTP/HTTPS checks (optional)
    #[serde(default)]
    url: Option<String>,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckBgpRouteParams {
    /// IP address to check (e.g. "8.8.8.8")
    ip: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckDnsHijackingParams {
    /// Domain to check
    domain: String,
    /// Record type (default "A")
    #[serde(default)]
    record_type: Option<String>,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckSpfDeepParams {
    /// Domain to analyze
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CheckThreatIntelParams {
    /// Domain or IP to check
    target: String,
    /// Specific sources to include (optional, default: all)
    #[serde(default)]
    include_sources: Option<Vec<String>>,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct ThreatIntelRiskScoreParams {
    /// Domain or IP to analyze
    target: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct PhishingDetectionParams {
    /// Domain to check for phishing indicators
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct MalwareSourcesParams {
    /// IP address to check
    ip: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct DomainTrustScoreParams {
    /// Domain to assess
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct IpTrustScoreParams {
    /// IP address to assess
    ip: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct SubdomainEnumerationParams {
    /// Domain to enumerate
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct WhoisEnrichmentParams {
    /// Domain to enrich
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct DnsThreatMappingParams {
    /// Domain to map threats for
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct DnsTakeoverRiskParams {
    /// Domain to assess for DNS takeover risk
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct SubdomainBruteforceParams {
    /// Domain to brute-force
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct TyposquatDetectionParams {
    /// Domain to check for typosquats
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct IpWhoisEnrichmentParams {
    /// IP address to enrich
    ip: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct DomainAgeTimelineParams {
    /// Domain to analyze
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CertificateHistoryParams {
    /// Domain to check certificate history
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct ThreatActorInfraParams {
    /// Domain to map threat infrastructure
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct DnsHistoryParams {
    /// Domain to analyze DNS history
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct IpGeolocationParams {
    /// IP address to geolocate
    ip: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct AsnLookupParams {
    /// IP address to look up ASN
    ip: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct WhoisPrivacyDetectionParams {
    /// Domain to check for WHOIS privacy
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct EmailSpoofingRiskParams {
    /// Domain to assess for email spoofing risk
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct TlsCertValidationParams {
    /// Domain to validate TLS certificate
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct InfrastructureOverlapParams {
    /// List of domains to check for infrastructure overlap
    domains: Vec<String>,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct TechStackFingerprintingParams {
    /// Domain to fingerprint technology stack
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct DomainReputationAnalysisParams {
    /// Domain to analyze reputation
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct PolicyDefinitionParams {
    /// Policy name
    policy_name: String,
    /// Policy type: blocklist | allowlist | rate_limit | approval_gate
    policy_type: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct DomainBlocklistParams {
    /// Domains to block
    domains: Vec<String>,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct IpBlocklistParams {
    /// IPs to block
    ips: Vec<String>,
    /// Threat level: low | medium | high | critical
    threat_level: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct AllowlistParams {
    /// Domains to whitelist
    domains: Vec<String>,
    /// Reason for allowlisting
    reason: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct RateLimitPolicyParams {
    /// User ID
    user_id: String,
    /// Requests per minute
    requests_per_minute: u32,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct ApprovalGateParams {
    /// Operation type
    operation: String,
    /// Requester name
    requester: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct AuditLogQueryParams {
    /// Number of days to query
    #[serde(default = "default_audit_days")]
    days: u32,
}

fn default_audit_days() -> u32 { 30 }

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct ComplianceReportParams {
    /// Compliance framework: SOC2 | ISO27001 | HIPAA | GDPR | PCI-DSS
    framework: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct ToolCallControlParams {
    /// Tool name to control
    tool_name: String,
    /// Comma-separated allowed user IDs
    #[serde(default)]
    allowed_users: Option<String>,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct RiskClassificationParams {
    /// Domain or IP to classify
    target: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct QuarantineParams {
    /// Targets to quarantine
    targets: Vec<String>,
    /// Reason for quarantine
    reason: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct PolicyViolationAlertParams {
    /// Domain causing violation
    domain: String,
    /// Violation type
    violation_type: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct DataResidencyComplianceParams {
    /// Domain to check
    domain: String,
    /// Required region: EU | US | APAC | CA
    required_region: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct EncryptionStatusParams {
    /// Domain to verify
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct PolicyExceptionParams {
    /// Target domain/IP
    target: String,
    /// Exception type: temporary | permanent
    exception_type: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct AuditTrailVerificationParams {
    /// Domain to verify
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct PolicyEffectivenessParams {
    /// Days to analyze
    #[serde(default = "default_effectiveness_days")]
    days: u32,
}

fn default_effectiveness_days() -> u32 { 30 }

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct IncidentResponsePlaybookParams {
    /// Incident type: data_breach | malware | ransomware | ddos
    incident_type: String,
    /// Severity: low | medium | high | critical
    #[serde(default = "default_severity")]
    severity: String,
}

fn default_severity() -> String { "high".to_string() }

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct SecurityPostureAssessmentParams {
    /// Domain to assess
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct BreachSimulationParams {
    /// Simulation type: phishing | credential_theft | data_exfil | lateral_movement
    simulation_type: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct PiiDetectionParams {
    /// Domain to scan for PII
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct PiiAnonymizationParams {
    /// Domain with PII to anonymize
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct DataRetentionPolicyParams {
    /// Domain for retention policy
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct GdprComplianceParams {
    /// Domain to assess
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct HipaaComplianceParams {
    /// Domain to assess
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct PciDssComplianceParams {
    /// Domain to assess
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct DataClassificationParams {
    /// Domain to classify
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct DataMaskingParams {
    /// Domain to mask
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct DataDeletionParams {
    /// Domain with data to delete
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct DataSubjectAccessParams {
    /// Domain for request
    domain: String,
    /// Subject identifier (email, phone, SSN)
    subject_identifier: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct ConsentManagementParams {
    /// Domain for consent
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CryptographicSignatureParams {
    /// Domain to sign
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct AuditTrailImmutabilityParams {
    /// Domain to verify
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct PrivacyImpactAssessmentParams {
    /// Domain to assess
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct PrivacyBreachNotificationParams {
    /// Domain affected
    domain: String,
    /// Number of affected records
    breach_scope: u32,
    /// Breach type: unauthorized_access | data_exfiltration | ransomware
    breach_type: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct Rfc3161TimestampParams {
    /// Document hash
    document_hash: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct TimestampValidationParams {
    /// Timestamp token
    timestamp_token: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct SignstoreRekorParams {
    /// Artifact hash
    artifact_hash: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct RekorVerificationParams {
    /// Entry UUID
    entry_uuid: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct ZkProofGenerationParams {
    /// Circuit type: merkle_proof | range_proof | authentication
    circuit_type: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct ZkProofVerificationParams {
    /// Proof
    proof: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct EscrowAgreementParams {
    /// Payer
    payer: String,
    /// Payee
    payee: String,
    /// Amount
    amount: u64,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct EscrowReleaseParams {
    /// Escrow ID
    escrow_id: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct DigitalNotarizationParams {
    /// Document hash
    document_hash: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct NotarizationVerificationParams {
    /// Notarization ID
    notarization_id: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct KeyManagementParams {
    /// Key type: RSA | ECDSA | EdDSA
    key_type: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct KeyRotationParams {
    /// Key ID to rotate
    key_id: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct AuditTrailBindingParams {
    /// Number of audit entries
    audit_entries: usize,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct HsmIntegrationParams {
    /// Operation type: sign | encrypt | decrypt | generate_key
    operation: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CryptographicComplianceParams {
    /// Domain to verify
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct UrlUnshortenParams {
    /// URL to unshorten
    url: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct Ja4hFingerprintParams {
    /// URL to fingerprint
    url: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct UrlSafetyMultiParams {
    /// URL to check
    url: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct UrlRedirectThreatParams {
    /// URL to check
    url: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct S3BucketExposureParams {
    /// Domain to check
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CloudProviderParams {
    /// Domain to check
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct ServerHardeningParams {
    /// URL to check
    url: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct DanglingDnsParams {
    /// Domain to check
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct UsernameOsintParams {
    /// Username to check
    username: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct EmailIntelParams {
    /// Email address to check
    email: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct OrganizationIntelParams {
    /// Domain to analyze
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct SocialMediaPresenceParams {
    /// Domain to check
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct AsnReputationParams {
    /// ASN (e.g., AS15169 or 15169)
    asn: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct BgpHijackHistoryParams {
    /// IP prefix (e.g., 8.8.8.0/24)
    prefix: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct NetworkExposureScoreParams {
    /// IP or domain to assess
    target: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CloudMetadataExposureParams {
    /// Domain to check
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct AzureBlobExposureParams {
    /// Domain to check
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct GcsBucketExposureParams {
    /// Domain to check
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CorsPolicyParams {
    /// URL to check
    url: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct SecurityTxtParams {
    /// Domain to check
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct JwtSecurityParams {
    /// JWT token to analyze
    token: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CookieSecurityParams {
    /// URL to check
    url: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CspAdvancedParams {
    /// URL to check
    url: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct ExposedFilesParams {
    /// Domain to check
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct NpmPackageSecurityParams {
    /// Package name to check
    package: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct PypiPackageSecurityParams {
    /// Package name to check
    package: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct DependencyConfusionParams {
    /// Internal package name to check
    internal_package: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct SbomDisclosureParams {
    /// Domain to check
    domain: String,
}

// ── Phase 9 Params ──────────────────────────────────────────────────────────

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct RobotsTxtParams {
    /// Domain to check (e.g. example.com)
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct WellKnownParams {
    /// Domain to check (e.g. example.com)
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct OauthOidcParams {
    /// Domain to check for OIDC configuration (e.g. example.com)
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct CertPinningParams {
    /// Domain to check for certificate pinning headers (e.g. example.com)
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct ApiExposureParams {
    /// Domain to scan for exposed API/debug endpoints (e.g. example.com)
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct ExposedDatabasesParams {
    /// Hostname or IP to probe for unauthenticated database access
    host: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct ContainerExposureParams {
    /// Hostname or IP to check for exposed Docker/Kubernetes APIs
    host: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct ServiceFingerprintParams {
    /// Hostname or IP to fingerprint
    host: String,
    /// Optional list of ports to probe (defaults to common service ports)
    #[serde(default)]
    ports: Option<Vec<u16>>,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct DgaRiskParams {
    /// Domain name to score for DGA risk (e.g. xn--abc123def.com)
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct SubdomainTakeoverParams {
    /// Apex domain to check for subdomain takeover (e.g. example.com)
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct PassiveDnsParams {
    /// Domain name or IP to query passive DNS for (e.g. example.com or 1.2.3.4)
    query: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct AzureAdExposureParams {
    /// Domain to check for Azure AD / Entra ID tenant exposure (e.g. example.com)
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct DkimKeyStrengthParams {
    /// Domain to check DKIM key strength (e.g. example.com)
    domain: String,
    /// Optional list of DKIM selectors to check (defaults to common selectors)
    #[serde(default)]
    selectors: Option<Vec<String>>,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct MxSecurityParams {
    /// Domain to check MX server security (e.g. example.com)
    domain: String,
}

#[derive(Deserialize, schemars::JsonSchema, Clone)]
struct AttackSurfaceParams {
    /// Domain to map attack surface for (e.g. example.com)
    domain: String,
}

#[derive(Clone)]
struct ShoheiServer;

#[tool_router(server_handler)]
impl ShoheiServer {
    #[tool(description = "Check DNS records for a domain")]
    async fn check_dns(
        &self,
        Parameters(CheckDnsParams { domain, record_types, transport }): Parameters<CheckDnsParams>,
    ) -> String {
        let transport_enum = match transport.as_deref() {
            Some("doh") | Some("doh-cloudflare") => Transport::Doh("https://1.1.1.1/dns-query".to_string()),
            Some("dot") | Some("dot-cloudflare") => Transport::Dot("1.1.1.1:853".to_string()),
            Some("doq") | Some("doq-cloudflare") => Transport::Doq("1.1.1.1:853".to_string()),
            Some(addr) => Transport::Server(addr.to_string()),
            None => Transport::System,
        };

        let req = DnsCheckRequest {
            domain,
            record_types: record_types.unwrap_or_else(|| vec!["A".to_string()]),
            transport: transport_enum,
            ..Default::default()
        };
        match shohei::api::check_dns(&req).await {
            Ok(results) => serde_json::to_string_pretty(&results).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check HTTP(S) endpoint reachability and headers")]
    async fn check_http(
        &self,
        Parameters(CheckHttpParams { url, follow_redirects }): Parameters<CheckHttpParams>,
    ) -> String {
        let req = HttpCheckRequest {
            url,
            follow_redirects,
            timeout_secs: 10,
        };
        match shohei::api::check_http(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Inspect TLS certificate chain for a hostname")]
    async fn check_tls_chain(
        &self,
        Parameters(CheckTlsChainParams {
            hostname,
            port,
            check_dane,
        }): Parameters<CheckTlsChainParams>,
    ) -> String {
        let req = TlsCheckRequest {
            hostname,
            port: port.unwrap_or(443),
            check_dane: check_dane.unwrap_or(false),
            timeout_secs: 10,
        };
        match shohei::api::check_tls_chain(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check email security (MX, SPF, DKIM, DMARC)")]
    async fn check_email_security(
        &self,
        Parameters(CheckEmailSecurityParams { domain, dkim_selectors }): Parameters<CheckEmailSecurityParams>,
    ) -> String {
        let req = EmailSecurityRequest {
            domain,
            timeout_secs: 5,
            dkim_selectors: dkim_selectors.unwrap_or_else(|| vec![
                "default".to_string(),
                "google".to_string(),
                "selector1".to_string(),
                "selector2".to_string(),
            ]),
        };
        match shohei::api::check_email_security(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check MTA-STS policy for SMTP TLS enforcement")]
    async fn check_mta_sts(
        &self,
        Parameters(CheckMtaStsParams { domain }): Parameters<CheckMtaStsParams>,
    ) -> String {
        let req = MtaStsRequest {
            domain,
            timeout_secs: 5,
        };
        match shohei::api::check_mta_sts(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check OCSP revocation status for a certificate")]
    async fn check_ocsp(
        &self,
        Parameters(CheckOcspParams { hostname, port }): Parameters<CheckOcspParams>,
    ) -> String {
        let req = OcspCheckRequest {
            hostname,
            port,
            ocsp_responder_url: None,
            timeout_secs: 10,
        };
        match shohei::api::check_ocsp(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check STARTTLS capability for SMTP/IMAP/POP3")]
    async fn check_starttls(
        &self,
        Parameters(CheckStartTlsParams { hostname, port, protocol }): Parameters<CheckStartTlsParams>,
    ) -> String {
        let proto = match protocol.to_lowercase().as_str() {
            "smtp" => StartTlsProtocol::Smtp,
            "imap" => StartTlsProtocol::Imap,
            "pop3" => StartTlsProtocol::Pop3,
            _ => return serde_json::json!({"error": format!("unknown protocol {}", protocol)}).to_string(),
        };

        let req = StartTlsCheckRequest {
            hostname,
            port,
            protocol: proto,
            timeout_secs: 10,
        };
        match shohei::api::check_starttls(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Comprehensive domain health assessment")]
    async fn check_domain_health(
        &self,
        Parameters(CheckDomainHealthParams { domain }): Parameters<CheckDomainHealthParams>,
    ) -> String {
        let req = DomainHealthRequest {
            domain,
            timeout_secs: 10,
        };
        match shohei::api::check_domain_health(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check CAA records for certificate issuance authorization")]
    async fn check_caa(
        &self,
        Parameters(CheckCaaParams { domain }): Parameters<CheckCaaParams>,
    ) -> String {
        let req = CaaCheckRequest {
            domain,
            issued_by_ca: None,
            timeout_secs: 5,
        };
        match shohei::api::check_caa(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check BIMI configuration for brand protection")]
    async fn check_bimi(
        &self,
        Parameters(CheckBimiParams { domain }): Parameters<CheckBimiParams>,
    ) -> String {
        let req = BimiCheckRequest {
            domain,
            timeout_secs: 5,
        };
        match shohei::api::check_bimi(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check Certificate Transparency logs")]
    async fn check_ct(
        &self,
        Parameters(CheckCtParams { hostname, port, expected_cas }): Parameters<CheckCtParams>,
    ) -> String {
        let req = CtCheckRequest {
            hostname,
            port,
            timeout_secs: 10,
            expected_cas,
        };
        match shohei::api::check_ct(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check DNS propagation across 6 global resolvers")]
    async fn check_propagation_global(
        &self,
        Parameters(CheckPropagationGlobalParams { domain, record_type }): Parameters<
            CheckPropagationGlobalParams,
        >,
    ) -> String {
        let req = PropagationRequest {
            domain: domain.clone(),
            record_type,
            resolvers: vec![
                PropagationResolver { name: "Google".to_string(), address: "8.8.8.8".to_string(), region: None },
                PropagationResolver { name: "Cloudflare".to_string(), address: "1.1.1.1".to_string(), region: None },
                PropagationResolver { name: "Quad9".to_string(), address: "9.9.9.9".to_string(), region: None },
                PropagationResolver { name: "OpenDNS".to_string(), address: "208.67.222.222".to_string(), region: None },
                PropagationResolver { name: "CleanBrowsing".to_string(), address: "185.228.168.168".to_string(), region: None },
                PropagationResolver { name: "Comodo".to_string(), address: "8.26.56.26".to_string(), region: None },
            ],
            timeout_secs: 5,
        };
        match shohei::api::check_propagation(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check DNS propagation across custom resolvers (default: 6 global resolvers)")]
    async fn check_propagation(
        &self,
        Parameters(CheckPropagationParams { domain, record_type, resolvers }): Parameters<
            CheckPropagationParams,
        >,
    ) -> String {
        let resolver_list = if let Some(resolver_str) = resolvers {
            let mut list = Vec::new();
            for (idx, addr) in resolver_str.split(',').enumerate() {
                let addr = addr.trim().to_string();
                list.push(PropagationResolver {
                    name: format!("Resolver{}", idx + 1),
                    address: addr,
                    region: None,
                });
            }
            list
        } else {
            // Default: 6 global resolvers (same as check_propagation_global)
            vec![
                PropagationResolver { name: "Google".to_string(), address: "8.8.8.8".to_string(), region: None },
                PropagationResolver { name: "Cloudflare".to_string(), address: "1.1.1.1".to_string(), region: None },
                PropagationResolver { name: "Quad9".to_string(), address: "9.9.9.9".to_string(), region: None },
                PropagationResolver { name: "OpenDNS".to_string(), address: "208.67.222.222".to_string(), region: None },
                PropagationResolver { name: "CleanBrowsing".to_string(), address: "185.228.168.168".to_string(), region: None },
                PropagationResolver { name: "Comodo".to_string(), address: "8.26.56.26".to_string(), region: None },
            ]
        };

        let req = PropagationRequest {
            domain,
            record_type,
            resolvers: resolver_list,
            timeout_secs: 5,
        };
        match shohei::api::check_propagation(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Validate DNSSEC chain of trust")]
    async fn check_dnssec(
        &self,
        Parameters(CheckDnssecParams { domain, record_type, resolver_ip, verbose }): Parameters<
            CheckDnssecParams,
        >,
    ) -> String {
        let req = DnssecCheckRequest {
            domain,
            record_type,
            resolver_ip,
            verbose,
        };
        match shohei::api::check_dnssec(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Trace DNS resolution path from root to authoritative")]
    async fn trace_resolution(
        &self,
        Parameters(TraceResolutionParams { domain, record_type }): Parameters<
            TraceResolutionParams,
        >,
    ) -> String {
        match shohei::api::trace_resolution(&domain, &record_type).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Benchmark DNS latency across transports")]
    async fn benchmark_latency(
        &self,
        Parameters(BenchmarkLatencyParams { domain, transports, record_type, rounds }): Parameters<
            BenchmarkLatencyParams,
        >,
    ) -> String {
        let mut bench_transports = vec![
            BenchTransport {
                transport: Transport::System,
                label: "System".to_string(),
            },
            BenchTransport {
                transport: Transport::Doh("https://1.1.1.1/dns-query".to_string()),
                label: "DoH-Cloudflare".to_string(),
            },
        ];

        if let Some(transport_str) = transports {
            bench_transports.clear();
            for (idx, t) in transport_str.split(',').enumerate() {
                let t = t.trim();
                let (transport, label) = match t.to_lowercase().as_str() {
                    "system" => (Transport::System, "System".to_string()),
                    "doh" | "doh-cloudflare" => (
                        Transport::Doh("https://1.1.1.1/dns-query".to_string()),
                        "DoH-Cloudflare".to_string(),
                    ),
                    "dot" | "dot-cloudflare" => (
                        Transport::Dot("1.1.1.1:853".to_string()),
                        "DoT-Cloudflare".to_string(),
                    ),
                    "doq" | "doq-cloudflare" => (
                        Transport::Doq("1.1.1.1:853".to_string()),
                        "DoQ-Cloudflare".to_string(),
                    ),
                    addr => {
                        (Transport::Server(addr.to_string()), format!("Server{}", idx + 1))
                    }
                };
                bench_transports.push(BenchTransport { transport, label });
            }
        }

        let req = LatencyBenchRequest {
            domain,
            record_type: record_type.unwrap_or_else(|| "A".to_string()),
            transports: bench_transports,
            rounds: rounds.unwrap_or(3),
            timeout_secs: 5,
        };
        match shohei::api::benchmark_latency(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check domain registration details and expiration")]
    async fn check_whois(
        &self,
        Parameters(CheckWhoisParams { domain }): Parameters<CheckWhoisParams>,
    ) -> String {
        let req = WhoisCheckRequest {
            domain,
            timeout_secs: 10,
        };
        match shohei::api::check_whois(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check common subdomains for DNS/HTTP/TLS validity")]
    async fn check_subdomains(
        &self,
        Parameters(CheckSubdomainsParams { domain, extra_subdomains }): Parameters<CheckSubdomainsParams>,
    ) -> String {
        let req = SubdomainCheckRequest {
            domain,
            timeout_secs: 10,
            extra_subdomains,
        };
        match shohei::api::check_common_subdomains(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check port reachability and service detection")]
    async fn check_ports(
        &self,
        Parameters(CheckPortsParams { host, ports }): Parameters<CheckPortsParams>,
    ) -> String {
        let port_list = ports.as_ref().and_then(|p| {
            let parsed: Result<Vec<u16>, _> = p.split(',')
                .map(|s| s.trim().parse::<u16>())
                .collect();
            parsed.ok()
        });

        let req = PortCheckRequest {
            host,
            ports: port_list,
            timeout_secs: 5,
        };
        match shohei::api::check_ports(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check reverse DNS and forward-confirmed reverse DNS (FCrDNS)")]
    async fn check_rdns(
        &self,
        Parameters(CheckRdnsParams { ip }): Parameters<CheckRdnsParams>,
    ) -> String {
        let req = RdnsCheckRequest {
            ip,
            timeout_secs: 10,
        };
        match shohei::api::check_rdns(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check IP reputation against DNSBL services")]
    async fn check_dnsbl(
        &self,
        Parameters(CheckDnsblParams { ip }): Parameters<CheckDnsblParams>,
    ) -> String {
        let req = DnsblCheckRequest {
            ip,
            timeout_secs: 10,
        };
        match shohei::api::check_dnsbl(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Detect CDN and WAF providers via HTTP headers")]
    async fn detect_cdn(
        &self,
        Parameters(DetectCdnParams { url }): Parameters<DetectCdnParams>,
    ) -> String {
        let req = CdnDetectRequest {
            url,
            timeout_secs: 10,
        };
        match shohei::api::detect_cdn(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check DNS delegation consistency (SOA serials, NS reachability)")]
    async fn check_delegation(
        &self,
        Parameters(CheckDelegationParams { domain }): Parameters<CheckDelegationParams>,
    ) -> String {
        let req = DelegationCheckRequest {
            domain,
            timeout_secs: 10,
        };
        match shohei::api::check_delegation(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check IP information (ASN, geolocation, organization)")]
    async fn check_ip_info(
        &self,
        Parameters(CheckIpInfoParams { ip }): Parameters<CheckIpInfoParams>,
    ) -> String {
        let req = IpInfoCheckRequest {
            ip,
            timeout_secs: 10,
        };
        match shohei::api::check_ip_info(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check TLS protocol vulnerabilities (TLS 1.0/1.1/1.2/1.3 support, forward secrecy)")]
    async fn check_tls_vulns(
        &self,
        Parameters(CheckTlsVulnsParams { hostname, port }): Parameters<CheckTlsVulnsParams>,
    ) -> String {
        let req = TlsVulnCheckRequest {
            hostname,
            port: port.unwrap_or(443),
            timeout_secs: 10,
        };
        match shohei::api::check_tls_vulns(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check TLS-RPT (SMTP TLS Reporting Policy) record")]
    async fn check_tls_rpt(
        &self,
        Parameters(CheckTlsRptParams { domain, dnssec }): Parameters<CheckTlsRptParams>,
    ) -> String {
        let req = TlsRptRequest {
            domain,
            dnssec: dnssec.unwrap_or(false),
            timeout_secs: 10,
        };
        match shohei::api::check_tls_rpt(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check IPv6 dual-stack support (DNS AAAA, TCP, TLS, HTTP)")]
    async fn check_ipv6(
        &self,
        Parameters(CheckIpv6Params { domain, port }): Parameters<CheckIpv6Params>,
    ) -> String {
        let req = Ipv6CheckRequest {
            domain,
            port: port.unwrap_or(443),
            timeout_secs: 10,
        };
        match shohei::api::check_ipv6(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check ARC (Authenticated Received Chain) records for a domain")]
    async fn check_arc(
        &self,
        Parameters(CheckArcParams { domain }): Parameters<CheckArcParams>,
    ) -> String {
        let req = ArcCheckRequest {
            domain,
            timeout_secs: 10,
        };
        match shohei::api::check_arc(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check supported TLS cipher suites for a hostname")]
    async fn check_cipher_suites(
        &self,
        Parameters(CheckCipherSuitesParams { hostname, port }): Parameters<CheckCipherSuitesParams>,
    ) -> String {
        let req = CipherSuitesRequest {
            hostname,
            port,
            timeout_secs: 10,
            probe_weak: false,
        };
        match shohei::api::check_cipher_suites(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check RPKI (Resource Public Key Infrastructure) validity for an IP prefix")]
    async fn check_rpki(
        &self,
        Parameters(CheckRpkiParams { ip }): Parameters<CheckRpkiParams>,
    ) -> String {
        let req = RpkiCheckRequest { ip };
        match shohei::api::check_rpki(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check DNS amplification risk (query/response size ratio)")]
    async fn check_dns_amplification(
        &self,
        Parameters(CheckDnsAmplificationParams { domain }): Parameters<CheckDnsAmplificationParams>,
    ) -> String {
        let req = DnsAmplificationRequest {
            nameserver: "8.8.8.8".to_string(),
            port: 53,
            domain,
            timeout_secs: 10,
        };
        match shohei::api::check_dns_amplification(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Trace route to a host using ICMP echo requests")]
    async fn check_traceroute(
        &self,
        Parameters(CheckTracerouteParams { host, max_hops }): Parameters<CheckTracerouteParams>,
    ) -> String {
        let req = TracerouteRequest {
            hostname: host,
            max_hops: max_hops.unwrap_or(30),
            timeout_secs: 30,
        };
        match shohei::api::check_traceroute(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check for wildcard DNS records that could mask domain enumeration")]
    async fn check_wildcard_dns(
        &self,
        Parameters(CheckWildcardDnsParams { domain }): Parameters<CheckWildcardDnsParams>,
    ) -> String {
        let req = WildcardDnsRequest {
            domain,
            timeout_secs: 10,
        };
        match shohei::api::check_wildcard_dns(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Attempt DNS zone transfer (AXFR) against authoritative nameservers")]
    async fn check_zone_transfer(
        &self,
        Parameters(CheckZoneTransferParams { domain }): Parameters<CheckZoneTransferParams>,
    ) -> String {
        let req = shohei::api::zone_transfer::ZoneTransferRequest {
            domain,
            timeout_secs: 10,
        };
        match shohei::api::zone_transfer::check_zone_transfer(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Classify IP address using GreyNoise community API (no API key required)")]
    async fn check_ip_noise(
        &self,
        Parameters(CheckIpNoiseParams { ip }): Parameters<CheckIpNoiseParams>,
    ) -> String {
        let req = shohei::api::greynoise::GreyNoiseRequest {
            ip,
            timeout_secs: 10,
        };
        match shohei::api::greynoise::check_ip_noise(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Evaluate domain registration risk for phishing and squatting")]
    async fn check_domain_risk(
        &self,
        Parameters(CheckDomainRiskParams { domain }): Parameters<CheckDomainRiskParams>,
    ) -> String {
        let req = shohei::api::domain_risk::DomainRiskRequest {
            domain,
            timeout_secs: 10,
        };
        match shohei::api::domain_risk::check_domain_risk(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Identify web technologies (web server, language, CMS, frameworks)")]
    async fn check_tech_stack(
        &self,
        Parameters(CheckTechStackParams { url }): Parameters<CheckTechStackParams>,
    ) -> String {
        let req = shohei::api::TechFingerprintRequest {
            url,
            timeout_secs: 10,
        };
        match shohei::api::check_tech_stack(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Search for known CVEs in the NVD database (no API key required)")]
    async fn check_cve(
        &self,
        Parameters(CheckCveParams { keyword, max_results }): Parameters<CheckCveParams>,
    ) -> String {
        let req = shohei::api::CveLookupRequest {
            keyword,
            max_results: max_results.unwrap_or(10),
            timeout_secs: 10,
        };
        match shohei::api::check_cve(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Detect typosquatting variants of a domain")]
    async fn check_typosquatting(
        &self,
        Parameters(CheckTyposquattingParams { domain, max_mutations }): Parameters<CheckTyposquattingParams>,
    ) -> String {
        let req = shohei::api::TyposquatRequest {
            domain,
            timeout_secs: 10,
            max_mutations: max_mutations.unwrap_or(200),
        };
        match shohei::api::check_typosquatting(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Trace HTTP redirect chain from a URL")]
    async fn check_redirect_chain(
        &self,
        Parameters(CheckRedirectChainParams { url, max_hops, check_domain_age }): Parameters<CheckRedirectChainParams>,
    ) -> String {
        let req = shohei::api::RedirectChainRequest {
            url,
            timeout_secs: 10,
            max_hops: max_hops.unwrap_or(20),
            check_domain_age: check_domain_age.unwrap_or(false),
        };
        match shohei::api::check_redirect_chain(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check if a domain is parked for sale")]
    async fn check_parked_domain(
        &self,
        Parameters(CheckParkedDomainParams { domain }): Parameters<CheckParkedDomainParams>,
    ) -> String {
        let req = shohei::api::ParkedDomainRequest {
            domain,
            timeout_secs: 10,
        };
        match shohei::api::check_parked_domain(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check if a domain impersonates known brands")]
    async fn check_brand_impersonation(
        &self,
        Parameters(CheckBrandImpersonationParams { domain }): Parameters<CheckBrandImpersonationParams>,
    ) -> String {
        let req = shohei::api::BrandImpersonationRequest {
            domain,
            timeout_secs: 10,
        };
        match shohei::api::check_brand_impersonation(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check URL against URLhaus malware/phishing database (no API key required)")]
    async fn check_url_reputation(
        &self,
        Parameters(CheckUrlReputationParams { url }): Parameters<CheckUrlReputationParams>,
    ) -> String {
        let req = shohei::api::UrlhausRequest {
            url,
            timeout_secs: 10,
        };
        match shohei::api::check_url_reputation(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Analyze URL structure for phishing and brand impersonation signals")]
    async fn check_url_analysis(
        &self,
        Parameters(CheckUrlAnalysisParams { url }): Parameters<CheckUrlAnalysisParams>,
    ) -> String {
        let req = shohei::api::UrlAnalysisRequest { url };
        match shohei::api::check_url_analysis(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Query Shodan InternetDB for open ports, CPEs, tags, and CVE associations (no API key required)")]
    async fn check_shodan_ip(
        &self,
        Parameters(CheckShodanIpParams { ip }): Parameters<CheckShodanIpParams>,
    ) -> String {
        let req = shohei::api::ShodanInternetDbRequest {
            ip,
            timeout_secs: 10,
        };
        match shohei::api::check_shodan_ip(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Compute HASSH SSH fingerprint from server KEXINIT packet")]
    async fn check_ssh_fingerprint(
        &self,
        Parameters(CheckSshFingerprintParams { host, port }): Parameters<CheckSshFingerprintParams>,
    ) -> String {
        let req = shohei::api::SshFingerprintRequest {
            host,
            port: port.unwrap_or(22),
            timeout_secs: 10,
        };
        match shohei::api::check_ssh_fingerprint(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Assess domain compliance against CIS, PCI-DSS, HIPAA, and OWASP controls")]
    async fn check_compliance(
        &self,
        Parameters(CheckComplianceParams { domain, url }): Parameters<CheckComplianceParams>,
    ) -> String {
        let req = shohei::api::ComplianceRequest {
            domain,
            url,
            timeout_secs: 15,
        };
        match shohei::api::check_compliance(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Query RIPE STAT for BGP route, AS name, prefix visibility, and routing status (no API key required)")]
    async fn check_bgp_route(
        &self,
        Parameters(CheckBgpRouteParams { ip }): Parameters<CheckBgpRouteParams>,
    ) -> String {
        let req = shohei::api::BgpRouteRequest {
            ip,
            timeout_secs: 10,
        };
        match shohei::api::check_bgp_route(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Compare authoritative DNS answers vs public resolvers to detect DNS hijacking, cache poisoning, or split-horizon configuration")]
    async fn check_dns_hijacking(
        &self,
        Parameters(CheckDnsHijackingParams { domain, record_type }): Parameters<CheckDnsHijackingParams>,
    ) -> String {
        let req = shohei::api::DnsHijackingRequest {
            domain,
            record_type: record_type.unwrap_or_else(|| "A".to_string()),
            timeout_secs: 10,
        };
        match shohei::api::check_dns_hijacking(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Recursively resolve SPF include chains and count total DNS lookups against RFC 7208 limit of 10 (no API key required)")]
    async fn check_spf_deep(
        &self,
        Parameters(CheckSpfDeepParams { domain }): Parameters<CheckSpfDeepParams>,
    ) -> String {
        let req = shohei::api::SpfAnalysisRequest {
            domain,
            timeout_secs: 10,
        };
        match shohei::api::check_spf_deep(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Aggregate threat intelligence from 5+ sources (GreyNoise, Shodan, URLhaus, Brand Impersonation, CT) with unified risk scoring")]
    async fn check_threat_intel_aggregate(
        &self,
        Parameters(CheckThreatIntelParams { target, include_sources }): Parameters<CheckThreatIntelParams>,
    ) -> String {
        let req = shohei::api::ThreatIntelRequest {
            target,
            include_sources,
            timeout_secs: 30,
        };
        match shohei::api::check_threat_intel_aggregate(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Get detailed risk score breakdown (0-100) with per-source confidence and actionable recommendation")]
    async fn threat_intel_risk_score(
        &self,
        Parameters(ThreatIntelRiskScoreParams { target }): Parameters<ThreatIntelRiskScoreParams>,
    ) -> String {
        match shohei::api::threat_intel_risk_score(&target).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Detect phishing indicators (brand impersonation, suspicious URLs, new domain registration) with phishing score")]
    async fn phishing_detection_aggregate(
        &self,
        Parameters(PhishingDetectionParams { domain }): Parameters<PhishingDetectionParams>,
    ) -> String {
        match shohei::api::phishing_detection_aggregate(&domain, 30).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "List all threat intelligence sources that flagged an IP as malicious with confidence levels")]
    async fn malware_detected_sources(
        &self,
        Parameters(MalwareSourcesParams { ip }): Parameters<MalwareSourcesParams>,
    ) -> String {
        match shohei::api::malware_detected_sources(&ip, 30).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Calculate 5-dimensional domain trust score (0-100): DNS consistency, TLS validity, threat reputation, registration age, infrastructure maturity")]
    async fn check_domain_trust_score(
        &self,
        Parameters(DomainTrustScoreParams { domain }): Parameters<DomainTrustScoreParams>,
    ) -> String {
        let req = shohei::api::DomainTrustScoreRequest {
            domain,
            timeout_secs: 30,
        };
        match shohei::api::check_domain_trust_score(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Calculate 5-dimensional IP trust score (0-100): reverse DNS, TLS presence, threat reputation, BGP status, RPKI validity")]
    async fn check_ip_trust_score(
        &self,
        Parameters(IpTrustScoreParams { ip }): Parameters<IpTrustScoreParams>,
    ) -> String {
        let req = shohei::api::IpTrustScoreRequest {
            ip,
            timeout_secs: 30,
        };
        match shohei::api::check_ip_trust_score(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Enumerate subdomains via Certificate Transparency, WHOIS nameservers, and DNS resolution")]
    async fn enumerate_subdomains(
        &self,
        Parameters(SubdomainEnumerationParams { domain }): Parameters<SubdomainEnumerationParams>,
    ) -> String {
        let req = shohei::api::SubdomainEnumerationRequest {
            domain,
            timeout_secs: 30,
        };
        match shohei::api::enumerate_subdomains(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Enrich WHOIS data with registration details, nameservers, and DNSSEC status")]
    async fn enrich_whois(
        &self,
        Parameters(WhoisEnrichmentParams { domain }): Parameters<WhoisEnrichmentParams>,
    ) -> String {
        let req = shohei::api::WhoisEnrichmentRequest {
            domain,
            timeout_secs: 30,
        };
        match shohei::api::enrich_whois(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Map DNS domain to threat sources (GreyNoise, Shodan, URLhaus, etc.) with risk scoring")]
    async fn map_dns_threats(
        &self,
        Parameters(DnsThreatMappingParams { domain }): Parameters<DnsThreatMappingParams>,
    ) -> String {
        let req = shohei::api::DnsThreatMappingRequest {
            domain,
            timeout_secs: 30,
        };
        match shohei::api::map_dns_threats(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Assess DNS takeover risk by checking nameserver redundancy, responsiveness, and dangling records")]
    async fn assess_dns_takeover_risk(
        &self,
        Parameters(DnsTakeoverRiskParams { domain }): Parameters<DnsTakeoverRiskParams>,
    ) -> String {
        let req = shohei::api::DnsTakeoverRiskRequest {
            domain,
            timeout_secs: 30,
        };
        match shohei::api::assess_dns_takeover_risk(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Brute-force common subdomain prefixes (www, mail, api, admin, staging, etc.)")]
    async fn bruteforce_subdomains(
        &self,
        Parameters(SubdomainBruteforceParams { domain }): Parameters<SubdomainBruteforceParams>,
    ) -> String {
        let req = shohei::api::SubdomainBruteforceRequest {
            domain,
            timeout_secs: 30,
        };
        match shohei::api::bruteforce_subdomains(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Detect typosquat domain variants (character omission, swaps, vowel substitution)")]
    async fn detect_typosquats(
        &self,
        Parameters(TyposquatDetectionParams { domain }): Parameters<TyposquatDetectionParams>,
    ) -> String {
        let req = shohei::api::TyposquatDetectionRequest {
            domain,
            timeout_secs: 30,
        };
        match shohei::api::detect_typosquats(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Enrich IP address with WHOIS, BGP, and ASN information")]
    async fn enrich_ip_whois(
        &self,
        Parameters(IpWhoisEnrichmentParams { ip }): Parameters<IpWhoisEnrichmentParams>,
    ) -> String {
        let req = shohei::api::IpWhoisEnrichmentRequest {
            ip,
            timeout_secs: 30,
        };
        match shohei::api::enrich_ip_whois(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Analyze domain age and registration timeline (new/young/established/legacy)")]
    async fn analyze_domain_age(
        &self,
        Parameters(DomainAgeTimelineParams { domain }): Parameters<DomainAgeTimelineParams>,
    ) -> String {
        let req = shohei::api::DomainAgeTimelineRequest {
            domain,
            timeout_secs: 30,
        };
        match shohei::api::analyze_domain_age(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Retrieve domain certificate history from Certificate Transparency logs")]
    async fn get_certificate_history(
        &self,
        Parameters(CertificateHistoryParams { domain }): Parameters<CertificateHistoryParams>,
    ) -> String {
        let req = shohei::api::CertificateHistoryRequest {
            domain,
            timeout_secs: 30,
        };
        match shohei::api::get_certificate_history(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Map threat actor infrastructure (IPs, nameservers, ASNs) and threat scoring")]
    async fn map_threat_actor_infra(
        &self,
        Parameters(ThreatActorInfraParams { domain }): Parameters<ThreatActorInfraParams>,
    ) -> String {
        let req = shohei::api::ThreatActorInfraRequest {
            domain,
            timeout_secs: 30,
        };
        match shohei::api::map_threat_actor_infra(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Analyze current DNS configuration as historical snapshot for forensics")]
    async fn analyze_dns_history(
        &self,
        Parameters(DnsHistoryParams { domain }): Parameters<DnsHistoryParams>,
    ) -> String {
        let req = shohei::api::DnsHistoryRequest {
            domain,
            timeout_secs: 30,
        };
        match shohei::api::analyze_dns_history(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Get IP geolocation: country, region, city, coordinates, timezone, ISP")]
    async fn get_ip_geolocation(
        &self,
        Parameters(IpGeolocationParams { ip }): Parameters<IpGeolocationParams>,
    ) -> String {
        let req = shohei::api::IpGeolocationRequest {
            ip,
            timeout_secs: 30,
        };
        match shohei::api::get_ip_geolocation(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Look up ASN (Autonomous System Number) and organization for IP address")]
    async fn lookup_asn(
        &self,
        Parameters(AsnLookupParams { ip }): Parameters<AsnLookupParams>,
    ) -> String {
        let req = shohei::api::AsnLookupRequest {
            ip,
            timeout_secs: 30,
        };
        match shohei::api::lookup_asn(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Detect WHOIS privacy protection (redacted/anonymized registrant information)")]
    async fn detect_whois_privacy(
        &self,
        Parameters(WhoisPrivacyDetectionParams { domain }): Parameters<WhoisPrivacyDetectionParams>,
    ) -> String {
        let req = shohei::api::WhoisPrivacyDetectionRequest {
            domain,
            timeout_secs: 30,
        };
        match shohei::api::detect_whois_privacy(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Assess email spoofing risk (SPF/DKIM/DMARC configuration analysis)")]
    async fn assess_email_spoofing_risk(
        &self,
        Parameters(EmailSpoofingRiskParams { domain }): Parameters<EmailSpoofingRiskParams>,
    ) -> String {
        let req = shohei::api::EmailSpoofingRiskRequest {
            domain,
            timeout_secs: 30,
        };
        match shohei::api::assess_email_spoofing_risk(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Validate TLS certificate: issuer, signature algorithm, expiry, trust level")]
    async fn validate_tls_cert(
        &self,
        Parameters(TlsCertValidationParams { domain }): Parameters<TlsCertValidationParams>,
    ) -> String {
        let req = shohei::api::TlsCertValidationRequest {
            domain,
            timeout_secs: 30,
        };
        match shohei::api::validate_tls_cert(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Detect infrastructure overlap between multiple domains (shared IPs, nameservers, ASNs)")]
    async fn detect_infrastructure_overlap(
        &self,
        Parameters(InfrastructureOverlapParams { domains }): Parameters<InfrastructureOverlapParams>,
    ) -> String {
        let req = shohei::api::InfrastructureOverlapRequest {
            domains,
            timeout_secs: 30,
        };
        match shohei::api::detect_infrastructure_overlap(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Fingerprint domain technology stack (web servers, frameworks, languages, tools)")]
    async fn fingerprint_tech_stack(
        &self,
        Parameters(TechStackFingerprintingParams { domain }): Parameters<TechStackFingerprintingParams>,
    ) -> String {
        let req = shohei::api::TechStackFingerprintingRequest {
            domain,
            timeout_secs: 30,
        };
        match shohei::api::fingerprint_tech_stack(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Analyze domain reputation: trust score, health, threats, age, email security")]
    async fn analyze_domain_reputation(
        &self,
        Parameters(DomainReputationAnalysisParams { domain }): Parameters<DomainReputationAnalysisParams>,
    ) -> String {
        let req = shohei::api::DomainReputationAnalysisRequest {
            domain,
            timeout_secs: 30,
        };
        match shohei::api::analyze_domain_reputation(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Define governance policy (blocklist, allowlist, rate limit, approval gate)")]
    async fn define_policy(
        &self,
        Parameters(PolicyDefinitionParams { policy_name, policy_type }): Parameters<PolicyDefinitionParams>,
    ) -> String {
        let req = shohei::api::PolicyDefinitionRequest {
            policy_name,
            policy_type,
            rules: Vec::new(),
            enabled: true,
        };
        match shohei::api::define_policy(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Add domains to blocklist (malicious, phishing, spam, malware)")]
    async fn add_domain_blocklist(
        &self,
        Parameters(DomainBlocklistParams { domains }): Parameters<DomainBlocklistParams>,
    ) -> String {
        let req = shohei::api::DomainBlocklistRequest {
            domains,
            reason: None,
            expires_at: None,
        };
        match shohei::api::add_domain_blocklist(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Add IPs to reputation blocklist with threat level classification")]
    async fn add_ip_blocklist(
        &self,
        Parameters(IpBlocklistParams { ips, threat_level }): Parameters<IpBlocklistParams>,
    ) -> String {
        let req = shohei::api::IpReputationBlocklistRequest {
            ips,
            threat_level,
            reason: None,
        };
        match shohei::api::add_ip_blocklist(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Add domains to allowlist (trusted, verified partners)")]
    async fn add_allowlist(
        &self,
        Parameters(AllowlistParams { domains, reason }): Parameters<AllowlistParams>,
    ) -> String {
        let req = shohei::api::AllowlistRequest {
            domains,
            reason,
            trusted_until: None,
        };
        match shohei::api::add_allowlist(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Set rate limit policy for user (requests per minute/hour/day)")]
    async fn set_rate_limit_policy(
        &self,
        Parameters(RateLimitPolicyParams { user_id, requests_per_minute }): Parameters<RateLimitPolicyParams>,
    ) -> String {
        let req = shohei::api::RateLimitPolicyRequest {
            user_id,
            requests_per_minute,
            requests_per_hour: requests_per_minute.saturating_mul(60),
            requests_per_day: requests_per_minute.saturating_mul(1440),
        };
        match shohei::api::set_rate_limit_policy(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Create approval gate for sensitive operations (requires 2+ approvals)")]
    async fn create_approval_gate(
        &self,
        Parameters(ApprovalGateParams { operation, requester }): Parameters<ApprovalGateParams>,
    ) -> String {
        let req = shohei::api::ApprovalGateRequest {
            operation,
            requester,
            justification: "Governance operation".to_string(),
            urgency: "medium".to_string(),
        };
        match shohei::api::create_approval_gate(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Query audit logs for user actions and system events")]
    async fn query_audit_logs(
        &self,
        Parameters(AuditLogQueryParams { days }): Parameters<AuditLogQueryParams>,
    ) -> String {
        let req = shohei::api::AuditLogQueryRequest {
            user: None,
            action: None,
            days,
        };
        match shohei::api::query_audit_logs(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Generate compliance report (SOC2, ISO27001, HIPAA, GDPR, PCI-DSS)")]
    async fn generate_compliance_report(
        &self,
        Parameters(ComplianceReportParams { framework }): Parameters<ComplianceReportParams>,
    ) -> String {
        let req = shohei::api::ComplianceReportRequest {
            framework,
            period: "monthly".to_string(),
        };
        match shohei::api::generate_compliance_report(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Set tool call access control (restrict by user, domain, or rate limit)")]
    async fn set_tool_call_control(
        &self,
        Parameters(ToolCallControlParams { tool_name, allowed_users }): Parameters<ToolCallControlParams>,
    ) -> String {
        let users: Vec<String> = allowed_users
            .map(|u| u.split(',').map(|s| s.trim().to_string()).collect())
            .unwrap_or_default();

        let req = shohei::api::ToolCallControlRequest {
            tool_name,
            allowed_users: users,
            allowed_domains: None,
            max_calls_per_day: None,
        };
        match shohei::api::set_tool_call_control(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Classify domain/IP by risk level (critical, high, medium, low, unknown)")]
    async fn classify_risk(
        &self,
        Parameters(RiskClassificationParams { target }): Parameters<RiskClassificationParams>,
    ) -> String {
        let req = shohei::api::RiskClassificationRequest {
            target,
            historical_data: true,
        };
        match shohei::api::classify_risk(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Quarantine suspicious domains/IPs pending review")]
    async fn quarantine_targets(
        &self,
        Parameters(QuarantineParams { targets, reason }): Parameters<QuarantineParams>,
    ) -> String {
        let req = shohei::api::QuarantineRequest {
            targets,
            reason,
            duration_hours: 72,
        };
        match shohei::api::quarantine_targets(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Alert on policy violations (blocklist match, rate limit, unauthorized access)")]
    async fn alert_policy_violation(
        &self,
        Parameters(PolicyViolationAlertParams { domain, violation_type }): Parameters<PolicyViolationAlertParams>,
    ) -> String {
        let req = shohei::api::PolicyViolationAlertRequest {
            domain,
            violation_type,
        };
        match shohei::api::alert_policy_violation(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check data residency compliance (EU, US, APAC, CA)")]
    async fn check_data_residency(
        &self,
        Parameters(DataResidencyComplianceParams { domain, required_region }): Parameters<DataResidencyComplianceParams>,
    ) -> String {
        let req = shohei::api::DataResidencyComplianceRequest {
            domain,
            required_region,
        };
        match shohei::api::check_data_residency(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Verify encryption status (TLS version, cipher strength, compliance)")]
    async fn verify_encryption_status(
        &self,
        Parameters(EncryptionStatusParams { domain }): Parameters<EncryptionStatusParams>,
    ) -> String {
        let req = shohei::api::EncryptionStatusRequest {
            domain,
        };
        match shohei::api::verify_encryption_status(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Create policy exception (temporary or permanent)")]
    async fn create_policy_exception(
        &self,
        Parameters(PolicyExceptionParams { target, exception_type }): Parameters<PolicyExceptionParams>,
    ) -> String {
        let req = shohei::api::PolicyExceptionRequest {
            target,
            exception_type,
            duration_days: Some(30),
            justification: "Governance exception".to_string(),
        };
        match shohei::api::create_policy_exception(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Verify audit trail integrity and completeness")]
    async fn verify_audit_trail(
        &self,
        Parameters(AuditTrailVerificationParams { domain }): Parameters<AuditTrailVerificationParams>,
    ) -> String {
        let req = shohei::api::AuditTrailVerificationRequest {
            domain,
            days: 30,
        };
        match shohei::api::verify_audit_trail(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Measure governance policy effectiveness and ROI")]
    async fn measure_policy_effectiveness(
        &self,
        Parameters(PolicyEffectivenessParams { days }): Parameters<PolicyEffectivenessParams>,
    ) -> String {
        let req = shohei::api::PolicyEffectivenessRequest {
            days,
        };
        match shohei::api::measure_policy_effectiveness(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Get incident response playbook with escalation procedures")]
    async fn get_incident_response_playbook(
        &self,
        Parameters(IncidentResponsePlaybookParams { incident_type, severity }): Parameters<IncidentResponsePlaybookParams>,
    ) -> String {
        let req = shohei::api::IncidentResponsePlaybookRequest {
            incident_type,
            severity,
        };
        match shohei::api::get_incident_response_playbook(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Assess security posture maturity level and improvement areas")]
    async fn assess_security_posture(
        &self,
        Parameters(SecurityPostureAssessmentParams { domain }): Parameters<SecurityPostureAssessmentParams>,
    ) -> String {
        let req = shohei::api::SecurityPostureAssessmentRequest {
            domain,
        };
        match shohei::api::assess_security_posture(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Run breach simulation / tabletop exercise (phishing, credential theft, data exfil, lateral movement)")]
    async fn run_breach_simulation(
        &self,
        Parameters(BreachSimulationParams { simulation_type }): Parameters<BreachSimulationParams>,
    ) -> String {
        let req = shohei::api::BreachSimulationRequest {
            simulation_type,
            scope: "organization_wide".to_string(),
        };
        match shohei::api::run_breach_simulation(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Detect personally identifiable information (PII) in domain/system")]
    async fn detect_pii(
        &self,
        Parameters(PiiDetectionParams { domain }): Parameters<PiiDetectionParams>,
    ) -> String {
        let req = shohei::api::PiiDetectionRequest {
            domain,
            scan_depth: "deep".to_string(),
        };
        match shohei::api::detect_pii(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Anonymize PII (redaction, pseudonymization, generalization)")]
    async fn anonymize_pii(
        &self,
        Parameters(PiiAnonymizationParams { domain }): Parameters<PiiAnonymizationParams>,
    ) -> String {
        let req = shohei::api::PiiAnonymizationRequest {
            domain,
            pii_types: vec!["email".to_string(), "phone".to_string(), "ssn".to_string()],
            retention_days: None,
        };
        match shohei::api::anonymize_pii(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Define data retention policy and auto-purge schedule")]
    async fn define_retention_policy(
        &self,
        Parameters(DataRetentionPolicyParams { domain }): Parameters<DataRetentionPolicyParams>,
    ) -> String {
        let req = shohei::api::DataRetentionPolicyRequest {
            domain,
            data_type: "customer_data".to_string(),
            retention_days: 365,
        };
        match shohei::api::define_retention_policy(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Assess GDPR compliance (processing, consent, DPIA, documentation)")]
    async fn assess_gdpr_compliance(
        &self,
        Parameters(GdprComplianceParams { domain }): Parameters<GdprComplianceParams>,
    ) -> String {
        let req = shohei::api::GdprComplianceRequest {
            domain,
            assessment_scope: "processing".to_string(),
        };
        match shohei::api::assess_gdpr_compliance(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Assess HIPAA compliance (technical, administrative, physical controls)")]
    async fn assess_hipaa_compliance(
        &self,
        Parameters(HipaaComplianceParams { domain }): Parameters<HipaaComplianceParams>,
    ) -> String {
        let req = shohei::api::HipaaComplianceRequest {
            domain,
            check_type: "technical".to_string(),
        };
        match shohei::api::assess_hipaa_compliance(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Assess PCI-DSS compliance for payment systems")]
    async fn assess_pci_dss_compliance(
        &self,
        Parameters(PciDssComplianceParams { domain }): Parameters<PciDssComplianceParams>,
    ) -> String {
        let req = shohei::api::PciDssComplianceRequest {
            domain,
            requirement: None,
        };
        match shohei::api::assess_pci_dss_compliance(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Classify data by sensitivity level (public, internal, confidential, restricted)")]
    async fn classify_data(
        &self,
        Parameters(DataClassificationParams { domain }): Parameters<DataClassificationParams>,
    ) -> String {
        let req = shohei::api::DataClassificationRequest {
            domain,
            data_inventory_provided: true,
        };
        match shohei::api::classify_data(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Apply data masking rules to sensitive fields")]
    async fn apply_data_masking(
        &self,
        Parameters(DataMaskingParams { domain }): Parameters<DataMaskingParams>,
    ) -> String {
        let req = shohei::api::DataMaskingRequest {
            domain,
            masking_rules: vec!["email_mask".to_string(), "phone_mask".to_string()],
        };
        match shohei::api::apply_data_masking(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Delete expired data according to retention policies")]
    async fn delete_expired_data(
        &self,
        Parameters(DataDeletionParams { domain }): Parameters<DataDeletionParams>,
    ) -> String {
        let req = shohei::api::DataDeletionRequest {
            domain,
            data_types: vec!["logs".to_string(), "backups".to_string()],
            reason: "retention_expired".to_string(),
        };
        match shohei::api::delete_expired_data(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Process data subject access request (DSAR / subject access rights)")]
    async fn process_data_subject_access(
        &self,
        Parameters(DataSubjectAccessParams { domain, subject_identifier }): Parameters<DataSubjectAccessParams>,
    ) -> String {
        let req = shohei::api::DataSubjectAccessRequest {
            domain,
            subject_identifier,
            data_types: None,
        };
        match shohei::api::process_data_subject_access(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Manage user consent preferences (marketing, analytics, processing)")]
    async fn manage_consent(
        &self,
        Parameters(ConsentManagementParams { domain }): Parameters<ConsentManagementParams>,
    ) -> String {
        let req = shohei::api::ConsentManagementRequest {
            domain,
            consent_type: "processing".to_string(),
        };
        match shohei::api::manage_consent(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Create cryptographic signature for audit trail (RSA, ECDSA, EdDSA)")]
    async fn sign_audit_trail(
        &self,
        Parameters(CryptographicSignatureParams { domain }): Parameters<CryptographicSignatureParams>,
    ) -> String {
        let req = shohei::api::CryptographicSignatureRequest {
            domain,
            algorithm: "ECDSA".to_string(),
            document_hash: "sha256".to_string(),
        };
        match shohei::api::sign_audit_trail(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Verify audit trail immutability (hash chain, blockchain, HSM)")]
    async fn verify_audit_immutability(
        &self,
        Parameters(AuditTrailImmutabilityParams { domain }): Parameters<AuditTrailImmutabilityParams>,
    ) -> String {
        let req = shohei::api::AuditTrailImmutabilityRequest {
            domain,
            days: 90,
        };
        match shohei::api::verify_audit_immutability(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Conduct privacy impact assessment (DPIA/PIA)")]
    async fn conduct_privacy_assessment(
        &self,
        Parameters(PrivacyImpactAssessmentParams { domain }): Parameters<PrivacyImpactAssessmentParams>,
    ) -> String {
        let req = shohei::api::PrivacyImpactAssessmentRequest {
            domain,
            processing_activity: "Data processing".to_string(),
        };
        match shohei::api::conduct_privacy_assessment(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Notify affected individuals of privacy breach (GDPR 72-hour requirement)")]
    async fn notify_privacy_breach(
        &self,
        Parameters(PrivacyBreachNotificationParams { domain, breach_scope, breach_type }): Parameters<PrivacyBreachNotificationParams>,
    ) -> String {
        let req = shohei::api::PrivacyBreachNotificationRequest {
            domain,
            breach_scope,
            breach_type,
        };
        match shohei::api::notify_privacy_breach(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Request RFC 3161 timestamp from TSA (timestamp authority)")]
    async fn request_rfc3161_timestamp(
        &self,
        Parameters(Rfc3161TimestampParams { document_hash }): Parameters<Rfc3161TimestampParams>,
    ) -> String {
        let req = shohei::api::Rfc3161TimestampRequest {
            document_hash,
            hash_algorithm: "SHA256".to_string(),
            tsa_url: None,
        };
        match shohei::api::request_rfc3161_timestamp(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Validate RFC 3161 timestamp token and TSA signature")]
    async fn validate_timestamp(
        &self,
        Parameters(TimestampValidationParams { timestamp_token }): Parameters<TimestampValidationParams>,
    ) -> String {
        let req = shohei::api::TimestampValidationRequest {
            timestamp_token,
            document_hash: "".to_string(),
        };
        match shohei::api::validate_timestamp(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Add entry to Sigstore Rekor transparency log (immutable audit trail)")]
    async fn add_sigstore_rekor_entry(
        &self,
        Parameters(SignstoreRekorParams { artifact_hash }): Parameters<SignstoreRekorParams>,
    ) -> String {
        let req = shohei::api::SignstoreRekorEntryRequest {
            artifact_hash,
            signature: "".to_string(),
            certificate: "".to_string(),
        };
        match shohei::api::add_sigstore_rekor_entry(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Verify Sigstore Rekor entry consistency and inclusion proofs")]
    async fn verify_rekor_entry(
        &self,
        Parameters(RekorVerificationParams { entry_uuid }): Parameters<RekorVerificationParams>,
    ) -> String {
        let req = shohei::api::RekorEntryVerificationRequest {
            entry_uuid,
            merkle_tree_leaf_hash: "".to_string(),
        };
        match shohei::api::verify_rekor_entry(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Generate zero-knowledge proof (merkle, range, authentication proofs)")]
    async fn generate_zk_proof(
        &self,
        Parameters(ZkProofGenerationParams { circuit_type }): Parameters<ZkProofGenerationParams>,
    ) -> String {
        let req = shohei::api::ZkProofGenerationRequest {
            statement: "".to_string(),
            witness: "".to_string(),
            circuit_type,
        };
        match shohei::api::generate_zk_proof(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Verify zero-knowledge proof (correctness and security)")]
    async fn verify_zk_proof(
        &self,
        Parameters(ZkProofVerificationParams { proof }): Parameters<ZkProofVerificationParams>,
    ) -> String {
        let req = shohei::api::ZkProofVerificationRequest {
            proof,
            verification_key: "".to_string(),
            statement: "".to_string(),
        };
        match shohei::api::verify_zk_proof(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Create escrow agreement with release conditions")]
    async fn create_escrow_agreement(
        &self,
        Parameters(EscrowAgreementParams { payer, payee, amount }): Parameters<EscrowAgreementParams>,
    ) -> String {
        let req = shohei::api::EscrowAgreementRequest {
            payer,
            payee,
            amount,
            release_conditions: Vec::new(),
        };
        match shohei::api::create_escrow_agreement(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Release funds from escrow upon condition satisfaction")]
    async fn release_escrow(
        &self,
        Parameters(EscrowReleaseParams { escrow_id }): Parameters<EscrowReleaseParams>,
    ) -> String {
        let req = shohei::api::EscrowReleaseRequest {
            escrow_id,
            release_reason: "Conditions satisfied".to_string(),
        };
        match shohei::api::release_escrow(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Notarize document digitally (blockchain, TSA, or ledger)")]
    async fn notarize_document(
        &self,
        Parameters(DigitalNotarizationParams { document_hash }): Parameters<DigitalNotarizationParams>,
    ) -> String {
        let req = shohei::api::DigitalNotarizationRequest {
            document_hash,
            document_type: "".to_string(),
            notary_type: "public_blockchain".to_string(),
        };
        match shohei::api::notarize_document(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Verify digital notarization (integrity and authenticity)")]
    async fn verify_notarization(
        &self,
        Parameters(NotarizationVerificationParams { notarization_id }): Parameters<NotarizationVerificationParams>,
    ) -> String {
        let req = shohei::api::NotarizationVerificationRequest {
            notarization_id,
            document_hash: "".to_string(),
        };
        match shohei::api::verify_notarization(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Generate and manage cryptographic keys (RSA, ECDSA, EdDSA)")]
    async fn manage_cryptographic_key(
        &self,
        Parameters(KeyManagementParams { key_type }): Parameters<KeyManagementParams>,
    ) -> String {
        let req = shohei::api::KeyManagementRequest {
            key_type,
            key_size: 2048,
            usage: "signing".to_string(),
        };
        match shohei::api::manage_cryptographic_key(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Rotate cryptographic key with transition period")]
    async fn rotate_key(
        &self,
        Parameters(KeyRotationParams { key_id }): Parameters<KeyRotationParams>,
    ) -> String {
        let req = shohei::api::KeyRotationRequest {
            key_id,
            new_key_size: None,
        };
        match shohei::api::rotate_key(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Bind audit trail entries cryptographically (hash chain, merkle tree)")]
    async fn bind_audit_trail(
        &self,
        Parameters(AuditTrailBindingParams { audit_entries }): Parameters<AuditTrailBindingParams>,
    ) -> String {
        let req = shohei::api::AuditTrailBindingRequest {
            audit_entries,
            binding_type: "hash_chain".to_string(),
        };
        match shohei::api::bind_audit_trail(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Perform cryptographic operations via Hardware Security Module (HSM)")]
    async fn integrate_hsm(
        &self,
        Parameters(HsmIntegrationParams { operation }): Parameters<HsmIntegrationParams>,
    ) -> String {
        let req = shohei::api::HsmIntegrationRequest {
            operation,
            hsm_slot: 0,
        };
        match shohei::api::integrate_hsm(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Verify cryptographic compliance (FIPS140-2/3, Common Criteria)")]
    async fn verify_crypto_compliance(
        &self,
        Parameters(CryptographicComplianceParams { domain }): Parameters<CryptographicComplianceParams>,
    ) -> String {
        let req = shohei::api::CryptographicComplianceRequest {
            domain,
            standard: "FIPS140-3".to_string(),
        };
        match shohei::api::verify_crypto_compliance(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Resolve shortened URLs (bit.ly, t.co, etc.) through full redirect chain")]
    async fn check_url_unshorten(
        &self,
        Parameters(UrlUnshortenParams { url }): Parameters<UrlUnshortenParams>,
    ) -> String {
        let req = shohei::api::UrlUnshortenRequest { url, timeout_secs: 10 };
        match shohei::api::check_url_unshorten(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "JA4H HTTP client fingerprinting — analyze request headers to identify client type")]
    async fn check_ja4h_fingerprint(
        &self,
        Parameters(Ja4hFingerprintParams { url }): Parameters<Ja4hFingerprintParams>,
    ) -> String {
        let req = shohei::api::Ja4hFingerprintRequest { url, timeout_secs: 10 };
        match shohei::api::check_ja4h_fingerprint(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Multi-source URL threat check combining URLhaus + phishing + domain age")]
    async fn check_url_safety_multi(
        &self,
        Parameters(UrlSafetyMultiParams { url }): Parameters<UrlSafetyMultiParams>,
    ) -> String {
        let req = shohei::api::UrlSafetyMultiRequest { url, timeout_secs: 10 };
        match shohei::api::check_url_safety_multi(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Detect open redirect vulnerabilities in URL redirect chains")]
    async fn check_url_redirect_threat(
        &self,
        Parameters(UrlRedirectThreatParams { url }): Parameters<UrlRedirectThreatParams>,
    ) -> String {
        let req = shohei::api::UrlRedirectThreatRequest { url, timeout_secs: 10 };
        match shohei::api::check_url_redirect_threat(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check if domain maps to publicly accessible AWS S3 bucket")]
    async fn check_s3_bucket_exposure(
        &self,
        Parameters(S3BucketExposureParams { domain }): Parameters<S3BucketExposureParams>,
    ) -> String {
        let req = shohei::api::S3BucketExposureRequest { domain, timeout_secs: 10 };
        match shohei::api::check_s3_bucket_exposure(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Detect cloud provider (AWS/GCP/Azure/Cloudflare) via CNAME and IP patterns")]
    async fn check_cloud_provider(
        &self,
        Parameters(CloudProviderParams { domain }): Parameters<CloudProviderParams>,
    ) -> String {
        let req = shohei::api::CloudProviderRequest { domain, timeout_secs: 10 };
        match shohei::api::check_cloud_provider(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "CIS-lite benchmark: check HTTP security headers, server disclosure, directory listing")]
    async fn check_server_hardening(
        &self,
        Parameters(ServerHardeningParams { url }): Parameters<ServerHardeningParams>,
    ) -> String {
        let req = shohei::api::ServerHardeningRequest { url, timeout_secs: 10 };
        match shohei::api::check_server_hardening(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Detect dangling DNS records pointing to deleted cloud resources")]
    async fn check_dangling_dns(
        &self,
        Parameters(DanglingDnsParams { domain }): Parameters<DanglingDnsParams>,
    ) -> String {
        let req = shohei::api::DanglingDnsRequest { domain, timeout_secs: 10 };
        match shohei::api::check_dangling_dns(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check username availability on GitHub, Twitter, LinkedIn, Reddit, HackerNews")]
    async fn check_username_osint(
        &self,
        Parameters(UsernameOsintParams { username }): Parameters<UsernameOsintParams>,
    ) -> String {
        let req = shohei::api::UsernameOsintRequest { username, timeout_secs: 10 };
        match shohei::api::check_username_osint(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Email intelligence: SMTP validation + breach check + SPF/DKIM assessment")]
    async fn check_email_intel(
        &self,
        Parameters(EmailIntelParams { email }): Parameters<EmailIntelParams>,
    ) -> String {
        let req = shohei::api::EmailIntelRequest { email, timeout_secs: 10 };
        match shohei::api::check_email_intel(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Organization footprinting: WHOIS, tech stack, social media profiles")]
    async fn check_organization_intel(
        &self,
        Parameters(OrganizationIntelParams { domain }): Parameters<OrganizationIntelParams>,
    ) -> String {
        let req = shohei::api::OrganizationIntelRequest { domain, timeout_secs: 10 };
        match shohei::api::check_organization_intel(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Map social media handles linked to a domain/brand")]
    async fn check_social_media_presence(
        &self,
        Parameters(SocialMediaPresenceParams { domain }): Parameters<SocialMediaPresenceParams>,
    ) -> String {
        let req = shohei::api::SocialMediaPresenceRequest { domain, timeout_secs: 10 };
        match shohei::api::check_social_media_presence(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "ASN reputation scoring: combine DNSBL + BGP visibility + threat intel")]
    async fn check_asn_reputation(
        &self,
        Parameters(AsnReputationParams { asn }): Parameters<AsnReputationParams>,
    ) -> String {
        let req = shohei::api::AsnReputationRequest { asn, timeout_secs: 10 };
        match shohei::api::check_asn_reputation(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Historical BGP route changes via RIPE STAT")]
    async fn check_bgp_hijack_history(
        &self,
        Parameters(BgpHijackHistoryParams { prefix }): Parameters<BgpHijackHistoryParams>,
    ) -> String {
        let req = shohei::api::BgpHijackHistoryRequest { prefix, timeout_secs: 10 };
        match shohei::api::check_bgp_hijack_history(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Comprehensive attack surface score: open ports + CVEs + BGP + RPKI + threat intel")]
    async fn check_network_exposure_score(
        &self,
        Parameters(NetworkExposureScoreParams { target }): Parameters<NetworkExposureScoreParams>,
    ) -> String {
        let req = shohei::api::NetworkExposureScoreRequest { target, timeout_secs: 10 };
        match shohei::api::check_network_exposure_score(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check if 169.254.169.254 IMDS endpoint is accessible")]
    async fn check_cloud_metadata_exposure(
        &self,
        Parameters(CloudMetadataExposureParams { domain }): Parameters<CloudMetadataExposureParams>,
    ) -> String {
        let req = shohei::api::CloudMetadataExposureRequest { domain, timeout_secs: 10 };
        match shohei::api::check_cloud_metadata_exposure(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Detect Azure Blob Storage CNAME exposure")]
    async fn check_azure_blob_exposure(
        &self,
        Parameters(AzureBlobExposureParams { domain }): Parameters<AzureBlobExposureParams>,
    ) -> String {
        let req = shohei::api::AzureBlobExposureRequest { domain, timeout_secs: 10 };
        match shohei::api::check_azure_blob_exposure(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Detect Google Cloud Storage CNAME exposure")]
    async fn check_gcs_bucket_exposure(
        &self,
        Parameters(GcsBucketExposureParams { domain }): Parameters<GcsBucketExposureParams>,
    ) -> String {
        let req = shohei::api::GcsBucketExposureRequest { domain, timeout_secs: 10 };
        match shohei::api::check_gcs_bucket_exposure(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Analyze CORS policy from HTTP response headers")]
    async fn check_cors_policy(
        &self,
        Parameters(CorsPolicyParams { url }): Parameters<CorsPolicyParams>,
    ) -> String {
        let req = shohei::api::CorsPolicyRequest { url, timeout_secs: 10 };
        match shohei::api::check_cors_policy(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Fetch and parse .well-known/security.txt (RFC 9116)")]
    async fn check_security_txt(
        &self,
        Parameters(SecurityTxtParams { domain }): Parameters<SecurityTxtParams>,
    ) -> String {
        let req = shohei::api::SecurityTxtRequest { domain, timeout_secs: 10 };
        match shohei::api::check_security_txt(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Parse and analyze JWT token security (alg, exp, none attack)")]
    async fn check_jwt_security(
        &self,
        Parameters(JwtSecurityParams { token }): Parameters<JwtSecurityParams>,
    ) -> String {
        let req = shohei::api::JwtSecurityRequest { token };
        match shohei::api::check_jwt_security(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Inspect HTTP Set-Cookie headers for Secure, HttpOnly, SameSite flags")]
    async fn check_cookie_security(
        &self,
        Parameters(CookieSecurityParams { url }): Parameters<CookieSecurityParams>,
    ) -> String {
        let req = shohei::api::CookieSecurityRequest { url, timeout_secs: 10 };
        match shohei::api::check_cookie_security(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Deep CSP analysis: unsafe-inline, unsafe-eval, wildcard sources")]
    async fn check_csp_advanced(
        &self,
        Parameters(CspAdvancedParams { url }): Parameters<CspAdvancedParams>,
    ) -> String {
        let req = shohei::api::CspAdvancedRequest { url, timeout_secs: 10 };
        match shohei::api::check_csp_advanced(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Probe common sensitive paths (.env, package.json, .git/config, etc.)")]
    async fn check_exposed_files(
        &self,
        Parameters(ExposedFilesParams { domain }): Parameters<ExposedFilesParams>,
    ) -> String {
        let req = shohei::api::ExposedFilesRequest { domain, timeout_secs: 10 };
        match shohei::api::check_exposed_files(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Query npm registry for package metadata, version, maintainers, typosquatting")]
    async fn check_npm_package_security(
        &self,
        Parameters(NpmPackageSecurityParams { package }): Parameters<NpmPackageSecurityParams>,
    ) -> String {
        let req = shohei::api::NpmPackageSecurityRequest { package, timeout_secs: 10 };
        match shohei::api::check_npm_package_security(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Query PyPI for package metadata, maintainers, security indicators")]
    async fn check_pypi_package_security(
        &self,
        Parameters(PypiPackageSecurityParams { package }): Parameters<PypiPackageSecurityParams>,
    ) -> String {
        let req = shohei::api::PypiPackageSecurityRequest { package, timeout_secs: 10 };
        match shohei::api::check_pypi_package_security(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check if internal package name exists on public registries (npm, PyPI, crates.io)")]
    async fn check_dependency_confusion(
        &self,
        Parameters(DependencyConfusionParams { internal_package }): Parameters<DependencyConfusionParams>,
    ) -> String {
        let req = shohei::api::DependencyConfusionRequest { internal_package, timeout_secs: 10 };
        match shohei::api::check_dependency_confusion(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Detect accidentally exposed SBOM files (/sbom.json, /bom.xml, /.well-known/sbom)")]
    async fn check_sbom_disclosure(
        &self,
        Parameters(SbomDisclosureParams { domain }): Parameters<SbomDisclosureParams>,
    ) -> String {
        let req = shohei::api::SbomDisclosureRequest { domain, timeout_secs: 10 };
        match shohei::api::check_sbom_disclosure(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    // ── Phase 9: Web Intelligence ────────────────────────────────────────────

    #[tool(description = "Fetch and analyze robots.txt — discover sensitive disallowed paths (admin, backup, config, api), sitemap URLs, and crawl-delay settings")]
    async fn check_robots_txt(
        &self,
        Parameters(RobotsTxtParams { domain }): Parameters<RobotsTxtParams>,
    ) -> String {
        let req = shohei::api::RobotsTxtRequest { domain, timeout_secs: 10 };
        match shohei::api::check_robots_txt(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Discover all accessible .well-known/ endpoints on a domain — OIDC, security.txt, MTA-STS, JWKS, ai-plugin.json, assetlinks, SBOM, and more")]
    async fn check_well_known(
        &self,
        Parameters(WellKnownParams { domain }): Parameters<WellKnownParams>,
    ) -> String {
        let req = shohei::api::WellKnownRequest { domain, timeout_secs: 10 };
        match shohei::api::check_well_known(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Audit OAuth 2.0 / OIDC configuration — check for implicit flow, PKCE support, grant types, and response types from .well-known/openid-configuration")]
    async fn check_oauth_oidc(
        &self,
        Parameters(OauthOidcParams { domain }): Parameters<OauthOidcParams>,
    ) -> String {
        let req = shohei::api::OauthOidcRequest { domain, timeout_secs: 10 };
        match shohei::api::check_oauth_oidc(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Check certificate pinning configuration — Expect-CT enforce mode, HPKP (deprecated), CAA iodef reporting")]
    async fn check_cert_pinning(
        &self,
        Parameters(CertPinningParams { domain }): Parameters<CertPinningParams>,
    ) -> String {
        let req = shohei::api::CertPinningRequest { domain, timeout_secs: 10 };
        match shohei::api::check_cert_pinning(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Probe for exposed API/debug endpoints — Spring Actuator, Swagger UI, GraphQL, phpinfo, server-status, and version disclosure headers")]
    async fn check_api_exposure(
        &self,
        Parameters(ApiExposureParams { domain }): Parameters<ApiExposureParams>,
    ) -> String {
        let req = shohei::api::ApiExposureRequest { domain, timeout_secs: 10 };
        match shohei::api::check_api_exposure(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    // ── Phase 9: Service Exposure ────────────────────────────────────────────

    #[tool(description = "Probe for unauthenticated database access — Redis (6379), MongoDB (27017), Elasticsearch (9200), Memcached (11211), CouchDB (5984)")]
    async fn check_exposed_databases(
        &self,
        Parameters(ExposedDatabasesParams { host }): Parameters<ExposedDatabasesParams>,
    ) -> String {
        let req = shohei::api::ExposedDatabasesRequest { host, timeout_secs: 10 };
        match shohei::api::check_exposed_databases(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Detect exposed container orchestration APIs — Docker API (2375/2376), Kubernetes API (6443), etcd (2379)")]
    async fn check_container_exposure(
        &self,
        Parameters(ContainerExposureParams { host }): Parameters<ContainerExposureParams>,
    ) -> String {
        let req = shohei::api::ContainerExposureRequest { host, timeout_secs: 10 };
        match shohei::api::check_container_exposure(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Fingerprint running services via banner grabbing — SSH version, FTP, SMTP, MySQL, PostgreSQL, Redis with security notes")]
    async fn check_service_fingerprint(
        &self,
        Parameters(ServiceFingerprintParams { host, ports }): Parameters<ServiceFingerprintParams>,
    ) -> String {
        let req = shohei::api::ServiceFingerprintRequest { host, ports, timeout_secs: 10 };
        match shohei::api::check_service_fingerprint(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Score a domain name for DGA (Domain Generation Algorithm) risk using entropy, vowel ratio, digit ratio, and consonant cluster analysis")]
    async fn check_dga_risk(
        &self,
        Parameters(DgaRiskParams { domain }): Parameters<DgaRiskParams>,
    ) -> String {
        let req = shohei::api::DgaRiskRequest { domain };
        match shohei::api::check_dga_risk(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    // ── Phase 9: Subdomain Takeover + Passive DNS + Azure AD ────────────────

    #[tool(description = "Detect subdomain takeover vulnerabilities across 30+ cloud services — GitHub Pages, Heroku, Netlify, Vercel, Azure, AWS, Shopify, Fastly, and more")]
    async fn check_subdomain_takeover(
        &self,
        Parameters(SubdomainTakeoverParams { domain }): Parameters<SubdomainTakeoverParams>,
    ) -> String {
        let req = shohei::api::SubdomainTakeoverRequest { domain, timeout_secs: 15 };
        match shohei::api::check_subdomain_takeover(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Query RIPE Stat passive DNS for historical DNS records — IP changes, old nameservers, past A/CNAME records (no API key required)")]
    async fn check_passive_dns(
        &self,
        Parameters(PassiveDnsParams { query }): Parameters<PassiveDnsParams>,
    ) -> String {
        let req = shohei::api::PassiveDnsRequest { query, timeout_secs: 15 };
        match shohei::api::check_passive_dns(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Discover Azure AD / Entra ID tenant information — tenant ID, federation type (ADFS/Managed), OIDC metadata via public Microsoft Graph endpoints")]
    async fn check_azure_ad_exposure(
        &self,
        Parameters(AzureAdExposureParams { domain }): Parameters<AzureAdExposureParams>,
    ) -> String {
        let req = shohei::api::AzureAdExposureRequest { domain, timeout_secs: 10 };
        match shohei::api::check_azure_ad_exposure(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    // ── Phase 9: Email Advanced ──────────────────────────────────────────────

    #[tool(description = "Check DKIM key strength — detect weak 1024-bit RSA keys, validate 2048-bit and Ed25519 keys across common selectors (default, google, selector1/2, etc.)")]
    async fn check_dkim_key_strength(
        &self,
        Parameters(DkimKeyStrengthParams { domain, selectors }): Parameters<DkimKeyStrengthParams>,
    ) -> String {
        let req = shohei::api::DkimKeyStrengthRequest { domain, selectors, timeout_secs: 15 };
        match shohei::api::check_dkim_key_strength(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    #[tool(description = "Deep MX server security audit — STARTTLS support, banner leak, ESMTP features for each MX server via live SMTP connection")]
    async fn check_mx_security(
        &self,
        Parameters(MxSecurityParams { domain }): Parameters<MxSecurityParams>,
    ) -> String {
        let req = shohei::api::MxSecurityRequest { domain, timeout_secs: 15 };
        match shohei::api::check_mx_security(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }

    // ── Phase 9: Attack Surface Mapping ─────────────────────────────────────

    #[tool(description = "Comprehensive attack surface score (0-100) — aggregates TLS, web security headers, email security, and network exposure into a CVSS-like composite score")]
    async fn check_attack_surface(
        &self,
        Parameters(AttackSurfaceParams { domain }): Parameters<AttackSurfaceParams>,
    ) -> String {
        let req = shohei::api::AttackSurfaceRequest { domain, timeout_secs: 20 };
        match shohei::api::check_attack_surface(&req).await {
            Ok(result) => serde_json::to_string_pretty(&result).unwrap_or_default(),
            Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
        }
    }
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    eprintln!("[shohei-mcp] Server started");
    ShoheiServer
        .serve(rmcp::transport::stdio())
        .await?
        .waiting()
        .await?;
    eprintln!("[shohei-mcp] Server exiting");
    Ok(())
}