vibe-graph-mcp 0.2.2

MCP (Model Context Protocol) server for Vibe-Graph
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
//! Types for MCP tool inputs and outputs.

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
use std::time::Instant;

use dashmap::DashMap;
use vibe_graph_core::SourceCodeGraph;
use vibe_graph_ops::Store;

// =============================================================================
// Gateway Registry Types
// =============================================================================

/// A registered project in the MCP gateway.
#[derive(Clone)]
pub struct RegisteredProject {
    /// Project name (derived from workspace directory name).
    pub name: String,

    /// Absolute path to the workspace root.
    pub workspace_path: PathBuf,

    /// The source code graph for this project.
    pub graph: Arc<SourceCodeGraph>,

    /// Store for accessing .self metadata.
    pub store: Store,

    /// When this project was registered.
    pub registered_at: Instant,
}

/// Thread-safe registry of all projects served by the gateway.
#[derive(Default)]
pub struct ProjectRegistry {
    /// Map from project name to project data.
    pub projects: DashMap<String, RegisteredProject>,
}

impl ProjectRegistry {
    /// Create a new empty registry.
    pub fn new() -> Self {
        Self {
            projects: DashMap::new(),
        }
    }

    /// Register a new project.
    pub fn register(&self, project: RegisteredProject) {
        self.projects.insert(project.name.clone(), project);
    }

    /// Unregister a project by name.
    pub fn unregister(&self, name: &str) -> Option<RegisteredProject> {
        self.projects.remove(name).map(|(_, v)| v)
    }

    /// Get a project by name.
    pub fn get(
        &self,
        name: &str,
    ) -> Option<dashmap::mapref::one::Ref<'_, String, RegisteredProject>> {
        self.projects.get(name)
    }

    /// List all project names.
    pub fn list_names(&self) -> Vec<String> {
        self.projects.iter().map(|r| r.key().clone()).collect()
    }

    /// Get count of registered projects.
    pub fn len(&self) -> usize {
        self.projects.len()
    }

    /// Check if registry is empty.
    pub fn is_empty(&self) -> bool {
        self.projects.is_empty()
    }

    /// Get the single project if only one is registered.
    pub fn get_single(&self) -> Option<dashmap::mapref::one::Ref<'_, String, RegisteredProject>> {
        if self.projects.len() == 1 {
            self.projects.iter().next().map(|r| {
                // Get a proper Ref by looking up the key
                let key = r.key().clone();
                drop(r);
                self.projects.get(&key).unwrap()
            })
        } else {
            None
        }
    }
}

/// Request to register a project with the gateway.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RegisterProjectRequest {
    /// Project name.
    pub name: String,

    /// Absolute path to the workspace.
    pub workspace_path: PathBuf,
}

/// Response from project registration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RegisterProjectResponse {
    /// Whether registration succeeded.
    pub success: bool,

    /// Message describing the result.
    pub message: String,

    /// Total number of projects now registered.
    pub project_count: usize,
}

/// Health check response.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HealthResponse {
    /// Server status.
    pub status: String,

    /// Server version.
    pub version: String,

    /// Number of registered projects.
    pub project_count: usize,

    /// List of registered project names.
    pub projects: Vec<String>,
}

/// Project info for list_projects tool.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct ProjectInfo {
    /// Project name.
    pub name: String,

    /// Workspace path.
    pub workspace_path: String,

    /// Number of nodes in the graph.
    pub node_count: usize,

    /// Number of edges in the graph.
    pub edge_count: usize,
}

/// Output for the `list_projects` tool.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct ListProjectsOutput {
    /// All registered projects.
    pub projects: Vec<ProjectInfo>,

    /// Total count.
    pub count: usize,
}

// =============================================================================
// Tool Input Types
// =============================================================================

/// Input for the `search_nodes` tool.
#[derive(Debug, Clone, Deserialize, JsonSchema)]
pub struct SearchNodesInput {
    /// Project name to search in. Required if multiple projects are registered.
    /// If only one project is registered, this is optional.
    #[serde(default)]
    pub project: Option<String>,

    /// Search query (matches against node name and path).
    pub query: String,

    /// Filter by node kind: "file", "directory", "module", "test", "service".
    #[serde(default)]
    pub kind: Option<String>,

    /// Filter by file extension (e.g., "rs", "py", "ts").
    #[serde(default)]
    pub extension: Option<String>,

    /// Maximum number of results to return.
    #[serde(default = "default_limit")]
    pub limit: usize,
}

fn default_limit() -> usize {
    20
}

/// Input for the `get_dependencies` tool.
#[derive(Debug, Clone, Deserialize, JsonSchema)]
pub struct GetDependenciesInput {
    /// Project name to query. Required if multiple projects are registered.
    #[serde(default)]
    pub project: Option<String>,

    /// Path or name of the node to query.
    pub node_path: String,

    /// Include incoming dependencies (nodes that depend on this one).
    #[serde(default = "default_true")]
    pub incoming: bool,

    /// Include outgoing dependencies (nodes this one depends on).
    #[serde(default = "default_true")]
    pub outgoing: bool,
}

fn default_true() -> bool {
    true
}

/// Input for the `impact_analysis` tool.
#[derive(Debug, Clone, Deserialize, JsonSchema)]
pub struct ImpactAnalysisInput {
    /// Project name to analyze. Required if multiple projects are registered.
    #[serde(default)]
    pub project: Option<String>,

    /// Paths to analyze for impact.
    pub paths: Vec<String>,

    /// Traversal depth for impact propagation.
    #[serde(default = "default_depth")]
    pub depth: usize,

    /// Include test files in the impact analysis.
    #[serde(default = "default_true")]
    pub include_tests: bool,
}

fn default_depth() -> usize {
    2
}

/// Input for the `get_node_context` tool.
#[derive(Debug, Clone, Deserialize, JsonSchema)]
pub struct GetNodeContextInput {
    /// Project name to query. Required if multiple projects are registered.
    #[serde(default)]
    pub project: Option<String>,

    /// Path or name of the node to get context for.
    pub node_path: String,

    /// Number of neighbor hops to include.
    #[serde(default = "default_context_depth")]
    pub depth: usize,

    /// Include file content for source files.
    #[serde(default)]
    pub include_content: bool,
}

fn default_context_depth() -> usize {
    1
}

/// Input for the `list_files` tool.
#[derive(Debug, Clone, Deserialize, JsonSchema)]
pub struct ListFilesInput {
    /// Project name to list files from. Required if multiple projects are registered.
    #[serde(default)]
    pub project: Option<String>,

    /// Directory path to list (empty for root).
    #[serde(default)]
    pub path: Option<String>,

    /// Filter by file extension.
    #[serde(default)]
    pub extension: Option<String>,

    /// Filter by node kind.
    #[serde(default)]
    pub kind: Option<String>,

    /// Maximum number of results.
    #[serde(default = "default_limit")]
    pub limit: usize,
}

/// Input for the `get_git_changes` tool.
#[derive(Debug, Clone, Deserialize, JsonSchema)]
pub struct GetGitChangesInput {
    /// Project name to get git changes for. Required if multiple projects are registered.
    #[serde(default)]
    pub project: Option<String>,
}

// =============================================================================
// Tool Output Types
// =============================================================================

/// Information about a single node in the graph.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct NodeInfo {
    /// Node ID.
    pub id: u64,

    /// Node name (typically filename).
    pub name: String,

    /// Full path to the node.
    pub path: String,

    /// Node kind: "file", "directory", "module", "test", "service", "other".
    pub kind: String,

    /// File extension (if applicable).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub extension: Option<String>,

    /// Programming language (if detected).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub language: Option<String>,

    /// Additional metadata.
    #[serde(skip_serializing_if = "HashMap::is_empty")]
    pub metadata: HashMap<String, String>,
}

/// Information about an edge/dependency.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct EdgeInfo {
    /// Source node path.
    pub from: String,

    /// Target node path.
    pub to: String,

    /// Relationship type: "uses", "imports", "implements", "contains".
    pub relationship: String,
}

/// Output for the `search_nodes` tool.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct SearchNodesOutput {
    /// Matching nodes.
    pub nodes: Vec<NodeInfo>,

    /// Total number of matches (may be more than returned if limit applied).
    pub total_matches: usize,

    /// Query that was executed.
    pub query: String,
}

/// Output for the `get_dependencies` tool.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct GetDependenciesOutput {
    /// The queried node.
    pub node: NodeInfo,

    /// Nodes that depend on this one (incoming edges).
    pub dependents: Vec<NodeInfo>,

    /// Nodes this one depends on (outgoing edges).
    pub dependencies: Vec<NodeInfo>,

    /// Edge details.
    pub edges: Vec<EdgeInfo>,
}

/// Output for the `impact_analysis` tool.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct ImpactAnalysisOutput {
    /// Paths that were analyzed.
    pub analyzed_paths: Vec<String>,

    /// All impacted nodes.
    pub impacted_nodes: Vec<NodeInfo>,

    /// Test files that should be run.
    pub impacted_tests: Vec<NodeInfo>,

    /// Number of nodes impacted.
    pub impact_count: usize,

    /// Traversal depth used.
    pub depth: usize,
}

/// Output for the `get_git_changes` tool.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct GitChangesOutput {
    /// Changed files.
    pub changes: Vec<GitFileChange>,

    /// Number of files changed.
    pub change_count: usize,

    /// Summary by change kind.
    pub summary: GitChangesSummary,
}

/// A single git file change.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct GitFileChange {
    /// File path.
    pub path: String,

    /// Change kind: "modified", "added", "deleted", "untracked", "renamed".
    pub kind: String,

    /// Whether the change is staged.
    pub staged: bool,
}

/// Summary of git changes by kind.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct GitChangesSummary {
    pub modified: usize,
    pub added: usize,
    pub deleted: usize,
    pub untracked: usize,
}

/// Output for the `get_node_context` tool.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct NodeContextOutput {
    /// The central node.
    pub node: NodeInfo,

    /// Neighboring nodes within the specified depth.
    pub neighbors: Vec<NodeInfo>,

    /// Edges connecting the nodes.
    pub edges: Vec<EdgeInfo>,

    /// File content (if requested and available).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub content: Option<String>,
}

/// Output for the `list_files` tool.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct ListFilesOutput {
    /// Files matching the criteria.
    pub files: Vec<NodeInfo>,

    /// Total count.
    pub total: usize,

    /// Path that was listed.
    pub path: Option<String>,
}