mcpls_core/mcp/
tools.rs

1//! MCP tool parameter definitions.
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6/// Parameters for the `get_hover` tool.
7#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
8#[schemars(description = "Parameters for getting hover information at a position in a file.")]
9pub struct HoverParams {
10    /// Absolute path to the file.
11    #[schemars(description = "Absolute path to the file.")]
12    pub file_path: String,
13    /// Line number (1-based).
14    #[schemars(description = "Line number (1-based).")]
15    pub line: u32,
16    /// Character/column number (1-based).
17    #[schemars(description = "Character/column number (1-based).")]
18    pub character: u32,
19}
20
21/// Parameters for the `get_definition` tool.
22#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
23#[schemars(description = "Parameters for getting the definition location of a symbol.")]
24pub struct DefinitionParams {
25    /// Absolute path to the file.
26    #[schemars(description = "Absolute path to the file.")]
27    pub file_path: String,
28    /// Line number (1-based).
29    #[schemars(description = "Line number (1-based).")]
30    pub line: u32,
31    /// Character/column number (1-based).
32    #[schemars(description = "Character/column number (1-based).")]
33    pub character: u32,
34}
35
36/// Parameters for the `get_references` tool.
37#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
38#[schemars(description = "Parameters for finding all references to a symbol.")]
39pub struct ReferencesParams {
40    /// Absolute path to the file.
41    #[schemars(description = "Absolute path to the file.")]
42    pub file_path: String,
43    /// Line number (1-based).
44    #[schemars(description = "Line number (1-based).")]
45    pub line: u32,
46    /// Character/column number (1-based).
47    #[schemars(description = "Character/column number (1-based).")]
48    pub character: u32,
49    /// Whether to include the declaration in the results.
50    #[schemars(description = "Whether to include the declaration in the results.")]
51    #[serde(default)]
52    pub include_declaration: bool,
53}
54
55/// Parameters for the `get_diagnostics` tool.
56#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
57#[schemars(description = "Parameters for getting diagnostics (errors, warnings) for a file.")]
58pub struct DiagnosticsParams {
59    /// Absolute path to the file.
60    #[schemars(description = "Absolute path to the file.")]
61    pub file_path: String,
62}
63
64/// Parameters for the `rename_symbol` tool.
65#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
66#[schemars(description = "Parameters for renaming a symbol across the workspace.")]
67pub struct RenameParams {
68    /// Absolute path to the file.
69    #[schemars(description = "Absolute path to the file.")]
70    pub file_path: String,
71    /// Line number (1-based).
72    #[schemars(description = "Line number (1-based).")]
73    pub line: u32,
74    /// Character/column number (1-based).
75    #[schemars(description = "Character/column number (1-based).")]
76    pub character: u32,
77    /// New name for the symbol.
78    #[schemars(description = "New name for the symbol.")]
79    pub new_name: String,
80}
81
82/// Parameters for the `get_completions` tool.
83#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
84#[schemars(description = "Parameters for getting code completion suggestions.")]
85pub struct CompletionsParams {
86    /// Absolute path to the file.
87    #[schemars(description = "Absolute path to the file.")]
88    pub file_path: String,
89    /// Line number (1-based).
90    #[schemars(description = "Line number (1-based).")]
91    pub line: u32,
92    /// Character/column number (1-based).
93    #[schemars(description = "Character/column number (1-based).")]
94    pub character: u32,
95    /// Optional trigger character (e.g., '.', ':', '->').
96    #[schemars(description = "Optional trigger character (e.g., '.', ':', '->').")]
97    pub trigger: Option<String>,
98}
99
100/// Parameters for the `get_document_symbols` tool.
101#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
102#[schemars(description = "Parameters for getting all symbols in a document.")]
103pub struct DocumentSymbolsParams {
104    /// Absolute path to the file.
105    #[schemars(description = "Absolute path to the file.")]
106    pub file_path: String,
107}
108
109/// Parameters for the `format_document` tool.
110#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
111#[schemars(description = "Parameters for formatting a document.")]
112pub struct FormatDocumentParams {
113    /// Absolute path to the file.
114    #[schemars(description = "Absolute path to the file.")]
115    pub file_path: String,
116    /// Tab size for formatting (default: 4).
117    #[schemars(description = "Tab size for formatting (default: 4).")]
118    #[serde(default = "default_tab_size")]
119    pub tab_size: u32,
120    /// Whether to use spaces instead of tabs (default: true).
121    #[schemars(description = "Whether to use spaces instead of tabs (default: true).")]
122    #[serde(default = "default_insert_spaces")]
123    pub insert_spaces: bool,
124}
125
126const fn default_tab_size() -> u32 {
127    4
128}
129
130const fn default_insert_spaces() -> bool {
131    true
132}
133
134/// Parameters for the `workspace_symbol_search` tool.
135#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
136#[schemars(description = "Parameters for searching symbols across the workspace.")]
137pub struct WorkspaceSymbolParams {
138    /// Search query for symbol names (supports partial matching).
139    #[schemars(description = "Search query for symbol names (supports partial matching).")]
140    pub query: String,
141    /// Optional filter by symbol kind (function, class, variable, etc.).
142    #[schemars(description = "Optional filter by symbol kind (function, class, variable, etc.).")]
143    #[serde(skip_serializing_if = "Option::is_none")]
144    pub kind_filter: Option<String>,
145    /// Maximum results to return (default: 100).
146    #[schemars(description = "Maximum results to return (default: 100).")]
147    #[serde(default = "default_max_results")]
148    pub limit: u32,
149}
150
151const fn default_max_results() -> u32 {
152    100
153}
154
155/// Parameters for the `get_code_actions` tool.
156#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
157#[schemars(
158    description = "Parameters for getting available code actions (quick fixes, refactorings) for a range."
159)]
160pub struct CodeActionsParams {
161    /// Absolute path to the file.
162    #[schemars(description = "Absolute path to the file.")]
163    pub file_path: String,
164    /// Start line (1-based).
165    #[schemars(description = "Start line (1-based).")]
166    pub start_line: u32,
167    /// Start character (1-based).
168    #[schemars(description = "Start character (1-based).")]
169    pub start_character: u32,
170    /// End line (1-based).
171    #[schemars(description = "End line (1-based).")]
172    pub end_line: u32,
173    /// End character (1-based).
174    #[schemars(description = "End character (1-based).")]
175    pub end_character: u32,
176    /// Optional filter by action kind (quickfix, refactor, source, etc.).
177    #[schemars(description = "Optional filter by action kind (quickfix, refactor, source, etc.).")]
178    #[serde(skip_serializing_if = "Option::is_none")]
179    pub kind_filter: Option<String>,
180}
181
182/// Parameters for the `prepare_call_hierarchy` tool.
183#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
184#[schemars(description = "Parameters for preparing call hierarchy at a position.")]
185pub struct CallHierarchyPrepareParams {
186    /// Absolute path to the file.
187    #[schemars(description = "Absolute path to the file.")]
188    pub file_path: String,
189    /// Line number (1-based).
190    #[schemars(description = "Line number (1-based).")]
191    pub line: u32,
192    /// Character/column number (1-based).
193    #[schemars(description = "Character/column number (1-based).")]
194    pub character: u32,
195}
196
197/// Parameters for the `get_incoming_calls` and `get_outgoing_calls` tools.
198#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
199#[schemars(
200    description = "Parameters for getting incoming or outgoing calls for a call hierarchy item."
201)]
202pub struct CallHierarchyCallsParams {
203    /// The call hierarchy item to get calls for (from prepare response).
204    #[schemars(description = "The call hierarchy item to get calls for (from prepare response).")]
205    pub item: serde_json::Value,
206}
207
208/// Parameters for the `get_cached_diagnostics` tool.
209#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
210#[schemars(
211    description = "Parameters for getting cached diagnostics from LSP server notifications."
212)]
213pub struct CachedDiagnosticsParams {
214    /// Absolute path to the file.
215    #[schemars(description = "Absolute path to the file.")]
216    pub file_path: String,
217}
218
219/// Parameters for the `get_server_logs` tool.
220#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
221#[schemars(description = "Parameters for getting recent LSP server log messages.")]
222pub struct ServerLogsParams {
223    /// Maximum number of log entries to return (default: 50).
224    #[schemars(description = "Maximum number of log entries to return (default: 50).")]
225    #[serde(default = "default_log_limit")]
226    pub limit: usize,
227    /// Minimum log level to include: error, warning, info, debug.
228    #[schemars(description = "Minimum log level to include: error, warning, info, debug.")]
229    #[serde(skip_serializing_if = "Option::is_none")]
230    pub min_level: Option<String>,
231}
232
233const fn default_log_limit() -> usize {
234    50
235}
236
237/// Parameters for the `get_server_messages` tool.
238#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
239#[schemars(
240    description = "Parameters for getting recent LSP server messages (showMessage notifications)."
241)]
242pub struct ServerMessagesParams {
243    /// Maximum number of messages to return (default: 20).
244    #[schemars(description = "Maximum number of messages to return (default: 20).")]
245    #[serde(default = "default_message_limit")]
246    pub limit: usize,
247}
248
249const fn default_message_limit() -> usize {
250    20
251}