refactor: clean up redundant serde aliases in tools schema

This commit is contained in:
Riz Ashraf committed 2026-10-10 03:54:16 +01:00
1 parent 27416e4ee9
commit 2ae343d968
6 files changed
+171 -191

No files matched your search

Generated
+40 -4
View File
@@ -2651,7 +2651,7 @@ dependencies = [
"reqwest", "reqwest",
"rmcp", "rmcp",
"rten", "rten",
"schemars", "schemars 1.2.2",
"serde", "serde",
"serde_json", "serde_json",
"serde_yaml", "serde_yaml",
@@ -3009,6 +3009,7 @@ dependencies = [
"mcp-stdio", "mcp-stdio",
"rmcp", "rmcp",
"rmpv", "rmpv",
"schemars 0.8.22",
"serde", "serde",
"serde_json", "serde_json",
"tokio", "tokio",
@@ -3859,7 +3860,7 @@ dependencies = [
"pastey 0.2.3", "pastey 0.2.3",
"pin-project-lite", "pin-project-lite",
"rmcp-macros", "rmcp-macros",
"schemars", "schemars 1.2.2",
"serde", "serde",
"serde_json", "serde_json",
"thiserror 2.0.20", "thiserror 2.0.20",
@@ -4179,6 +4180,18 @@ dependencies = [
"windows-sys 0.61.2", "windows-sys 0.61.2",
] ]
[[package]]
name = "schemars"
version = "0.8.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fbf2ae1b8bc8e02df939598064d22402220cd5bbcca1c76f7d6a310974d5615"
dependencies = [
"dyn-clone",
"schemars_derive 0.8.22",
"serde",
"serde_json",
]
[[package]] [[package]]
name = "schemars" name = "schemars"
version = "1.2.2" version = "1.2.2"
@@ -4188,11 +4201,23 @@ dependencies = [
"chrono", "chrono",
"dyn-clone", "dyn-clone",
"ref-cast", "ref-cast",
"schemars_derive", "schemars_derive 1.2.2",
"serde", "serde",
"serde_json", "serde_json",
] ]
[[package]]
name = "schemars_derive"
version = "0.8.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32e265784ad618884abaea0600a9adf15393368d840e0222d101a072f3f7534d"
dependencies = [
"proc-macro2",
"quote",
"serde_derive_internals 0.29.1",
"syn 2.0.119",
]
[[package]] [[package]]
name = "schemars_derive" name = "schemars_derive"
version = "1.2.2" version = "1.2.2"
@@ -4201,7 +4226,7 @@ checksum = "d98c67716b46af2f0b8cf752abc930f6f9aecfbf671ecfb531db8a31dbe4e2ba"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"serde_derive_internals", "serde_derive_internals 0.30.0",
"syn 3.0.6", "syn 3.0.6",
] ]
@@ -4276,6 +4301,17 @@ dependencies = [
"syn 3.0.6", "syn 3.0.6",
] ]
[[package]]
name = "serde_derive_internals"
version = "0.29.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.119",
]
[[package]] [[package]]
name = "serde_derive_internals" name = "serde_derive_internals"
version = "0.30.0" version = "0.30.0"
+1
View File
@@ -16,6 +16,7 @@ rmcp = { version = "3.4.0", features = ["server"] }
mcp-stdio = { version = "1.0.0", path = "../mcp-stdio" } mcp-stdio = { version = "1.0.0", path = "../mcp-stdio" }
bytes = "1.12.1" bytes = "1.12.1"
dashmap = "6.2.1" dashmap = "6.2.1"
schemars = "0.8"
[build-dependencies] [build-dependencies]
chrono = "0.4.45" chrono = "0.4.45"
+25 -118
View File
@@ -1,3 +1,5 @@
mod tools;
use tools::*;
mod headless; mod headless;
use headless::*; use headless::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -22,6 +24,22 @@ pub struct JsonRpcResponse {
pub error: Option<Value>, pub error: Option<Value>,
} }
pub fn tool_def<T: schemars::JsonSchema>(name: &str, fallback_desc: &str) -> serde_json::Value {
let schema = schemars::schema_for!(T);
let schema_val = serde_json::to_value(&schema).unwrap_or_default();
let desc = schema_val
.get("description")
.and_then(|d| d.as_str())
.filter(|s| !s.trim().is_empty())
.unwrap_or(fallback_desc)
.to_string();
serde_json::json!({
"name": name,
"description": desc,
"inputSchema": schema_val
})
}
pub async fn send_response(response: JsonRpcResponse) { pub async fn send_response(response: JsonRpcResponse) {
let msg = serde_json::to_string(&response).unwrap_or_else(|_| "{}".to_string()); let msg = serde_json::to_string(&response).unwrap_or_else(|_| "{}".to_string());
tracing::info!( tracing::info!(
@@ -977,124 +995,13 @@ pub async fn run_mcp_loop(app_name: &str, app_version: &str) {
jsonrpc: "2.0".to_string(), jsonrpc: "2.0".to_string(),
id, id,
result: Some(json!({ result: Some(json!({
"tools": "tools": [
[ tool_def::<NvimBufferTool>("nvim_buffer", "Core Text Editing: read, replace, save, and manipulate Neovim buffers in memory."),
{ tool_def::<NvimWorkspaceTool>("nvim_workspace", "Window & Editor State: list buffers, windows, focus splits, and manage cwd."),
"name": "nvim_buffer", tool_def::<NvimIntelligenceTool>("nvim_intelligence", "Code Semantics: LSP queries (hover, definition, references, code_action, rename, diagnostics) and AST outlining/queries."),
"description": "Core Text Editing: read, replace, save, and manipulate Neovim buffers in memory.", tool_def::<NvimUiTool>("nvim_ui", "Visual Feedback: communicating visually with the human user via highlights and ghost text."),
"inputSchema": { tool_def::<NvimExecTool>("nvim_exec", "The Escape Hatch: execute lua read-only queries, run vimscript commands, or send commands to the terminal."),
"type": "object", ]
"properties": {
"action": {
"type": "string",
"enum": ["read", "replace", "save", "undo", "redo", "create_scratch"],
"description": "Action to perform on the buffer"
},
"file": { "type": "string", "description": "Target file path (for read, replace, save)" },
"start_line": { "type": "integer", "description": "1-indexed start line (for read)" },
"end_line": { "type": "integer", "description": "1-indexed end line (for read)" },
"content": { "type": "string", "description": "Initial text content (for create_scratch)" },
"name": { "type": "string", "description": "Buffer display name (for create_scratch)" },
"steps": { "type": "integer", "description": "Number of undo/redo steps to apply (default: 1)" },
"edits": {
"type": "array",
"description": "Array of edits to apply sequentially (for replace). Grouped by file, applied in descending order.",
"items": {
"type": "object",
"properties": {
"file": { "type": "string" },
"start_line": { "type": "integer" },
"end_line": { "type": "integer" },
"replacement_content": { "type": "string" },
"expected_content": { "type": "string" }
},
"required": ["file", "start_line", "end_line", "replacement_content"]
}
}
},
"required": ["action"]
}
},
{
"name": "nvim_workspace",
"description": "Window & Editor State: list buffers, windows, focus splits, and manage cwd.",
"inputSchema": {
"type": "object",
"properties": {
"action": {
"type": "string",
"enum": ["list_buffers", "list_windows", "focus", "split", "cwd"],
"description": "Workspace operation to perform"
},
"win_id": { "type": "integer", "description": "Window ID to focus" },
"file": { "type": "string", "description": "File to open in split" },
"direction": { "type": "string", "enum": ["vertical", "horizontal"], "description": "Split orientation (default: vertical)" },
"path": { "type": "string", "description": "Target directory (for cwd action)" }
},
"required": ["action"]
}
},
{
"name": "nvim_intelligence",
"description": "Code Semantics: LSP queries (hover, definition, references, code_action, rename, diagnostics) and AST outlining/queries.",
"inputSchema": {
"type": "object",
"properties": {
"action": {
"type": "string",
"enum": ["hover", "definition", "references", "outline", "query", "diagnostics", "rename", "code_action"],
"description": "Intelligence action to perform"
},
"file": { "type": "string", "description": "Target file path" },
"line": { "type": "integer", "description": "1-indexed line number (for LSP)" },
"col": { "type": "integer", "description": "0-indexed column number (for LSP)" },
"new_name": { "type": "string", "description": "New name (for rename action)" },
"query": { "type": "string", "description": "Tree-sitter query string (for AST query)" },
"preset": { "type": "string", "description": "Query preset (e.g., 'functions', 'classes' for AST query)" }
},
"required": ["action"]
}
},
{
"name": "nvim_ui",
"description": "Visual Feedback: communicating visually with the human user via highlights and ghost text.",
"inputSchema": {
"type": "object",
"properties": {
"action": {
"type": "string",
"enum": ["highlight", "ghost_text", "clear"],
"description": "UI action"
},
"buf_id": { "type": "integer", "description": "Buffer ID to apply to" },
"start_line": { "type": "integer", "description": "1-indexed start line (for highlight)" },
"end_line": { "type": "integer", "description": "1-indexed end line (for highlight)" },
"line": { "type": "integer", "description": "1-indexed line number (for ghost_text)" },
"text": { "type": "string", "description": "Virtual text to display (for ghost_text)" },
"highlight_group": { "type": "string", "description": "Highlight group (e.g. 'Comment', 'IncSearch')" },
"duration_ms": { "type": "integer", "description": "Auto-clear duration in ms (for highlight, default: 5000)" }
},
"required": ["action"]
}
},
{
"name": "nvim_exec",
"description": "The Escape Hatch: execute lua read-only queries, run vimscript commands, or send commands to the terminal.",
"inputSchema": {
"type": "object",
"properties": {
"action": {
"type": "string",
"enum": ["lua", "vimscript", "terminal"],
"description": "Execution action"
},
"code": { "type": "string", "description": "Lua code or Vimscript command to execute" },
"command": { "type": "string", "description": "Shell command to send (for terminal)" }
},
"required": ["action"]
}
}
]
})), })),
error: None, error: None,
+101
View File
@@ -0,0 +1,101 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
#[serde(tag = "action", rename_all = "snake_case")]
pub enum NvimBufferTool {
Read {
file: String,
start_line: Option<i64>,
end_line: Option<i64>,
},
Replace {
file: Option<String>,
start_line: Option<i64>,
end_line: Option<i64>,
replacement_content: Option<String>,
expected_content: Option<String>,
edits: Option<Vec<BufferEdit>>,
},
Save {
file: Option<String>,
},
Undo {
steps: Option<i64>,
},
Redo {
steps: Option<i64>,
},
CreateScratch {
name: Option<String>,
content: Option<String>,
},
}
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
pub struct BufferEdit {
pub file: String,
pub start_line: i64,
pub end_line: i64,
pub replacement_content: String,
pub expected_content: Option<String>,
}
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
#[serde(tag = "action", rename_all = "snake_case")]
pub enum NvimWorkspaceTool {
ListBuffers,
ListWindows,
Focus {
win_id: i64,
},
Split {
direction: Option<String>,
file: Option<String>,
buf_id: Option<i64>,
},
Cwd {
path: Option<String>,
},
}
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
#[serde(tag = "action", rename_all = "snake_case")]
pub enum NvimIntelligenceTool {
Hover { file: String, line: i64, col: i64 },
Definition { file: String, line: i64, col: i64 },
References { file: String, line: i64, col: i64 },
CodeAction { file: String, line: i64, col: i64 },
Rename { file: String, line: i64, col: i64, new_name: String },
Diagnostics { file: String },
Outline { file: String },
Query { file: String, query: Option<String>, preset: Option<String> },
}
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
#[serde(tag = "action", rename_all = "snake_case")]
pub enum NvimUiTool {
Highlight {
buf_id: Option<i64>,
start_line: i64,
end_line: Option<i64>,
highlight_group: Option<String>,
duration_ms: Option<i64>,
},
GhostText {
line: i64,
text: String,
highlight_group: Option<String>,
},
Clear {
buf_id: Option<i64>,
},
}
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
#[serde(tag = "action", rename_all = "snake_case")]
pub enum NvimExecTool {
Lua { code: String },
Vimscript { code: String },
Terminal { command: String },
}
-64
View File
@@ -597,11 +597,8 @@ pub struct AutoSessionCheckpointTool {
#[derive(Debug, Deserialize, Serialize, JsonSchema, PartialEq)] #[derive(Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum HandoffMemoAction { pub enum HandoffMemoAction {
#[serde(alias = "leave", alias = "LEAVE", alias = "Leave")]
Leave, Leave,
#[serde(alias = "read", alias = "READ", alias = "Read")]
Read, Read,
#[serde(alias = "clear", alias = "CLEAR", alias = "Clear")]
Clear, Clear,
} }
@@ -627,22 +624,11 @@ pub struct HandoffMemosTool {
#[derive(Debug, Deserialize, Serialize, JsonSchema, PartialEq)] #[derive(Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum TaskAction { pub enum TaskAction {
#[serde(alias = "add", alias = "ADD", alias = "Add")]
Add, Add,
#[serde(alias = "update", alias = "UPDATE", alias = "Update")]
Update, Update,
#[serde(alias = "delete", alias = "DELETE", alias = "Delete")]
Delete, Delete,
#[serde(alias = "list", alias = "LIST", alias = "List")]
List, List,
#[serde(
alias = "set_criteria",
alias = "setCriteria",
alias = "SET_CRITERIA",
alias = "SetCriteria"
)]
SetCriteria, SetCriteria,
#[serde(alias = "verify", alias = "VERIFY", alias = "Verify")]
Verify, Verify,
} }
@@ -706,11 +692,8 @@ pub struct TasksTool {
#[derive(Debug, Deserialize, Serialize, JsonSchema, PartialEq)] #[derive(Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum MilestoneAction { pub enum MilestoneAction {
#[serde(alias = "add", alias = "ADD", alias = "Add")]
Add, Add,
#[serde(alias = "update", alias = "UPDATE", alias = "Update")]
Update, Update,
#[serde(alias = "list", alias = "LIST", alias = "List")]
List, List,
} }
@@ -750,13 +733,9 @@ pub struct MilestonesTool {
#[derive(Debug, Deserialize, Serialize, JsonSchema, PartialEq)] #[derive(Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum SnippetAction { pub enum SnippetAction {
#[serde(alias = "store", alias = "STORE", alias = "Store")]
Store, Store,
#[serde(alias = "search", alias = "SEARCH", alias = "Search")]
Search, Search,
#[serde(alias = "delete", alias = "DELETE", alias = "Delete")]
Delete, Delete,
#[serde(alias = "tag", alias = "TAG", alias = "Tag")]
Tag, Tag,
} }
@@ -801,13 +780,9 @@ pub struct SnippetsTool {
#[derive(Debug, Deserialize, Serialize, JsonSchema, PartialEq, Clone)] #[derive(Debug, Deserialize, Serialize, JsonSchema, PartialEq, Clone)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum DecisionAction { pub enum DecisionAction {
#[serde(alias = "log", alias = "LOG", alias = "Log")]
Log, Log,
#[serde(alias = "query", alias = "QUERY", alias = "Query")]
Query, Query,
#[serde(alias = "delete", alias = "DELETE", alias = "Delete")]
Delete, Delete,
#[serde(alias = "update", alias = "UPDATE", alias = "Update")]
Update, Update,
} }
@@ -865,11 +840,8 @@ pub struct DecisionsTool {
#[derive(Debug, Deserialize, Serialize, JsonSchema, PartialEq)] #[derive(Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum TechDebtAction { pub enum TechDebtAction {
#[serde(alias = "log", alias = "LOG", alias = "Log")]
Log, Log,
#[serde(alias = "resolve", alias = "RESOLVE", alias = "Resolve")]
Resolve, Resolve,
#[serde(alias = "list", alias = "LIST", alias = "List")]
List, List,
} }
@@ -928,35 +900,10 @@ pub struct TechDebtTool {
#[derive(Debug, Deserialize, Serialize, JsonSchema, PartialEq)] #[derive(Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum EnvAction { pub enum EnvAction {
#[serde(
alias = "update_fingerprint",
alias = "updateFingerprint",
alias = "UPDATE_FINGERPRINT",
alias = "UpdateFingerprint"
)]
UpdateFingerprint, UpdateFingerprint,
#[serde(
alias = "read_fingerprint",
alias = "readFingerprint",
alias = "READ_FINGERPRINT",
alias = "ReadFingerprint"
)]
ReadFingerprint, ReadFingerprint,
#[serde(
alias = "log_requirement",
alias = "logRequirement",
alias = "LOG_REQUIREMENT",
alias = "LogRequirement"
)]
LogRequirement, LogRequirement,
#[serde(alias = "register", alias = "REGISTER", alias = "Register")]
Register, Register,
#[serde(
alias = "get_details",
alias = "getDetails",
alias = "GET_DETAILS",
alias = "GetDetails"
)]
GetDetails, GetDetails,
} }
@@ -998,21 +945,10 @@ pub struct EnvironmentTool {
#[derive(Debug, Clone, Copy, Deserialize, Serialize, JsonSchema, PartialEq)] #[derive(Debug, Clone, Copy, Deserialize, Serialize, JsonSchema, PartialEq)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum ClipboardAction { pub enum ClipboardAction {
#[serde(
alias = "image",
alias = "IMAGE",
alias = "Image",
alias = "screenshot",
alias = "SCREENSHOT"
)]
Image, Image,
#[serde(alias = "text", alias = "TEXT", alias = "Text")]
Text, Text,
#[serde(alias = "history", alias = "HISTORY", alias = "History")]
History, History,
#[serde(alias = "clear", alias = "CLEAR", alias = "Clear")]
Clear, Clear,
#[serde(alias = "write", alias = "WRITE", alias = "Write")]
Write, Write,
} }
/// Smart OS Clipboard management with overwrite-immune screenshot caching and OCR. /// Smart OS Clipboard management with overwrite-immune screenshot caching and OCR.
+4 -5
View File
@@ -29,11 +29,10 @@ fn test_eager_tools_parity() {
let nvim_source = let nvim_source =
std::fs::read_to_string("../nvim-core/src/lib.rs").expect("Failed to read nvim lib.rs"); std::fs::read_to_string("../nvim-core/src/lib.rs").expect("Failed to read nvim lib.rs");
let mut nvim_tools = HashSet::new(); let mut nvim_tools = HashSet::new();
for line in nvim_source.lines() { let parts: Vec<&str> = nvim_source.split("tool_def").collect();
if line.contains("\"name\": \"nvim_") for part in parts.iter().skip(1) {
&& let Some(start) = line.find("\"name\": \"") if let Some(start) = part.find("(\"") {
{ let rest = &part[start + 2..];
let rest = &line[start + 9..];
if let Some(end) = rest.find('"') { if let Some(end) = rest.find('"') {
nvim_tools.insert(rest[..end].to_string()); nvim_tools.insert(rest[..end].to_string());
} }