m1nd-mcp 0.8.0

MCP Server for m1nd. Stop letting AI grep your codebase. Neuro-symbolic connectome for AI agents.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
// === m1nd-mcp/src/protocol/perspective.rs ===
// Input/Output types for the 12 perspective MCP tools.
// From 12-PERSPECTIVE-SYNTHESIS, PRD sections 5-14.

use serde::{Deserialize, Serialize};

use crate::perspective::state::{
    AffinityCandidate, Diagnostic, PeekContent, PerspectiveLens, PerspectiveMode, Route,
    RouteFamily, SuggestResult,
};

// ---------------------------------------------------------------------------
// perspective.start (PRD §6)
// ---------------------------------------------------------------------------

#[derive(Clone, Debug, Deserialize)]
pub struct PerspectiveStartInput {
    pub agent_id: String,
    /// Seed query for route synthesis.
    pub query: String,
    /// Optional: anchor to a specific node (activates anchored mode).
    #[serde(default)]
    pub anchor_node: Option<String>,
    /// Optional: starting lens configuration.
    #[serde(default)]
    pub lens: Option<PerspectiveLens>,
}

#[derive(Clone, Debug, Serialize)]
pub struct PerspectiveStartOutput {
    pub perspective_id: String,
    pub mode: PerspectiveMode,
    pub anchor_node: Option<String>,
    pub focus_node: Option<String>,
    /// Initial route set (first page).
    pub routes: Vec<Route>,
    pub total_routes: usize,
    pub page: u32,
    pub total_pages: u32,
    pub route_set_version: u64,
    pub cache_generation: u64,
    pub suggested: Option<String>, // e.g. "inspect R03"
    pub proof_state: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_suggested_tool: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_suggested_target: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_step_hint: Option<String>,
}

// ---------------------------------------------------------------------------
// perspective.routes (PRD §7)
// ---------------------------------------------------------------------------

#[derive(Clone, Debug, Deserialize)]
pub struct PerspectiveRoutesInput {
    pub agent_id: String,
    pub perspective_id: String,
    /// Page number (1-based). Default: 1. Must be >= 1.
    #[serde(default = "default_page")]
    pub page: u32,
    /// Page size. Clamped to [1, 10]. Default: 6.
    #[serde(default = "default_page_size")]
    pub page_size: u32,
    /// Required: route_set_version from previous response. Staleness check.
    #[serde(default)]
    pub route_set_version: Option<u64>,
}

#[derive(Clone, Debug, Serialize)]
pub struct PerspectiveRoutesOutput {
    pub perspective_id: String,
    pub mode: PerspectiveMode,
    pub mode_effective: String, // "anchored" or "local" (degraded if >8 hops from anchor)
    pub anchor: Option<String>,
    pub focus: Option<String>,
    pub lens_summary: String, // compact one-line lens description
    pub page: u32,
    pub total_pages: u32,
    pub total_routes: usize,
    pub route_set_version: u64,
    pub cache_generation: u64,
    pub routes: Vec<Route>,
    pub suggested: Option<String>,
    /// Diagnostic if routes are empty (Theme 12).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub diagnostic: Option<Diagnostic>,
    /// Warning if all routes are from one family.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub family_diversity_warning: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub dominant_family: Option<RouteFamily>,
    /// Whether page_size was clamped.
    #[serde(default)]
    pub page_size_clamped: bool,
    pub proof_state: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_suggested_tool: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_suggested_target: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_step_hint: Option<String>,
}

// ---------------------------------------------------------------------------
// perspective.inspect (PRD §9)
// ---------------------------------------------------------------------------

#[derive(Clone, Debug, Deserialize)]
pub struct PerspectiveInspectInput {
    pub agent_id: String,
    pub perspective_id: String,
    /// Exactly one of route_id or route_index must be provided.
    #[serde(default)]
    pub route_id: Option<String>,
    #[serde(default)]
    pub route_index: Option<u32>,
    /// Route set version for staleness check.
    pub route_set_version: u64,
}

#[derive(Clone, Debug, Serialize)]
pub struct PerspectiveInspectOutput {
    pub route_id: String,
    pub route_index: u32,
    pub family: RouteFamily,
    pub target_node: String,
    pub target_label: String,
    pub target_type: String,
    /// Fuller path preview.
    pub path_preview: Vec<String>,
    /// Route family explanation.
    pub family_explanation: String,
    /// Stronger metrics than the route list.
    pub score: f32,
    pub score_breakdown: InspectScoreBreakdown,
    /// Provenance summary.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub provenance: Option<InspectProvenance>,
    /// Whether peek is available.
    pub peek_available: bool,
    /// Affinity candidates for this route (Theme 12).
    pub affinity_candidates: Vec<AffinityCandidate>,
    /// Total chars in this response (for Theme 5 cap enforcement).
    pub response_chars: usize,
    pub proof_state: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_suggested_tool: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_suggested_target: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_step_hint: Option<String>,
}

#[derive(Clone, Debug, Serialize)]
pub struct InspectScoreBreakdown {
    pub local_activation: f32,
    pub path_coherence: f32,
    pub novelty: f32,
    pub anchor_relevance: Option<f32>, // None in local mode
    pub continuity: Option<f32>,       // None in local mode
}

#[derive(Clone, Debug, Serialize)]
pub struct InspectProvenance {
    pub source_path: Option<String>,
    pub line_start: Option<u32>,
    pub line_end: Option<u32>,
    pub namespace: Option<String>,
    pub provenance_stale: bool,
}

// ---------------------------------------------------------------------------
// perspective.peek (PRD §10)
// ---------------------------------------------------------------------------

#[derive(Clone, Debug, Deserialize)]
pub struct PerspectivePeekInput {
    pub agent_id: String,
    pub perspective_id: String,
    /// Exactly one of route_id or route_index must be provided.
    #[serde(default)]
    pub route_id: Option<String>,
    #[serde(default)]
    pub route_index: Option<u32>,
    /// Route set version for staleness check.
    pub route_set_version: u64,
}

#[derive(Clone, Debug, Serialize)]
pub struct PerspectivePeekOutput {
    pub route_id: String,
    pub route_index: u32,
    pub target_node: String,
    /// Security-checked peek content.
    pub content: PeekContent,
    pub proof_state: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_suggested_tool: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_suggested_target: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_step_hint: Option<String>,
}

// ---------------------------------------------------------------------------
// perspective.follow (PRD §8 implied)
// ---------------------------------------------------------------------------

#[derive(Clone, Debug, Deserialize)]
pub struct PerspectiveFollowInput {
    pub agent_id: String,
    pub perspective_id: String,
    /// Exactly one of route_id or route_index must be provided.
    #[serde(default)]
    pub route_id: Option<String>,
    #[serde(default)]
    pub route_index: Option<u32>,
    /// Route set version for staleness check.
    pub route_set_version: u64,
}

#[derive(Clone, Debug, Serialize)]
pub struct PerspectiveFollowOutput {
    pub perspective_id: String,
    pub previous_focus: Option<String>,
    pub new_focus: String,
    pub mode: PerspectiveMode,
    pub mode_effective: String,
    /// New routes from the new focus.
    pub routes: Vec<Route>,
    pub total_routes: usize,
    pub page: u32,
    pub total_pages: u32,
    pub route_set_version: u64,
    pub cache_generation: u64,
    pub suggested: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub diagnostic: Option<Diagnostic>,
    pub proof_state: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_suggested_tool: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_suggested_target: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_step_hint: Option<String>,
}

// ---------------------------------------------------------------------------
// perspective.suggest (PRD §11)
// ---------------------------------------------------------------------------

#[derive(Clone, Debug, Deserialize)]
pub struct PerspectiveSuggestInput {
    pub agent_id: String,
    pub perspective_id: String,
    /// Route set version for staleness check.
    pub route_set_version: u64,
}

#[derive(Clone, Debug, Serialize)]
pub struct PerspectiveSuggestOutput {
    pub perspective_id: String,
    pub suggestion: SuggestResult,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub diagnostic: Option<Diagnostic>,
    pub proof_state: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_suggested_tool: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_suggested_target: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_step_hint: Option<String>,
}

// ---------------------------------------------------------------------------
// perspective.affinity (PRD §12)
// ---------------------------------------------------------------------------

#[derive(Clone, Debug, Deserialize)]
pub struct PerspectiveAffinityInput {
    pub agent_id: String,
    pub perspective_id: String,
    /// Exactly one of route_id or route_index must be provided.
    #[serde(default)]
    pub route_id: Option<String>,
    #[serde(default)]
    pub route_index: Option<u32>,
    /// Route set version for staleness check.
    pub route_set_version: u64,
}

#[derive(Clone, Debug, Serialize)]
pub struct PerspectiveAffinityOutput {
    pub route_id: String,
    pub target_node: String,
    /// Epistemic notice (Theme 13).
    pub notice: String, // "Probable connections, not verified edges."
    /// Up to 8 candidates (Theme 5 cap). Min threshold: 0.15.
    pub candidates: Vec<AffinityCandidate>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub diagnostic: Option<Diagnostic>,
    pub proof_state: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_suggested_tool: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_suggested_target: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_step_hint: Option<String>,
}

// ---------------------------------------------------------------------------
// perspective.branch (PRD implied)
// ---------------------------------------------------------------------------

#[derive(Clone, Debug, Deserialize)]
pub struct PerspectiveBranchInput {
    pub agent_id: String,
    pub perspective_id: String,
    /// Optional branch name. Auto-generated if not provided.
    #[serde(default)]
    pub branch_name: Option<String>,
}

#[derive(Clone, Debug, Serialize)]
pub struct PerspectiveBranchOutput {
    pub perspective_id: String,
    /// The new branch's perspective_id.
    pub branch_perspective_id: String,
    pub branch_name: String,
    pub branched_from_focus: Option<String>,
    pub proof_state: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_suggested_tool: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_suggested_target: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_step_hint: Option<String>,
}

// ---------------------------------------------------------------------------
// perspective.back (PRD §14.2)
// ---------------------------------------------------------------------------

#[derive(Clone, Debug, Deserialize)]
pub struct PerspectiveBackInput {
    pub agent_id: String,
    pub perspective_id: String,
}

#[derive(Clone, Debug, Serialize)]
pub struct PerspectiveBackOutput {
    pub perspective_id: String,
    pub restored_focus: Option<String>,
    pub restored_mode: PerspectiveMode,
    /// New routes from the restored focus.
    pub routes: Vec<Route>,
    pub total_routes: usize,
    pub page: u32,
    pub total_pages: u32,
    pub route_set_version: u64,
    pub cache_generation: u64,
    pub proof_state: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_suggested_tool: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_suggested_target: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_step_hint: Option<String>,
}

// ---------------------------------------------------------------------------
// perspective.compare (PRD §9 implied)
// ---------------------------------------------------------------------------

#[derive(Clone, Debug, Deserialize)]
pub struct PerspectiveCompareInput {
    pub agent_id: String,
    /// Two perspective IDs to compare. Must be same agent (V1 restriction).
    pub perspective_id_a: String,
    pub perspective_id_b: String,
    /// Dimensions to compare on. Empty = all.
    #[serde(default)]
    pub dimensions: Vec<String>,
}

#[derive(Clone, Debug, Serialize)]
pub struct PerspectiveCompareOutput {
    pub perspective_id_a: String,
    pub perspective_id_b: String,
    pub shared_nodes: Vec<String>,
    pub unique_to_a: Vec<String>,
    pub unique_to_b: Vec<String>,
    pub dimension_deltas: Vec<DimensionDelta>,
    /// Total chars (for Theme 5 cap of 3000).
    pub response_chars: usize,
    /// Warning if comparing across different generations.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub generation_mismatch_warning: Option<String>,
    pub proof_state: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_suggested_tool: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_suggested_target: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_step_hint: Option<String>,
}

#[derive(Clone, Debug, Serialize)]
pub struct DimensionDelta {
    pub dimension: String,
    pub score_a: f32,
    pub score_b: f32,
    pub delta: f32,
}

// ---------------------------------------------------------------------------
// perspective.list (Theme 2 — management tool)
// ---------------------------------------------------------------------------

#[derive(Clone, Debug, Deserialize)]
pub struct PerspectiveListInput {
    pub agent_id: String,
}

#[derive(Clone, Debug, Serialize)]
pub struct PerspectiveListOutput {
    pub agent_id: String,
    pub perspectives: Vec<PerspectiveSummary>,
    pub total_memory_bytes: usize,
    pub proof_state: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_suggested_tool: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_suggested_target: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_step_hint: Option<String>,
}

#[derive(Clone, Debug, Serialize)]
pub struct PerspectiveSummary {
    pub perspective_id: String,
    pub mode: PerspectiveMode,
    pub focus_node: Option<String>,
    pub route_count: usize,
    pub nav_event_count: usize,
    pub stale: bool,
    pub created_at_ms: u64,
    pub last_accessed_ms: u64,
}

// ---------------------------------------------------------------------------
// perspective.close (Theme 2 — management tool)
// ---------------------------------------------------------------------------

#[derive(Clone, Debug, Deserialize)]
pub struct PerspectiveCloseInput {
    pub agent_id: String,
    pub perspective_id: String,
}

#[derive(Clone, Debug, Serialize)]
pub struct PerspectiveCloseOutput {
    pub perspective_id: String,
    pub closed: bool,
    /// Locks that were cascade-released (Theme 5).
    pub locks_released: Vec<String>,
    pub proof_state: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_suggested_tool: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_suggested_target: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_step_hint: Option<String>,
}

// ---------------------------------------------------------------------------
// Default helpers
// ---------------------------------------------------------------------------

fn default_page() -> u32 {
    1
}

fn default_page_size() -> u32 {
    6
}

// ---------------------------------------------------------------------------
// Tests
// ---------------------------------------------------------------------------

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

    #[test]
    fn start_input_deserializes_minimal() {
        let json = r#"{"agent_id": "jimi", "query": "session management"}"#;
        let input: PerspectiveStartInput = serde_json::from_str(json).unwrap();
        assert_eq!(input.agent_id, "jimi");
        assert_eq!(input.query, "session management");
        assert!(input.anchor_node.is_none());
        assert!(input.lens.is_none());
    }

    #[test]
    fn routes_input_defaults() {
        let json = r#"{"agent_id": "jimi", "perspective_id": "persp_jimi_001"}"#;
        let input: PerspectiveRoutesInput = serde_json::from_str(json).unwrap();
        assert_eq!(input.page, 1);
        assert_eq!(input.page_size, 6);
    }

    #[test]
    fn inspect_input_requires_route_ref() {
        // Both route_id and route_index are optional at serde level;
        // validation layer rejects if neither is provided.
        let json = r#"{"agent_id": "jimi", "perspective_id": "p1", "route_set_version": 100}"#;
        let input: PerspectiveInspectInput = serde_json::from_str(json).unwrap();
        assert!(input.route_id.is_none());
        assert!(input.route_index.is_none());
    }

    #[test]
    fn follow_input_accepts_route_id() {
        let json = r#"{"agent_id": "jimi", "perspective_id": "p1", "route_id": "R_abc123", "route_set_version": 100}"#;
        let input: PerspectiveFollowInput = serde_json::from_str(json).unwrap();
        assert_eq!(input.route_id.as_deref(), Some("R_abc123"));
    }

    #[test]
    fn compare_input_deserializes() {
        let json = r#"{"agent_id": "jimi", "perspective_id_a": "p1", "perspective_id_b": "p2"}"#;
        let input: PerspectiveCompareInput = serde_json::from_str(json).unwrap();
        assert!(input.dimensions.is_empty()); // empty = all
    }
}