alexhancock/mcp-crate-cleanup (#4885)

This commit is contained in:
Alex Hancock
2025-09-29 17:00:17 -04:00
committed by GitHub
parent 2bd18a757b
commit cb0eca9966
78 changed files with 1039 additions and 1090 deletions
+84 -68
View File
@@ -127,9 +127,11 @@ pub fn tool_request_to_markdown(req: &ToolRequest, export_all_content: bool) ->
));
md.push_str("**Arguments:**\n");
match call.name.as_str() {
match call.name.as_ref() {
"developer__shell" => {
if let Some(Value::String(command)) = call.arguments.get("command") {
if let Some(Value::String(command)) =
call.arguments.as_ref().and_then(|args| args.get("command"))
{
md.push_str(&format!(
"* **command**:\n ```sh\n {}\n ```\n",
command.trim()
@@ -137,7 +139,7 @@ pub fn tool_request_to_markdown(req: &ToolRequest, export_all_content: bool) ->
}
let other_args: serde_json::Map<String, Value> = call
.arguments
.as_object()
.as_ref()
.map(|obj| {
obj.iter()
.filter(|(k, _)| k.as_str() != "command")
@@ -154,10 +156,16 @@ pub fn tool_request_to_markdown(req: &ToolRequest, export_all_content: bool) ->
}
}
"developer__text_editor" => {
if let Some(Value::String(path)) = call.arguments.get("path") {
if let Some(Value::String(path)) =
call.arguments.as_ref().and_then(|args| args.get("path"))
{
md.push_str(&format!("* **path**: `{}`\n", path));
}
if let Some(Value::String(code_edit)) = call.arguments.get("code_edit") {
if let Some(Value::String(code_edit)) = call
.arguments
.as_ref()
.and_then(|args| args.get("code_edit"))
{
md.push_str(&format!(
"* **code_edit**:\n ```\n{}\n ```\n",
code_edit
@@ -166,7 +174,7 @@ pub fn tool_request_to_markdown(req: &ToolRequest, export_all_content: bool) ->
let other_args: serde_json::Map<String, Value> = call
.arguments
.as_object()
.as_ref()
.map(|obj| {
obj.iter()
.filter(|(k, _)| k.as_str() != "path" && k.as_str() != "code_edit")
@@ -183,7 +191,15 @@ pub fn tool_request_to_markdown(req: &ToolRequest, export_all_content: bool) ->
}
}
_ => {
md.push_str(&value_to_markdown(&call.arguments, 0, export_all_content));
if let Some(args) = &call.arguments {
md.push_str(&value_to_markdown(
&Value::Object(args.clone()),
0,
export_all_content,
));
} else {
md.push_str("*No arguments*\n");
}
}
}
}
@@ -370,8 +386,8 @@ pub fn message_to_markdown(message: &Message, export_all_content: bool) -> Strin
mod tests {
use super::*;
use goose::conversation::message::{Message, ToolRequest, ToolResponse};
use mcp_core::tool::ToolCall;
use rmcp::model::{Content, RawTextContent, TextContent};
use rmcp::model::{CallToolRequestParam, Content, RawTextContent, TextContent};
use rmcp::object;
use serde_json::json;
#[test]
@@ -486,12 +502,12 @@ mod tests {
#[test]
fn test_tool_request_to_markdown_shell() {
let tool_call = ToolCall {
name: "developer__shell".to_string(),
arguments: json!({
let tool_call = CallToolRequestParam {
name: "developer__shell".into(),
arguments: Some(object!({
"command": "ls -la",
"working_dir": "/home/user"
}),
})),
};
let tool_request = ToolRequest {
id: "test-id".to_string(),
@@ -509,12 +525,12 @@ mod tests {
#[test]
fn test_tool_request_to_markdown_text_editor() {
let tool_call = ToolCall {
name: "developer__text_editor".to_string(),
arguments: json!({
let tool_call = CallToolRequestParam {
name: "developer__text_editor".into(),
arguments: Some(object!({
"path": "/path/to/file.txt",
"code_edit": "print('Hello World')"
}),
})),
};
let tool_request = ToolRequest {
id: "test-id".to_string(),
@@ -578,9 +594,9 @@ mod tests {
#[test]
fn test_message_to_markdown_with_tool_request() {
let tool_call = ToolCall {
name: "test_tool".to_string(),
arguments: json!({"param": "value"}),
let tool_call = CallToolRequestParam {
name: "test_tool".into(),
arguments: Some(object!({"param": "value"})),
};
let message = Message::assistant().with_tool_request("test-id", Ok(tool_call));
@@ -637,11 +653,11 @@ mod tests {
#[test]
fn test_shell_tool_with_code_output() {
let tool_call = ToolCall {
name: "developer__shell".to_string(),
arguments: json!({
let tool_call = CallToolRequestParam {
name: "developer__shell".into(),
arguments: Some(object!({
"command": "cat main.py"
}),
})),
};
let tool_request = ToolRequest {
id: "shell-cat".to_string(),
@@ -683,11 +699,11 @@ if __name__ == "__main__":
#[test]
fn test_shell_tool_with_git_commands() {
let git_status_call = ToolCall {
name: "developer__shell".to_string(),
arguments: json!({
let git_status_call = CallToolRequestParam {
name: "developer__shell".into(),
arguments: Some(object!({
"command": "git status --porcelain"
}),
})),
};
let tool_request = ToolRequest {
id: "git-status".to_string(),
@@ -721,11 +737,11 @@ if __name__ == "__main__":
#[test]
fn test_shell_tool_with_build_output() {
let cargo_build_call = ToolCall {
name: "developer__shell".to_string(),
arguments: json!({
let cargo_build_call = CallToolRequestParam {
name: "developer__shell".into(),
arguments: Some(object!({
"command": "cargo build"
}),
})),
};
let _tool_request = ToolRequest {
id: "cargo-build".to_string(),
@@ -765,11 +781,11 @@ warning: unused variable `x`
#[test]
fn test_shell_tool_with_json_api_response() {
let curl_call = ToolCall {
name: "developer__shell".to_string(),
arguments: json!({
let curl_call = CallToolRequestParam {
name: "developer__shell".into(),
arguments: Some(object!({
"command": "curl -s https://api.github.com/repos/microsoft/vscode/releases/latest"
}),
})),
};
let _tool_request = ToolRequest {
id: "curl-api".to_string(),
@@ -811,13 +827,13 @@ warning: unused variable `x`
#[test]
fn test_text_editor_tool_with_code_creation() {
let editor_call = ToolCall {
name: "developer__text_editor".to_string(),
arguments: json!({
let editor_call = CallToolRequestParam {
name: "developer__text_editor".into(),
arguments: Some(object!({
"command": "write",
"path": "/tmp/fibonacci.js",
"file_text": "function fibonacci(n) {\n if (n <= 1) return n;\n return fibonacci(n - 1) + fibonacci(n - 2);\n}\n\nconsole.log(fibonacci(10));"
}),
})),
};
let tool_request = ToolRequest {
id: "editor-write".to_string(),
@@ -852,12 +868,12 @@ warning: unused variable `x`
#[test]
fn test_text_editor_tool_view_code() {
let editor_call = ToolCall {
name: "developer__text_editor".to_string(),
arguments: json!({
let editor_call = CallToolRequestParam {
name: "developer__text_editor".into(),
arguments: Some(object!({
"command": "view",
"path": "/src/utils.py"
}),
})),
};
let _tool_request = ToolRequest {
id: "editor-view".to_string(),
@@ -902,11 +918,11 @@ def process_data(data: List[Dict]) -> List[Dict]:
#[test]
fn test_shell_tool_with_error_output() {
let error_call = ToolCall {
name: "developer__shell".to_string(),
arguments: json!({
let error_call = CallToolRequestParam {
name: "developer__shell".into(),
arguments: Some(object!({
"command": "python nonexistent_script.py"
}),
})),
};
let _tool_request = ToolRequest {
id: "shell-error".to_string(),
@@ -937,11 +953,11 @@ Command failed with exit code 2"#;
#[test]
fn test_shell_tool_complex_script_execution() {
let script_call = ToolCall {
name: "developer__shell".to_string(),
arguments: json!({
let script_call = CallToolRequestParam {
name: "developer__shell".into(),
arguments: Some(object!({
"command": "python -c \"import sys; print(f'Python {sys.version}'); [print(f'{i}^2 = {i**2}') for i in range(1, 6)]\""
}),
})),
};
let tool_request = ToolRequest {
id: "script-exec".to_string(),
@@ -983,11 +999,11 @@ Command failed with exit code 2"#;
#[test]
fn test_shell_tool_with_multi_command() {
let multi_call = ToolCall {
name: "developer__shell".to_string(),
arguments: json!({
let multi_call = CallToolRequestParam {
name: "developer__shell".into(),
arguments: Some(object!({
"command": "cd /tmp && ls -la | head -5 && pwd"
}),
})),
};
let _tool_request = ToolRequest {
id: "multi-cmd".to_string(),
@@ -1027,11 +1043,11 @@ drwx------ 3 user staff 96 Dec 6 16:20 com.apple.launchd.abc
#[test]
fn test_developer_tool_grep_code_search() {
let grep_call = ToolCall {
name: "developer__shell".to_string(),
arguments: json!({
let grep_call = CallToolRequestParam {
name: "developer__shell".into(),
arguments: Some(object!({
"command": "rg 'async fn' --type rust -n"
}),
})),
};
let tool_request = ToolRequest {
id: "grep-search".to_string(),
@@ -1070,11 +1086,11 @@ src/middleware.rs:12:async fn auth_middleware(req: Request, next: Next) -> Resul
#[test]
fn test_shell_tool_json_detection_works() {
// This test shows that JSON detection in tool responses DOES work
let tool_call = ToolCall {
name: "developer__shell".to_string(),
arguments: json!({
let tool_call = CallToolRequestParam {
name: "developer__shell".into(),
arguments: Some(object!({
"command": "echo '{\"test\": \"json\"}'"
}),
})),
};
let _tool_request = ToolRequest {
id: "json-test".to_string(),
@@ -1104,11 +1120,11 @@ src/middleware.rs:12:async fn auth_middleware(req: Request, next: Next) -> Resul
#[test]
fn test_shell_tool_with_package_management() {
let npm_call = ToolCall {
name: "developer__shell".to_string(),
arguments: json!({
let npm_call = CallToolRequestParam {
name: "developer__shell".into(),
arguments: Some(object!({
"command": "npm install express typescript @types/node --save-dev"
}),
})),
};
let tool_request = ToolRequest {
id: "npm-install".to_string(),