Skip to main content

codesearch/mcp/
types.rs

1//! MCP types and request/response structures
2
3use rmcp::schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6/// Request for semantic search
7#[derive(Debug, Deserialize, JsonSchema)]
8pub struct SemanticSearchRequest {
9    /// The search query (natural language or code snippet)
10    pub query: String,
11
12    /// Maximum number of results to return (default: 10)
13    pub limit: Option<usize>,
14
15    /// Return compact results (metadata only) to save tokens (default: true).
16    /// When true: returns only path, start_line, end_line, kind, signature, score.
17    /// When false: also includes full code content and surrounding context.
18    /// Use compact=true (default) and then read specific files with line offsets for the code you need.
19    pub compact: Option<bool>,
20
21    /// Only return results from files under this path prefix (e.g., "src/api/")
22    pub filter_path: Option<String>,
23}
24
25/// Request to get file chunks
26#[derive(Debug, Deserialize, JsonSchema)]
27pub struct GetFileChunksRequest {
28    /// Path to the file (relative to project root)
29    pub path: String,
30
31    /// Return compact results (metadata only) to save tokens (default: true).
32    /// When true: returns only path, start_line, end_line, kind, signature.
33    /// When false: also includes full code content.
34    pub compact: Option<bool>,
35}
36
37/// Request to find references/call sites of a symbol.
38/// Use this AFTER semantic_search to find where a function/class/variable is used.
39/// Use this INSTEAD OF grep for finding symbol usages in the codebase.
40#[derive(Debug, Deserialize, JsonSchema)]
41pub struct FindReferencesRequest {
42    /// The symbol name to find references for (e.g., "authenticate", "User", "Config")
43    pub symbol: String,
44
45    /// Maximum number of references to return (default: 20)
46    pub limit: Option<usize>,
47}
48
49/// Search result item - returned by semantic_search and get_file_chunks
50#[derive(Debug, Serialize)]
51pub struct SearchResultItem {
52    pub path: String,
53    pub start_line: usize,
54    pub end_line: usize,
55    pub kind: String,
56    pub score: f32,
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub signature: Option<String>,
59    #[serde(skip_serializing_if = "Option::is_none")]
60    pub content: Option<String>,
61    #[serde(skip_serializing_if = "Option::is_none")]
62    pub context_prev: Option<String>,
63    #[serde(skip_serializing_if = "Option::is_none")]
64    pub context_next: Option<String>,
65}
66
67/// Reference/call site item - returned by find_references
68#[derive(Debug, Serialize)]
69pub struct ReferenceItem {
70    /// File path containing the reference
71    pub path: String,
72    /// Line number of the reference
73    pub line: usize,
74    /// The kind of chunk containing the reference (e.g., "Function", "Method")
75    pub kind: String,
76    /// Signature of the containing function/method (if available)
77    #[serde(skip_serializing_if = "Option::is_none")]
78    pub signature: Option<String>,
79    /// FTS relevance score
80    pub score: f32,
81}
82
83/// Index status response
84#[derive(Debug, Serialize)]
85pub struct IndexStatusResponse {
86    pub indexed: bool,
87    pub total_chunks: usize,
88    pub total_files: usize,
89    pub model: String,
90    pub dimensions: usize,
91    pub max_chunk_id: u32,
92    pub db_path: String,
93    pub project_path: String,
94    #[serde(skip_serializing_if = "Option::is_none")]
95    pub error_message: Option<String>,
96}
97
98/// Database info response
99#[derive(Debug, Serialize)]
100pub struct DatabaseInfoResponse {
101    pub database_path: String,
102    pub project_path: String,
103    pub is_current_directory: bool,
104    pub depth_from_current: usize,
105    pub total_chunks: usize,
106    pub total_files: usize,
107    pub model: String,
108}
109
110/// Find databases response
111#[derive(Debug, Serialize)]
112pub struct FindDatabasesResponse {
113    pub databases: Vec<DatabaseInfoResponse>,
114    pub message: String,
115    pub current_directory: String,
116}