fallow-mcp 2.32.1

MCP server for the fallow TypeScript/JavaScript codebase analyzer
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
use rmcp::ServerHandler;

use super::super::FallowMcp;

#[test]
fn server_info_is_correct() {
    let server = FallowMcp::new();
    let info = ServerHandler::get_info(&server);
    assert_eq!(info.server_info.name, "fallow-mcp");
    assert_eq!(info.server_info.version, env!("CARGO_PKG_VERSION"));
    assert!(info.capabilities.tools.is_some());
    assert!(info.instructions.is_some());
}

#[test]
fn all_tools_registered() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    let names: Vec<String> = tools.iter().map(|t| t.name.to_string()).collect();
    assert!(names.contains(&"analyze".to_string()));
    assert!(names.contains(&"check_changed".to_string()));
    assert!(names.contains(&"find_dupes".to_string()));
    assert!(names.contains(&"fix_preview".to_string()));
    assert!(names.contains(&"fix_apply".to_string()));
    assert!(names.contains(&"project_info".to_string()));
    assert!(names.contains(&"check_health".to_string()));
    assert!(names.contains(&"audit".to_string()));
    assert!(names.contains(&"list_boundaries".to_string()));
    assert!(names.contains(&"feature_flags".to_string()));
    assert_eq!(tools.len(), 10);
}

#[test]
fn read_only_tools_have_annotations() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    let read_only = [
        "analyze",
        "check_changed",
        "find_dupes",
        "fix_preview",
        "project_info",
        "check_health",
        "audit",
        "list_boundaries",
        "feature_flags",
    ];
    for tool in &tools {
        let name = tool.name.to_string();
        if read_only.contains(&name.as_str()) {
            let ann = tool.annotations.as_ref().expect("annotations");
            assert_eq!(ann.read_only_hint, Some(true), "{name} should be read-only");
        }
    }
}

#[test]
fn fix_apply_is_destructive() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    let fix = tools.iter().find(|t| t.name == "fix_apply").unwrap();
    let ann = fix.annotations.as_ref().unwrap();
    assert_eq!(ann.destructive_hint, Some(true));
    assert_eq!(ann.read_only_hint, Some(false));
}

#[test]
fn all_tools_have_descriptions() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    for tool in &tools {
        let name = tool.name.to_string();
        let desc = tool.description.as_deref().unwrap_or("");
        assert!(
            !desc.is_empty(),
            "tool '{name}' should have a non-empty description"
        );
    }
}

#[test]
fn all_tools_have_annotations() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    for tool in &tools {
        let name = tool.name.to_string();
        assert!(
            tool.annotations.is_some(),
            "tool '{name}' should have annotations"
        );
    }
}

#[test]
fn open_world_hint_on_analysis_tools() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    let open_world = [
        "analyze",
        "check_changed",
        "find_dupes",
        "fix_preview",
        "project_info",
        "check_health",
        "audit",
        "list_boundaries",
        "feature_flags",
    ];
    for tool in &tools {
        let name = tool.name.to_string();
        if open_world.contains(&name.as_str()) {
            let ann = tool.annotations.as_ref().unwrap();
            assert_eq!(
                ann.open_world_hint,
                Some(true),
                "{name} should have open_world_hint=true"
            );
        }
    }
}

#[test]
fn fix_preview_is_not_destructive() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    let preview = tools.iter().find(|t| t.name == "fix_preview").unwrap();
    let ann = preview.annotations.as_ref().unwrap();
    // fix_preview should be read-only (dry-run only)
    assert_eq!(ann.read_only_hint, Some(true));
    assert_ne!(ann.destructive_hint, Some(true));
}

#[test]
fn server_info_has_description() {
    let server = FallowMcp::new();
    let info = ServerHandler::get_info(&server);
    assert!(
        info.server_info
            .description
            .as_ref()
            .is_some_and(|d| !d.is_empty()),
        "server info should have a description"
    );
}

#[test]
fn server_instructions_mention_all_tools() {
    let server = FallowMcp::new();
    let info = ServerHandler::get_info(&server);
    let instructions = info.instructions.as_deref().unwrap();
    assert!(instructions.contains("analyze"));
    assert!(instructions.contains("check_changed"));
    assert!(instructions.contains("find_dupes"));
    assert!(instructions.contains("fix_preview"));
    assert!(instructions.contains("fix_apply"));
    assert!(instructions.contains("project_info"));
    assert!(instructions.contains("check_health"));
    assert!(instructions.contains("audit"));
    assert!(instructions.contains("list_boundaries"));
    assert!(instructions.contains("feature_flags"));
}

#[test]
fn all_tools_have_input_schema() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    for tool in &tools {
        let name = tool.name.to_string();
        // input_schema should be present (JSON Schema object)
        assert!(
            !tool.input_schema.is_empty(),
            "tool '{name}' should have a non-empty input_schema"
        );
    }
}

// ── Schema property validation ────────────────────────────────────

#[test]
fn analyze_schema_contains_expected_properties() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    let tool = tools.iter().find(|t| t.name == "analyze").unwrap();
    let schema = serde_json::to_string(&tool.input_schema).unwrap();
    for prop in [
        "root",
        "config",
        "production",
        "workspace",
        "issue_types",
        "boundary_violations",
        "baseline",
        "save_baseline",
        "no_cache",
        "threads",
    ] {
        assert!(
            schema.contains(prop),
            "analyze schema should contain property '{prop}'"
        );
    }
}

#[test]
fn check_changed_schema_contains_expected_properties() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    let tool = tools.iter().find(|t| t.name == "check_changed").unwrap();
    let schema = serde_json::to_string(&tool.input_schema).unwrap();
    for prop in [
        "root",
        "since",
        "config",
        "production",
        "workspace",
        "baseline",
        "save_baseline",
        "no_cache",
        "threads",
    ] {
        assert!(
            schema.contains(prop),
            "check_changed schema should contain property '{prop}'"
        );
    }
}

#[test]
fn check_changed_schema_requires_since() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    let tool = tools.iter().find(|t| t.name == "check_changed").unwrap();
    let schema = serde_json::to_string(&tool.input_schema).unwrap();
    // "since" should appear in the "required" array
    assert!(
        schema.contains("\"required\""),
        "check_changed schema should have a required array"
    );
    // The required field should reference "since"
    let schema_value: serde_json::Value = serde_json::from_str(&schema).unwrap();
    if let Some(required) = schema_value.get("required").and_then(|r| r.as_array()) {
        assert!(
            required.iter().any(|v| v.as_str() == Some("since")),
            "check_changed schema should require 'since'"
        );
    }
}

#[test]
fn find_dupes_schema_contains_expected_properties() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    let tool = tools.iter().find(|t| t.name == "find_dupes").unwrap();
    let schema = serde_json::to_string(&tool.input_schema).unwrap();
    for prop in [
        "root",
        "config",
        "workspace",
        "mode",
        "min_tokens",
        "min_lines",
        "threshold",
        "skip_local",
        "cross_language",
        "top",
        "baseline",
        "save_baseline",
        "no_cache",
        "threads",
        "changed_since",
    ] {
        assert!(
            schema.contains(prop),
            "find_dupes schema should contain property '{prop}'"
        );
    }
}

#[test]
fn fix_preview_schema_contains_expected_properties() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    let tool = tools.iter().find(|t| t.name == "fix_preview").unwrap();
    let schema = serde_json::to_string(&tool.input_schema).unwrap();
    for prop in [
        "root",
        "config",
        "production",
        "workspace",
        "no_cache",
        "threads",
    ] {
        assert!(
            schema.contains(prop),
            "fix_preview schema should contain property '{prop}'"
        );
    }
}

#[test]
fn fix_apply_schema_contains_expected_properties() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    let tool = tools.iter().find(|t| t.name == "fix_apply").unwrap();
    let schema = serde_json::to_string(&tool.input_schema).unwrap();
    for prop in [
        "root",
        "config",
        "production",
        "workspace",
        "no_cache",
        "threads",
    ] {
        assert!(
            schema.contains(prop),
            "fix_apply schema should contain property '{prop}'"
        );
    }
}

#[test]
fn project_info_schema_contains_expected_properties() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    let tool = tools.iter().find(|t| t.name == "project_info").unwrap();
    let schema = serde_json::to_string(&tool.input_schema).unwrap();
    for prop in [
        "root",
        "config",
        "entry_points",
        "files",
        "plugins",
        "boundaries",
        "no_cache",
        "threads",
    ] {
        assert!(
            schema.contains(prop),
            "project_info schema should contain property '{prop}'"
        );
    }
}

#[test]
fn check_health_schema_contains_expected_properties() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    let tool = tools.iter().find(|t| t.name == "check_health").unwrap();
    let schema = serde_json::to_string(&tool.input_schema).unwrap();
    for prop in [
        "root",
        "config",
        "max_cyclomatic",
        "max_cognitive",
        "top",
        "sort",
        "changed_since",
        "complexity",
        "file_scores",
        "hotspots",
        "targets",
        "since",
        "min_commits",
        "workspace",
        "production",
        "save_snapshot",
        "baseline",
        "save_baseline",
        "no_cache",
        "threads",
    ] {
        assert!(
            schema.contains(prop),
            "check_health schema should contain property '{prop}'"
        );
    }
}

#[test]
fn audit_schema_contains_expected_properties() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    let tool = tools.iter().find(|t| t.name == "audit").unwrap();
    let schema = serde_json::to_string(&tool.input_schema).unwrap();
    for prop in [
        "root",
        "config",
        "base",
        "production",
        "workspace",
        "no_cache",
        "threads",
    ] {
        assert!(
            schema.contains(prop),
            "audit schema should contain property '{prop}'"
        );
    }
}

#[test]
fn list_boundaries_schema_contains_expected_properties() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    let tool = tools.iter().find(|t| t.name == "list_boundaries").unwrap();
    let schema = serde_json::to_string(&tool.input_schema).unwrap();
    for prop in ["root", "config", "no_cache", "threads"] {
        assert!(
            schema.contains(prop),
            "list_boundaries schema should contain property '{prop}'"
        );
    }
}

#[test]
fn feature_flags_schema_contains_expected_properties() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    let tool = tools.iter().find(|t| t.name == "feature_flags").unwrap();
    let schema = serde_json::to_string(&tool.input_schema).unwrap();
    for prop in [
        "root",
        "config",
        "production",
        "workspace",
        "flag_type",
        "confidence",
        "no_cache",
        "threads",
    ] {
        assert!(
            schema.contains(prop),
            "feature_flags schema should contain property '{prop}'"
        );
    }
}

// ── fix_apply is not open_world ───────────────────────────────────

#[test]
fn fix_apply_does_not_have_open_world_hint() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    let fix = tools.iter().find(|t| t.name == "fix_apply").unwrap();
    let ann = fix.annotations.as_ref().unwrap();
    // fix_apply is destructive, should not have open_world_hint=true
    assert_ne!(
        ann.open_world_hint,
        Some(true),
        "fix_apply should not have open_world_hint=true"
    );
}

// ── Tool descriptions mention key behaviors ───────────────────────

#[test]
fn analyze_description_mentions_unused_code() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    let tool = tools.iter().find(|t| t.name == "analyze").unwrap();
    let desc = tool.description.as_deref().unwrap();
    assert!(
        desc.contains("unused"),
        "analyze description should mention 'unused'"
    );
}

#[test]
fn find_dupes_description_mentions_duplication() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    let tool = tools.iter().find(|t| t.name == "find_dupes").unwrap();
    let desc = tool.description.as_deref().unwrap();
    assert!(
        desc.contains("duplic"),
        "find_dupes description should mention duplication"
    );
}

#[test]
fn check_health_description_mentions_complexity() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    let tool = tools.iter().find(|t| t.name == "check_health").unwrap();
    let desc = tool.description.as_deref().unwrap();
    assert!(
        desc.contains("complexity"),
        "check_health description should mention 'complexity'"
    );
}

#[test]
fn fix_apply_description_warns_about_modification() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    let tool = tools.iter().find(|t| t.name == "fix_apply").unwrap();
    let desc = tool.description.as_deref().unwrap();
    assert!(
        desc.contains("modif") || desc.contains("disk") || desc.contains("destructi"),
        "fix_apply description should warn about file modification"
    );
}

#[test]
fn fix_preview_description_mentions_dry_run_or_preview() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    let tool = tools.iter().find(|t| t.name == "fix_preview").unwrap();
    let desc = tool.description.as_deref().unwrap();
    assert!(
        desc.contains("preview") || desc.contains("dry") || desc.contains("without modif"),
        "fix_preview description should mention preview/dry-run behavior"
    );
}

// ── All schemas are valid JSON objects ─────────────────────────────

#[test]
fn all_tool_schemas_are_json_objects() {
    let server = FallowMcp::new();
    let tools = server.tool_router.list_all();
    for tool in &tools {
        let name = tool.name.to_string();
        let schema_str = serde_json::to_string(&tool.input_schema).unwrap();
        let schema_value: serde_json::Value = serde_json::from_str(&schema_str).unwrap();
        assert!(
            schema_value.is_object(),
            "tool '{name}' schema should be a JSON object"
        );
        // Should have "type": "object" at the top level
        assert_eq!(
            schema_value.get("type").and_then(|t| t.as_str()),
            Some("object"),
            "tool '{name}' schema should have type=object"
        );
    }
}

// ── Server can be cloned (required for rmcp runtime) ───────────────

#[test]
fn server_is_cloneable() {
    let server = FallowMcp::new();
    // Use clone in a way that isn't redundant — verify both instances work
    let cloned = server.clone();
    let tools_original = server.tool_router.list_all();
    let tools_cloned = cloned.tool_router.list_all();
    assert_eq!(tools_original.len(), tools_cloned.len());
}