m1nd-mcp 0.2.0

MCP server for m1nd — 43 tools for AI agents to understand code structure
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
// === m1nd-mcp/src/brand.rs ===
//
// m1nd visual identity system.
// Unicode brand symbols chosen by the creator to represent the neuro-symbolic
// nature of m1nd — circuits, graphs, connections, dimensions.
//
// The glyphs ARE the name: ⍌⍐⍂𝔻 ⟁
// No text needed. Each symbol maps to a semantic domain.
//
// Symbol semantics:
//   ⍌  signal / flow       — activation, spreading, ingest, learn, warmup
//   ⍐  path / trace        — why, trace, timeline, routes, seek
//   ⍂  structure / holes   — missing, fingerprint, scan, topology, diverge
//   𝔻  dimension / analysis — impact, predict, counterfactual, differential, hypothesize
//   ⟁  connection / graph  — perspective, federation, resonance
//
// State tools (health, locks, trails, drift) use ⍂ as their glyph.

// ---------------------------------------------------------------------------
// Core symbols
// ---------------------------------------------------------------------------

/// Signal / flow — spreading activation, data flowing through the graph.
pub const SYM_SIGNAL: &str = "\u{234C}"; //
/// Path / trace — following connections, tracing dependencies.
pub const SYM_PATH: &str = "\u{2350}"; //
/// Structure / holes — structural analysis, gap detection, topology.
pub const SYM_STRUCTURE: &str = "\u{2342}"; //
/// Dimension / analysis — multi-dimensional impact, prediction, what-if.
pub const SYM_DIMENSION: &str = "\u{1D53B}"; // 𝔻

/// State / grid — system state, locks, trails, health status.
pub const SYM_STATE: &str = "\u{1F062}"; // 🁢

/// Connection / graph — perspectives, federation, resonance harmonics.
pub const SYM_CONNECTION: &str = "\u{27C1}"; //
// ---------------------------------------------------------------------------
// Composite banners
// ---------------------------------------------------------------------------

/// Full banner: the glyphs ARE the name. No text needed.
pub const BANNER: &str = "\u{234C}\u{2350}\u{2342}\u{1D53B} \u{27C1}";

/// Compact signature for log lines.
pub const SIG: &str = "\u{234C}\u{2350}\u{2342}\u{1D53B}\u{27C1}";

// ---------------------------------------------------------------------------
// Tool → symbol mapping
// ---------------------------------------------------------------------------

/// Returns the brand symbol prefix for a given tool name.
/// Used to stamp every tool response with a semantic identity marker.
pub fn tool_glyph(tool_name: &str) -> &'static str {
    match tool_name {
        // ⍌ signal / flow
        "m1nd.activate" => SYM_SIGNAL,
        "m1nd.ingest" => SYM_SIGNAL,
        "m1nd.learn" => SYM_SIGNAL,
        "m1nd.warmup" => SYM_SIGNAL,

        // ⍐ path / trace
        "m1nd.why" => SYM_PATH,
        "m1nd.trace" => SYM_PATH,
        "m1nd.timeline" => SYM_PATH,
        "m1nd.seek" => SYM_PATH,

        // ⍂ structure / holes
        "m1nd.missing" => SYM_STRUCTURE,
        "m1nd.fingerprint" => SYM_STRUCTURE,
        "m1nd.scan" => SYM_STRUCTURE,
        "m1nd.diverge" => SYM_STRUCTURE,

        // 𝔻 dimension / analysis
        "m1nd.impact" => SYM_DIMENSION,
        "m1nd.predict" => SYM_DIMENSION,
        "m1nd.counterfactual" => SYM_DIMENSION,
        "m1nd.differential" => SYM_DIMENSION,
        "m1nd.hypothesize" => SYM_DIMENSION,

        // 🁢 state / grid
        "m1nd.health" => SYM_STATE,
        "m1nd.drift" => SYM_STATE,
        "m1nd.lock.create" => SYM_STATE,
        "m1nd.lock.watch" => SYM_STATE,
        "m1nd.lock.diff" => SYM_STATE,
        "m1nd.lock.rebase" => SYM_STATE,
        "m1nd.lock.release" => SYM_STATE,
        "m1nd.trail.save" => SYM_STATE,
        "m1nd.trail.resume" => SYM_STATE,
        "m1nd.trail.merge" => SYM_STATE,
        "m1nd.trail.list" => SYM_STATE,
        "m1nd.validate.plan" => SYM_STATE,

        // ⟁ connection / graph
        "m1nd.resonate" => SYM_CONNECTION,
        "m1nd.federate" => SYM_CONNECTION,
        "m1nd.perspective.start" => SYM_CONNECTION,
        "m1nd.perspective.routes" => SYM_CONNECTION,
        "m1nd.perspective.inspect" => SYM_CONNECTION,
        "m1nd.perspective.peek" => SYM_CONNECTION,
        "m1nd.perspective.follow" => SYM_CONNECTION,
        "m1nd.perspective.suggest" => SYM_CONNECTION,
        "m1nd.perspective.affinity" => SYM_CONNECTION,
        "m1nd.perspective.branch" => SYM_CONNECTION,
        "m1nd.perspective.back" => SYM_CONNECTION,
        "m1nd.perspective.compare" => SYM_CONNECTION,
        "m1nd.perspective.list" => SYM_CONNECTION,
        "m1nd.perspective.close" => SYM_CONNECTION,

        // fallback
        _ => SIG,
    }
}

/// Returns a short human-readable category tag for the tool's semantic domain.
pub fn tool_domain(tool_name: &str) -> &'static str {
    match tool_name {
        "m1nd.activate" | "m1nd.ingest" | "m1nd.learn" | "m1nd.warmup" => "signal",
        "m1nd.why" | "m1nd.trace" | "m1nd.timeline" | "m1nd.seek" => "path",
        "m1nd.missing" | "m1nd.fingerprint" | "m1nd.scan" | "m1nd.diverge" => "structure",
        "m1nd.impact"
        | "m1nd.predict"
        | "m1nd.counterfactual"
        | "m1nd.differential"
        | "m1nd.hypothesize" => "dimension",
        "m1nd.health" | "m1nd.drift" | "m1nd.validate.plan" => "state",
        name if name.starts_with("m1nd.lock.") => "state",
        name if name.starts_with("m1nd.trail.") => "state",
        "m1nd.resonate" | "m1nd.federate" => "connection",
        name if name.starts_with("m1nd.perspective.") => "connection",
        _ => "signal",
    }
}

/// Stamp a JSON result value with the m1nd brand identity.
///
/// Injects a `_m1nd` key at the top level of the JSON object containing:
/// - `glyph`: the semantic symbol for this tool
/// - `tool`: the tool name
/// - `domain`: the semantic domain category
///
/// If the value is not an object, wraps it in one.
pub fn stamp(tool_name: &str, mut value: serde_json::Value) -> serde_json::Value {
    let glyph = tool_glyph(tool_name);
    let domain = tool_domain(tool_name);

    // Extract the short tool name (e.g. "activate" from "m1nd.activate")
    let short_name = tool_name.strip_prefix("m1nd.").unwrap_or(tool_name);

    let brand_meta = serde_json::json!({
        "glyph": glyph,
        "tool": short_name,
        "domain": domain,
    });

    match value {
        serde_json::Value::Object(ref mut map) => {
            map.insert("_m1nd".to_string(), brand_meta);
            value
        }
        other => {
            serde_json::json!({
                "_m1nd": brand_meta,
                "data": other,
            })
        }
    }
}

/// Format a branded text header line for the MCP text content.
/// Example: "⍌ activate — \"query\" — 15 results in 31ms"
pub fn header(tool_name: &str, detail: &str) -> String {
    let glyph = tool_glyph(tool_name);
    let short_name = tool_name.strip_prefix("m1nd.").unwrap_or(tool_name);
    format!("{} {} \u{2014} {}", glyph, short_name, detail)
}

/// Format a branded error line.
/// Example: "⍌⍐⍂𝔻⟁ error — tool not found: foo"
pub fn error_line(detail: &str) -> String {
    format!("{} error \u{2014} {}", SIG, detail)
}

/// Format a branded stderr log line.
/// Example: "[⍌⍐⍂𝔻⟁] Server ready. 4927 nodes, 12345 edges"
pub fn log(msg: &str) -> String {
    format!("[{}] {}", SIG, msg)
}

// ---------------------------------------------------------------------------
// ANSI-colored output for terminal (stderr)
// ---------------------------------------------------------------------------

/// ANSI-colored banner for terminal startup.
/// Each symbol gets a distinct color — the spectrum IS the identity.
pub fn banner_colored() -> String {
    format!(
        "\x1b[36m{}\x1b[33m{}\x1b[35m{}\x1b[34m{}\x1b[0m \x1b[32m{}\x1b[0m",
        SYM_SIGNAL,     // cyan    ⍌
        SYM_PATH,       // yellow  ⍐
        SYM_STRUCTURE,  // magenta ⍂
        SYM_DIMENSION,  // blue    𝔻
        SYM_CONNECTION, // green   ⟁
    )
}

/// ANSI-colored compact signature for log prefixes.
pub fn sig_colored() -> String {
    format!(
        "\x1b[36m{}\x1b[33m{}\x1b[35m{}\x1b[34m{}\x1b[32m{}\x1b[0m",
        SYM_SIGNAL, SYM_PATH, SYM_STRUCTURE, SYM_DIMENSION, SYM_CONNECTION,
    )
}

/// Colored log line for stderr.
pub fn log_colored(msg: &str) -> String {
    format!("[{}] {}", sig_colored(), msg)
}

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

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

    #[test]
    fn tool_glyph_covers_all_core_tools() {
        // Verify no core tool falls through to the fallback
        let core_tools = [
            "m1nd.activate",
            "m1nd.impact",
            "m1nd.missing",
            "m1nd.why",
            "m1nd.warmup",
            "m1nd.counterfactual",
            "m1nd.predict",
            "m1nd.fingerprint",
            "m1nd.drift",
            "m1nd.learn",
            "m1nd.ingest",
            "m1nd.resonate",
            "m1nd.health",
        ];
        for tool in &core_tools {
            let glyph = tool_glyph(tool);
            assert_ne!(
                glyph, SIG,
                "Core tool {} should have a specific glyph, not fallback",
                tool
            );
        }
    }

    #[test]
    fn tool_glyph_covers_layer_tools() {
        let layer_tools = [
            "m1nd.seek",
            "m1nd.scan",
            "m1nd.timeline",
            "m1nd.diverge",
            "m1nd.trace",
            "m1nd.hypothesize",
            "m1nd.differential",
            "m1nd.federate",
            "m1nd.validate.plan",
        ];
        for tool in &layer_tools {
            let glyph = tool_glyph(tool);
            assert_ne!(
                glyph, SIG,
                "Layer tool {} should have a specific glyph",
                tool
            );
        }
    }

    #[test]
    fn tool_glyph_covers_perspective_tools() {
        let perspective_tools = [
            "m1nd.perspective.start",
            "m1nd.perspective.routes",
            "m1nd.perspective.follow",
            "m1nd.perspective.close",
        ];
        for tool in &perspective_tools {
            assert_eq!(tool_glyph(tool), SYM_CONNECTION);
        }
    }

    #[test]
    fn tool_glyph_covers_lock_tools() {
        let lock_tools = [
            "m1nd.lock.create",
            "m1nd.lock.watch",
            "m1nd.lock.diff",
            "m1nd.lock.rebase",
            "m1nd.lock.release",
        ];
        for tool in &lock_tools {
            assert_eq!(tool_glyph(tool), SYM_STATE);
        }
    }

    #[test]
    fn tool_glyph_covers_trail_tools() {
        let trail_tools = [
            "m1nd.trail.save",
            "m1nd.trail.resume",
            "m1nd.trail.merge",
            "m1nd.trail.list",
        ];
        for tool in &trail_tools {
            assert_eq!(tool_glyph(tool), SYM_STATE);
        }
    }

    #[test]
    fn stamp_injects_brand_on_object() {
        let val = serde_json::json!({"query": "test", "results": 5});
        let stamped = stamp("m1nd.activate", val);
        let m = stamped.get("_m1nd").expect("_m1nd field must exist");
        assert_eq!(m["glyph"].as_str().unwrap(), SYM_SIGNAL);
        assert_eq!(m["tool"].as_str().unwrap(), "activate");
        assert_eq!(m["domain"].as_str().unwrap(), "signal");
        // Original fields preserved
        assert_eq!(stamped["query"].as_str().unwrap(), "test");
    }

    #[test]
    fn stamp_wraps_non_object() {
        let val = serde_json::json!(42);
        let stamped = stamp("m1nd.health", val);
        assert!(stamped.get("_m1nd").is_some());
        assert_eq!(stamped["data"], 42);
    }

    #[test]
    fn header_format() {
        let h = header(
            "m1nd.activate",
            "\"chat_handler\" \u{2014} 15 results in 31ms",
        );
        assert!(h.starts_with(SYM_SIGNAL));
        assert!(h.contains("activate"));
        // No "m1nd" text — glyphs ARE the identity
        assert!(!h.contains("m1nd."));
    }

    #[test]
    fn error_line_format() {
        let e = error_line("tool not found: foo");
        assert!(e.starts_with(SIG));
        assert!(e.contains("error"));
        assert!(!e.contains("m1nd"));
    }

    #[test]
    fn log_format() {
        let l = log("Server ready");
        assert!(l.contains(SIG));
        assert!(l.contains("Server ready"));
        // Pure glyph identity — no text name
        assert!(!l.contains("m1nd"));
    }

    #[test]
    fn banner_is_pure_glyphs() {
        assert!(BANNER.contains(SYM_SIGNAL));
        assert!(BANNER.contains(SYM_PATH));
        assert!(BANNER.contains(SYM_STRUCTURE));
        assert!(BANNER.contains(SYM_DIMENSION));
        assert!(BANNER.contains(SYM_CONNECTION));
        // No text — glyphs ARE the name
        assert!(!BANNER.contains("m1nd"));
    }

    #[test]
    fn colored_output_contains_ansi() {
        let bc = banner_colored();
        assert!(bc.contains("\x1b["));
        assert!(bc.contains(SYM_SIGNAL));
        assert!(bc.contains(SYM_CONNECTION));

        let sc = sig_colored();
        assert!(sc.contains("\x1b["));

        let lc = log_colored("test msg");
        assert!(lc.contains("test msg"));
        assert!(lc.contains("\x1b["));
    }

    #[test]
    fn semantic_groupings_are_correct() {
        // Signal domain
        assert_eq!(tool_domain("m1nd.activate"), "signal");
        assert_eq!(tool_domain("m1nd.ingest"), "signal");

        // Path domain
        assert_eq!(tool_domain("m1nd.why"), "path");
        assert_eq!(tool_domain("m1nd.seek"), "path");

        // Structure domain
        assert_eq!(tool_domain("m1nd.missing"), "structure");
        assert_eq!(tool_domain("m1nd.scan"), "structure");

        // Dimension domain
        assert_eq!(tool_domain("m1nd.impact"), "dimension");
        assert_eq!(tool_domain("m1nd.predict"), "dimension");

        // State domain
        assert_eq!(tool_domain("m1nd.health"), "state");
        assert_eq!(tool_domain("m1nd.lock.create"), "state");

        // Connection domain
        assert_eq!(tool_domain("m1nd.resonate"), "connection");
        assert_eq!(tool_domain("m1nd.perspective.start"), "connection");
    }
}