Skip to content

Commit 48d2f32

Browse files
committed
refactor(mcp): flatten text editor command schema
- Replace tagged enum with struct and command enum - Make content and text fields optional in schema - Simplify parameter deserialization for editor tools
1 parent 79e08c6 commit 48d2f32

1 file changed

Lines changed: 22 additions & 26 deletions

File tree

src/mcp/server.rs

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -337,33 +337,29 @@ where
337337
deserializer.deserialize_any(StringOrVec)
338338
}
339339

340-
/// Text editor operation. The `command` field discriminates between variants,
341-
/// and each variant declares exactly the fields it needs — so `old_text`/`new_text`
342-
/// are schema-level required for `str_replace` and absent for `create`/`undo_edit`.
343340
#[derive(Debug, Clone, Deserialize, Serialize, schemars::JsonSchema)]
344-
#[serde(tag = "command", rename_all = "snake_case")]
345-
pub enum TextEditorParams {
346-
/// Create a new file with the given content. Fails if the file already exists.
347-
Create {
348-
/// Path to the file to create.
349-
path: String,
350-
/// Content to write to the new file.
351-
content: String,
352-
},
353-
/// Replace an exact text match in an existing file.
354-
StrReplace {
355-
/// Path to the file to edit.
356-
path: String,
357-
/// Text to find (must match exactly, including whitespace).
358-
old_text: String,
359-
/// Replacement text.
360-
new_text: String,
361-
},
362-
/// Undo the last edit to a file (up to 10 levels of history).
363-
UndoEdit {
364-
/// Path to the file to revert.
365-
path: String,
366-
},
341+
#[serde(rename_all = "snake_case")]
342+
pub enum TextEditorCommand {
343+
Create,
344+
StrReplace,
345+
UndoEdit,
346+
}
347+
348+
#[derive(Debug, Clone, Deserialize, Serialize, schemars::JsonSchema)]
349+
pub struct TextEditorParams {
350+
/// The operation to perform: create, str_replace, undo_edit
351+
pub command: TextEditorCommand,
352+
/// REQUIRED. Path to the file to operate on.
353+
pub path: String,
354+
/// File content for create command.
355+
#[serde(default)]
356+
pub content: Option<String>,
357+
/// Text to find (must match exactly). REQUIRED for str_replace.
358+
#[serde(default)]
359+
pub old_text: Option<String>,
360+
/// Replacement text. REQUIRED for str_replace.
361+
#[serde(default)]
362+
pub new_text: Option<String>,
367363
}
368364

369365
#[derive(Debug, Clone, Deserialize, Serialize, schemars::JsonSchema)]

0 commit comments

Comments
 (0)