rust-fs-mcp 0.1.1

Rust stdio MCP server compatible with fs-mcp public tool contracts.
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
//! catalog.rs
//! protocol::catalog
//!
//! Single source of truth for the public tool catalog (name, description, annotation, JSON input schema) exposed by tools/list.
//! Caches the full and fast-coding variants in OnceLock based on the RUST_FS_MCP_TOOL_PROFILE env var.
//!

use serde_json::{Map, Value, json};
use std::env;
use std::sync::OnceLock;

const CMD_PRF_DSC: &str = "For large arguments, pass a UTF-8 JSON file via {\"args_path\":\"ABSOLUTE_PATH_TO_ARGS_JSON\"}.";
const BTCH_GDNC: &str = "Batch same-kind operations into one call.";
const PTH_GDNC: &str =
    "Use absolute paths. Relative paths depend on the current working directory.";
static FULL_TOOL_CATALOG: OnceLock<Vec<Value>> = OnceLock::new();
static FAST_CODING_TOOL_CATALOG: OnceLock<Vec<Value>> = OnceLock::new();
static ACTIVE_PROFILE: OnceLock<String> = OnceLock::new();

// 1. Tool catalog ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
// Removes the per-`tools/list` cost of an env::var call plus a full catalog clone via an OnceLock cache.
pub fn tool_catalog() -> Vec<Value> {
    let profile = ACTIVE_PROFILE.get_or_init(|| {
        env::var("RUST_FS_MCP_TOOL_PROFILE").unwrap_or_else(|_| "full".to_string())
    });
    tool_catalog_for_profile(profile)
}

pub fn tool_catalog_for_profile(profile: &str) -> Vec<Value> {
    if profile == "fast-coding" {
        return FAST_CODING_TOOL_CATALOG
            .get_or_init(|| {
                full_tool_catalog_ref()
                    .iter()
                    .filter(|tool| tool.get("name").and_then(Value::as_str) == Some("fs-inspect"))
                    .cloned()
                    .collect()
            })
            .clone();
    }
    full_tool_catalog_ref().clone()
}

fn full_tool_catalog_ref() -> &'static Vec<Value> {
    FULL_TOOL_CATALOG.get_or_init(build_full_tool_catalog)
}

fn build_full_tool_catalog() -> Vec<Value> {
    vec![
        tool(
            "file-read",
            "Read Files",
            &format!(
                "Read files in parallel.\nUse paths for simple reads or items for offset, length, headers, or URL reads.\nSet allowMissing true to return missing local paths as non-error missing results.\n{BTCH_GDNC}\n{PTH_GDNC}\n{CMD_PRF_DSC}"
            ),
            read_schema(),
            true,
            None,
            Some(true),
        ),
        tool(
            "file-lines",
            "Read Files With Line Numbers",
            &format!(
                "Read text files in parallel with 1-based line numbers.\nUse paths for simple reads or items for offset and length.\nSet allowMissing true to return missing local paths as non-error missing results.\n{BTCH_GDNC}\n{PTH_GDNC}\n{CMD_PRF_DSC}"
            ),
            read_schema(),
            true,
            None,
            Some(true),
        ),
        tool(
            "file-write",
            "Write Files",
            &format!(
                "Write files in parallel.\nPrefer content_path or args_path for large text.\n{BTCH_GDNC}\n{PTH_GDNC}\n{CMD_PRF_DSC}"
            ),
            write_schema(),
            false,
            Some(true),
            Some(false),
        ),
        tool(
            "dir-mk",
            "Create Directories",
            &format!(
                "Create one or many directories in parallel.\n{BTCH_GDNC}\n{PTH_GDNC}\n{CMD_PRF_DSC}"
            ),
            dir_mk_schema(),
            false,
            Some(false),
            None,
        ),
        tool(
            "dir-list",
            "List Directories",
            &format!(
                "List one or many directories in parallel.\nUse items: [{{ path, depth?, maxEntries?, excludePatterns?, includeFiles? }}].\nSet allowMissing true to return missing local paths as non-error missing results.\n{BTCH_GDNC}\n{PTH_GDNC}\n{CMD_PRF_DSC}"
            ),
            dir_list_schema(),
            true,
            None,
            None,
        ),
        tool(
            "file-copy",
            "Copy Files",
            &format!(
                "Copy one or many files or directories in parallel.\nUse items: [{{ source, destination, recursive?, force? }}].\n{BTCH_GDNC}\n{PTH_GDNC}\n{CMD_PRF_DSC}"
            ),
            copy_schema(),
            false,
            Some(false),
            Some(false),
        ),
        tool(
            "file-move",
            "Move/Rename Files",
            &format!(
                "Move or rename one or many files in parallel.\n{BTCH_GDNC}\n{PTH_GDNC}\n{CMD_PRF_DSC}"
            ),
            move_schema(),
            false,
            Some(true),
            Some(false),
        ),
        tool(
            "file-remove",
            "Remove Files",
            &format!(
                "Delete one or many files or directories in parallel.\nUse items: [{{ path, recursive?, force? }}].\n{BTCH_GDNC}\n{PTH_GDNC}\n{CMD_PRF_DSC}"
            ),
            remove_schema(),
            false,
            Some(true),
            Some(false),
        ),
        tool(
            "search-start",
            "Start Searches",
            &format!(
                "Start searches in parallel.\npattern_path can reduce transport overhead, and filePattern can narrow the target set.\n{BTCH_GDNC}\n{PTH_GDNC}\n{CMD_PRF_DSC}"
            ),
            search_start_schema(),
            true,
            None,
            None,
        ),
        tool(
            "search-regex",
            "Regex Searches",
            &format!(
                "Run ripgrep-compatible regular-expression content searches directly.\nPrefer this over shell rg when regex search is needed.\npattern_path can reduce transport overhead, and filePattern can narrow the target set.\n{BTCH_GDNC}\n{PTH_GDNC}\n{CMD_PRF_DSC}"
            ),
            search_regex_schema(),
            true,
            None,
            None,
        ),
        tool(
            "search-get",
            "Get Full Search Results",
            &format!(
                "Read one or many active search sessions in parallel with full per-item result text.\nUse offset or length for pagination.\n{BTCH_GDNC}\n{CMD_PRF_DSC}"
            ),
            search_get_schema(),
            true,
            None,
            None,
        ),
        tool(
            "search-stop",
            "Stop Searches",
            &format!("Stop one or many active searches in parallel.\n{BTCH_GDNC}\n{CMD_PRF_DSC}"),
            search_stop_schema(),
            false,
            Some(false),
            None,
        ),
        tool(
            "file-infos",
            "Get File Information",
            &format!(
                "Retrieve metadata for one or many files in parallel.\nSet allowMissing true to return missing local paths as non-error missing results.\n{BTCH_GDNC}\n{PTH_GDNC}\n{CMD_PRF_DSC}"
            ),
            infos_schema(),
            true,
            None,
            None,
        ),
        tool(
            "file-edit",
            "Edit Blocks",
            &format!(
                "Apply exact block replacements in parallel.\nPrefer *_path or args_path for large text.\nFor large or multi-file writes/edits, prefer fs-mcp batch tools with *_path or args_path.\n{BTCH_GDNC}\n{PTH_GDNC}\n{CMD_PRF_DSC}"
            ),
            edit_schema(),
            false,
            Some(true),
            Some(false),
        ),
        tool(
            "file-edit-lines",
            "Edit Line Ranges",
            &format!(
                "Replace, insert, or delete by 1-based line numbers. PREFER over file-edit when line numbers are known (faster, no EOL crafting). EOL auto-detected from file. Use `after: true` to insert after end_line without removing it.\n{BTCH_GDNC}\n{PTH_GDNC}\n{CMD_PRF_DSC}"
            ),
            edit_lines_schema(),
            false,
            Some(true),
            Some(false),
        ),
        tool(
            "git-add",
            "Git Add",
            &format!("Stage files for commit.\n{CMD_PRF_DSC}"),
            git_add_schema(),
            false,
            None,
            None,
        ),
        tool(
            "git-commit",
            "Git Commit",
            &format!(
                "Create a commit from staged changes.\nUse an English multi-line Conventional Commit message.\n<type>: <summary>\n- <change detail>\n- <verification or behavior detail>\nUse messagePath for long messages.\n{CMD_PRF_DSC}"
            ),
            git_commit_schema(),
            false,
            Some(true),
            None,
        ),
        tool(
            "git-diff",
            "Git Diff",
            &format!(
                "Show differences between commits, branches, or working tree state.\n{CMD_PRF_DSC}"
            ),
            git_diff_schema(),
            true,
            None,
            None,
        ),
        tool(
            "git-cwd",
            "Git Set Working Directory",
            &format!(
                "Pin the session git working directory and return a repository snapshot.\n{PTH_GDNC}\n{CMD_PRF_DSC}"
            ),
            git_cwd_schema(),
            false,
            Some(true),
            None,
        ),
        tool(
            "git-show",
            "Git Show",
            &format!("Show a git object or file content at a revision.\n{CMD_PRF_DSC}"),
            git_show_schema(),
            true,
            None,
            None,
        ),
        tool(
            "git-status",
            "Git Status",
            &format!("Show working tree status, staging, and conflicts.\n{CMD_PRF_DSC}"),
            git_status_schema(),
            true,
            None,
            None,
        ),
        tool(
            "fs-inspect",
            "FS Inspect",
            &format!(
                "Run compact read-only filesystem inspection requests in one call for coding tasks. Supports count-files, search, json-pick, and snippet operations with short source snippets. For count-files, use glob or pattern for filename matching.\n{PTH_GDNC}\n{CMD_PRF_DSC}"
            ),
            inspect_schema(),
            true,
            None,
            None,
        ),
    ]
}

// 2. Tool entry ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
fn tool(
    name: &str,
    title: &str,
    description: &str,
    input_schema: Value,
    read_only: bool,
    destructive: Option<bool>,
    open_world: Option<bool>,
) -> Value {
    let mut annotations = Map::new();
    annotations.insert("title".to_string(), json!(title));
    annotations.insert("readOnlyHint".to_string(), json!(read_only));
    if let Some(value) = destructive {
        annotations.insert("destructiveHint".to_string(), json!(value));
    }
    if let Some(value) = open_world {
        annotations.insert("openWorldHint".to_string(), json!(value));
    }
    json!({
        "name": name,
        "description": description,
        "inputSchema": input_schema,
        "annotations": annotations
    })
}

// 3. Schema helpers ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
fn object_schema(properties: Map<String, Value>, required: Vec<&str>) -> Value {
    let mut props = properties;
    props.insert(
        "args_path".to_string(),
        json!({"type": "string", "description": "Path to a UTF-8 JSON file containing the complete arguments for this tool."}),
    );
    props.insert(
        "args_offset".to_string(),
        json!({"type": "number", "default": 0, "description": "Optional character offset inside args_path."}),
    );
    props.insert(
        "args_length".to_string(),
        json!({"type": "number", "description": "Optional character length to read from args_path."}),
    );
    let mut schema = Map::new();
    schema.insert("type".to_string(), json!("object"));
    schema.insert("properties".to_string(), Value::Object(props));
    if !required.is_empty() {
        schema.insert("required".to_string(), json!(required));
    }
    schema.insert("additionalProperties".to_string(), json!(false));
    schema.insert(
        "$schema".to_string(),
        json!("http://json-schema.org/draft-07/schema#"),
    );
    Value::Object(schema)
}

fn item_object(properties: Map<String, Value>, required: Vec<&str>) -> Value {
    let mut schema = Map::new();
    schema.insert("type".to_string(), json!("object"));
    schema.insert("properties".to_string(), Value::Object(properties));
    if !required.is_empty() {
        schema.insert("required".to_string(), json!(required));
    }
    schema.insert("additionalProperties".to_string(), json!(false));
    Value::Object(schema)
}

fn array_of(item: Value) -> Value {
    json!({"type": "array", "items": item, "minItems": 1})
}

fn prop(entries: Vec<(&str, Value)>) -> Map<String, Value> {
    entries
        .into_iter()
        .map(|(key, value)| (key.to_string(), value))
        .collect()
}

fn string() -> Value {
    json!({"type": "string"})
}

fn number() -> Value {
    json!({"type": "number"})
}

fn integer_min(value: i64) -> Value {
    json!({"type": "integer", "minimum": value})
}

fn boolean() -> Value {
    json!({"type": "boolean"})
}

fn boolean_default(value: bool) -> Value {
    json!({"type": "boolean", "default": value})
}

fn number_default(value: i64) -> Value {
    json!({"type": "number", "default": value})
}

fn string_array() -> Value {
    json!({"type": "array", "items": {"type": "string"}})
}

fn string_array_min() -> Value {
    json!({"type": "array", "items": {"type": "string"}, "minItems": 1})
}

fn allow_missing() -> Value {
    json!({
        "type": "boolean",
        "default": false,
        "description": "When true, missing local paths are returned as non-error missing results."
    })
}

// 4. Public schemas ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
fn read_item_schema() -> Value {
    item_object(
        prop(vec![
            ("path", string()),
            ("isUrl", boolean_default(false)),
            ("offset", number_default(0)),
            ("length", number()),
            (
                "options",
                json!({"type": "object", "additionalProperties": {}}),
            ),
        ]),
        vec!["path"],
    )
}

fn read_schema() -> Value {
    object_schema(
        prop(vec![
            ("allowMissing", allow_missing()),
            ("paths", string_array_min()),
            ("items", array_of(read_item_schema())),
        ]),
        vec![],
    )
}

fn write_item_schema() -> Value {
    item_object(
        prop(vec![
            ("path", string()),
            (
                "content_path",
                json!({"type": "string", "description": "Read UTF-8 content from this file. Preferred for large generated or pasted text."}),
            ),
            (
                "content",
                json!({"type": "string", "description": "Inline text accepted. For very large generated or pasted payloads, content_path or args_path can still reduce transport overhead."}),
            ),
            ("content_offset", number_default(0)),
            ("content_length", number()),
            (
                "mode",
                json!({"type": "string", "enum": ["rewrite", "append"], "default": "rewrite"}),
            ),
        ]),
        vec!["path"],
    )
}

fn write_schema() -> Value {
    object_schema(
        prop(vec![("items", array_of(write_item_schema()))]),
        vec!["items"],
    )
}

fn dir_mk_schema() -> Value {
    object_schema(prop(vec![("paths", string_array_min())]), vec!["paths"])
}

fn dir_item_schema() -> Value {
    item_object(
        prop(vec![
            ("path", string()),
            ("depth", number_default(2)),
            (
                "maxEntries",
                json!({"type": "integer", "exclusiveMinimum": 0}),
            ),
            (
                "excludePatterns",
                json!({"type": "array", "items": {"type": "string"}, "default": []}),
            ),
            ("includeFiles", boolean_default(true)),
        ]),
        vec!["path"],
    )
}

fn dir_list_schema() -> Value {
    object_schema(
        prop(vec![
            ("allowMissing", allow_missing()),
            ("items", array_of(dir_item_schema())),
        ]),
        vec!["items"],
    )
}

fn copy_schema() -> Value {
    object_schema(
        prop(vec![(
            "items",
            array_of(item_object(
                prop(vec![
                    ("source", string()),
                    ("destination", string()),
                    ("recursive", boolean_default(false)),
                    ("force", boolean_default(false)),
                ]),
                vec!["source", "destination"],
            )),
        )]),
        vec!["items"],
    )
}

fn move_schema() -> Value {
    object_schema(
        prop(vec![(
            "items",
            array_of(item_object(
                prop(vec![("source", string()), ("destination", string())]),
                vec!["source", "destination"],
            )),
        )]),
        vec!["items"],
    )
}

fn remove_schema() -> Value {
    object_schema(
        prop(vec![(
            "items",
            array_of(item_object(
                prop(vec![
                    ("path", string()),
                    ("recursive", boolean_default(false)),
                    ("force", boolean_default(false)),
                ]),
                vec!["path"],
            )),
        )]),
        vec!["items"],
    )
}

fn search_start_item_schema() -> Value {
    item_object(
        prop(vec![
            ("path", string()),
            ("pattern", string()),
            ("pattern_path", string()),
            ("pattern_offset", number_default(0)),
            ("pattern_length", number()),
            (
                "searchType",
                json!({"type": "string", "enum": ["files", "content"], "default": "files"}),
            ),
            ("filePattern", string()),
            ("ignoreCase", boolean_default(true)),
            ("maxResults", number()),
            ("includeHidden", boolean_default(false)),
            ("contextLines", number_default(5)),
            ("timeout_ms", number()),
            ("earlyTermination", boolean()),
            ("literalSearch", boolean_default(false)),
        ]),
        vec!["path"],
    )
}

fn search_start_schema() -> Value {
    object_schema(
        prop(vec![("items", array_of(search_start_item_schema()))]),
        vec!["items"],
    )
}

fn search_regex_item_schema() -> Value {
    item_object(
        prop(vec![
            ("path", string()),
            ("pattern", string()),
            ("pattern_path", string()),
            ("pattern_offset", number_default(0)),
            ("pattern_length", number()),
            ("filePattern", string()),
            ("ignoreCase", boolean_default(true)),
            ("maxResults", number()),
            ("includeHidden", boolean_default(false)),
            ("contextLines", number_default(2)),
            ("timeout_ms", number_default(10000)),
        ]),
        vec!["path"],
    )
}

fn search_regex_schema() -> Value {
    object_schema(
        prop(vec![("items", array_of(search_regex_item_schema()))]),
        vec!["items"],
    )
}

fn search_get_schema() -> Value {
    object_schema(
        prop(vec![(
            "items",
            array_of(item_object(
                prop(vec![
                    ("sessionId", string()),
                    ("offset", number_default(0)),
                    ("length", number()),
                ]),
                vec!["sessionId"],
            )),
        )]),
        vec!["items"],
    )
}

fn search_stop_schema() -> Value {
    object_schema(
        prop(vec![("sessionIds", string_array_min())]),
        vec!["sessionIds"],
    )
}

fn evidence_extract_schema() -> Value {
    item_object(
        prop(vec![("name", string()), ("regex", string())]),
        vec!["name", "regex"],
    )
}

fn inspect_request_schema() -> Value {
    item_object(
        prop(vec![
            ("id", string()),
            (
                "op",
                json!({"type": "string", "enum": ["count-files", "search", "json-pick", "snippet"]}),
            ),
            ("path", string()),
            ("glob", string()),
            ("recursive", boolean()),
            ("pattern", string()),
            ("literal", boolean_default(false)),
            ("filePattern", string()),
            ("maxMatches", number_default(20)),
            ("extract", array_of(evidence_extract_schema())),
            ("pointers", string_array()),
            ("patterns", string_array()),
            ("contextLines", number_default(2)),
            ("maxSnippets", number_default(10)),
        ]),
        vec!["op", "path"],
    )
}

fn inspect_schema() -> Value {
    object_schema(
        prop(vec![
            ("root", string()),
            ("requests", array_of(inspect_request_schema())),
            ("maxSnippetChars", number_default(6000)),
            (
                "mode",
                json!({"type": "string", "enum": ["strict", "balanced", "speed"], "default": "strict"}),
            ),
        ]),
        vec!["root", "requests"],
    )
}

fn infos_schema() -> Value {
    object_schema(
        prop(vec![
            ("allowMissing", allow_missing()),
            ("paths", string_array_min()),
        ]),
        vec!["paths"],
    )
}

fn edit_lines_schema() -> Value {
    object_schema(
        prop(vec![(
            "items",
            array_of(item_object(
                prop(vec![
                    ("file_path", string()),
                    ("start_line", number()),
                    ("end_line", number()),
                    ("replacement", string()),
                    ("replacement_path", string()),
                    ("replacement_offset", number_default(0)),
                    ("replacement_length", number()),
                    ("after", boolean_default(false)),
                    ("expected_lines", number()),
                ]),
                vec!["file_path", "start_line"],
            )),
        )]),
        vec!["items"],
    )
}

fn edit_schema() -> Value {
    object_schema(
        prop(vec![(
            "items",
            array_of(item_object(
                prop(vec![
                    ("file_path", string()),
                    ("old_string", string()),
                    ("old_string_path", string()),
                    ("old_string_offset", number_default(0)),
                    ("old_string_length", number()),
                    ("new_string", string()),
                    ("new_string_path", string()),
                    ("new_string_offset", number_default(0)),
                    ("new_string_length", number()),
                    ("expected_replacements", number_default(1)),
                ]),
                vec!["file_path"],
            )),
        )]),
        vec!["items"],
    )
}

fn git_add_schema() -> Value {
    object_schema(
        prop(vec![
            ("path", string()),
            ("paths", string_array()),
            ("all", boolean()),
            ("update", boolean()),
            ("force", boolean()),
        ]),
        vec![],
    )
}

fn git_commit_schema() -> Value {
    object_schema(
        prop(vec![
            ("path", string()),
            ("message", string()),
            ("messagePath", string()),
            ("messageOffset", number_default(0)),
            ("messageLength", number()),
            (
                "author",
                item_object(
                    prop(vec![
                        ("name", json!({"type": "string", "minLength": 1})),
                        ("email", json!({"type": "string", "format": "email"})),
                    ]),
                    vec!["name", "email"],
                ),
            ),
            ("amend", boolean()),
            ("allowEmpty", boolean()),
            ("noVerify", boolean()),
            ("filesToStage", string_array()),
        ]),
        vec![],
    )
}

fn git_diff_schema() -> Value {
    object_schema(
        prop(vec![
            ("path", string()),
            ("target", string()),
            ("source", string()),
            ("paths", string_array()),
            ("staged", boolean()),
            ("includeUntracked", boolean()),
            ("nameOnly", boolean()),
            ("stat", boolean()),
            ("contextLines", integer_min(0)),
            ("autoExclude", boolean()),
        ]),
        vec![],
    )
}

fn git_cwd_schema() -> Value {
    object_schema(
        prop(vec![
            ("path", string()),
            ("validateGitRepo", boolean()),
            ("initializeIfNotPresent", boolean()),
        ]),
        vec!["path"],
    )
}

fn git_show_schema() -> Value {
    object_schema(
        prop(vec![
            ("path", string()),
            ("object", string()),
            ("filePath", string()),
            ("format", json!({"type": "string", "enum": ["raw"]})),
            ("stat", boolean()),
        ]),
        vec!["object"],
    )
}

fn git_status_schema() -> Value {
    object_schema(
        prop(vec![("path", string()), ("includeUntracked", boolean())]),
        vec![],
    )
}

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

    #[test]
    fn exposes_expected_tool_surface() {
        let tools = tool_catalog();
        let mut names = tools
            .iter()
            .map(|tool| tool["name"].as_str().unwrap().to_string())
            .collect::<Vec<_>>();
        names.sort();
        let mut expected = vec![
            "dir-list",
            "dir-mk",
            "file-copy",
            "file-edit",
            "file-edit-lines",
            "file-infos",
            "file-lines",
            "file-move",
            "file-read",
            "file-remove",
            "file-write",
            "git-add",
            "git-commit",
            "git-cwd",
            "git-diff",
            "git-show",
            "git-status",
            "search-get",
            "search-regex",
            "search-start",
            "search-stop",
            "fs-inspect",
        ]
        .into_iter()
        .map(str::to_string)
        .collect::<Vec<_>>();
        expected.sort();
        assert_eq!(names, expected);
        assert!(tools.iter().all(|tool| {
            serde_json::to_string(&tool["inputSchema"])
                .unwrap()
                .contains("args_path")
        }));
    }
}