Revert "Internal MCP Crate Cleanup (#4800)" (#4883)

This commit is contained in:
Alex Hancock
2025-09-29 14:21:30 -04:00
committed by GitHub
parent 2cfef016e2
commit b9ba8dca29
78 changed files with 1090 additions and 844 deletions
+68 -84
View File
@@ -127,11 +127,9 @@ pub fn tool_request_to_markdown(req: &ToolRequest, export_all_content: bool) ->
));
md.push_str("**Arguments:**\n");
match call.name.as_ref() {
match call.name.as_str() {
"developer__shell" => {
if let Some(Value::String(command)) =
call.arguments.as_ref().and_then(|args| args.get("command"))
{
if let Some(Value::String(command)) = call.arguments.get("command") {
md.push_str(&format!(
"* **command**:\n ```sh\n {}\n ```\n",
command.trim()
@@ -139,7 +137,7 @@ pub fn tool_request_to_markdown(req: &ToolRequest, export_all_content: bool) ->
}
let other_args: serde_json::Map<String, Value> = call
.arguments
.as_ref()
.as_object()
.map(|obj| {
obj.iter()
.filter(|(k, _)| k.as_str() != "command")
@@ -156,16 +154,10 @@ pub fn tool_request_to_markdown(req: &ToolRequest, export_all_content: bool) ->
}
}
"developer__text_editor" => {
if let Some(Value::String(path)) =
call.arguments.as_ref().and_then(|args| args.get("path"))
{
if let Some(Value::String(path)) = call.arguments.get("path") {
md.push_str(&format!("* **path**: `{}`\n", path));
}
if let Some(Value::String(code_edit)) = call
.arguments
.as_ref()
.and_then(|args| args.get("code_edit"))
{
if let Some(Value::String(code_edit)) = call.arguments.get("code_edit") {
md.push_str(&format!(
"* **code_edit**:\n ```\n{}\n ```\n",
code_edit
@@ -174,7 +166,7 @@ pub fn tool_request_to_markdown(req: &ToolRequest, export_all_content: bool) ->
let other_args: serde_json::Map<String, Value> = call
.arguments
.as_ref()
.as_object()
.map(|obj| {
obj.iter()
.filter(|(k, _)| k.as_str() != "path" && k.as_str() != "code_edit")
@@ -191,15 +183,7 @@ pub fn tool_request_to_markdown(req: &ToolRequest, export_all_content: bool) ->
}
}
_ => {
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");
}
md.push_str(&value_to_markdown(&call.arguments, 0, export_all_content));
}
}
}
@@ -386,8 +370,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 rmcp::model::{CallToolRequestParam, Content, RawTextContent, TextContent};
use rmcp::object;
use mcp_core::tool::ToolCall;
use rmcp::model::{Content, RawTextContent, TextContent};
use serde_json::json;
#[test]
@@ -502,12 +486,12 @@ mod tests {
#[test]
fn test_tool_request_to_markdown_shell() {
let tool_call = CallToolRequestParam {
name: "developer__shell".into(),
arguments: Some(object!({
let tool_call = ToolCall {
name: "developer__shell".to_string(),
arguments: json!({
"command": "ls -la",
"working_dir": "/home/user"
})),
}),
};
let tool_request = ToolRequest {
id: "test-id".to_string(),
@@ -525,12 +509,12 @@ mod tests {
#[test]
fn test_tool_request_to_markdown_text_editor() {
let tool_call = CallToolRequestParam {
name: "developer__text_editor".into(),
arguments: Some(object!({
let tool_call = ToolCall {
name: "developer__text_editor".to_string(),
arguments: json!({
"path": "/path/to/file.txt",
"code_edit": "print('Hello World')"
})),
}),
};
let tool_request = ToolRequest {
id: "test-id".to_string(),
@@ -594,9 +578,9 @@ mod tests {
#[test]
fn test_message_to_markdown_with_tool_request() {
let tool_call = CallToolRequestParam {
name: "test_tool".into(),
arguments: Some(object!({"param": "value"})),
let tool_call = ToolCall {
name: "test_tool".to_string(),
arguments: json!({"param": "value"}),
};
let message = Message::assistant().with_tool_request("test-id", Ok(tool_call));
@@ -653,11 +637,11 @@ mod tests {
#[test]
fn test_shell_tool_with_code_output() {
let tool_call = CallToolRequestParam {
name: "developer__shell".into(),
arguments: Some(object!({
let tool_call = ToolCall {
name: "developer__shell".to_string(),
arguments: json!({
"command": "cat main.py"
})),
}),
};
let tool_request = ToolRequest {
id: "shell-cat".to_string(),
@@ -699,11 +683,11 @@ if __name__ == "__main__":
#[test]
fn test_shell_tool_with_git_commands() {
let git_status_call = CallToolRequestParam {
name: "developer__shell".into(),
arguments: Some(object!({
let git_status_call = ToolCall {
name: "developer__shell".to_string(),
arguments: json!({
"command": "git status --porcelain"
})),
}),
};
let tool_request = ToolRequest {
id: "git-status".to_string(),
@@ -737,11 +721,11 @@ if __name__ == "__main__":
#[test]
fn test_shell_tool_with_build_output() {
let cargo_build_call = CallToolRequestParam {
name: "developer__shell".into(),
arguments: Some(object!({
let cargo_build_call = ToolCall {
name: "developer__shell".to_string(),
arguments: json!({
"command": "cargo build"
})),
}),
};
let _tool_request = ToolRequest {
id: "cargo-build".to_string(),
@@ -781,11 +765,11 @@ warning: unused variable `x`
#[test]
fn test_shell_tool_with_json_api_response() {
let curl_call = CallToolRequestParam {
name: "developer__shell".into(),
arguments: Some(object!({
let curl_call = ToolCall {
name: "developer__shell".to_string(),
arguments: json!({
"command": "curl -s https://api.github.com/repos/microsoft/vscode/releases/latest"
})),
}),
};
let _tool_request = ToolRequest {
id: "curl-api".to_string(),
@@ -827,13 +811,13 @@ warning: unused variable `x`
#[test]
fn test_text_editor_tool_with_code_creation() {
let editor_call = CallToolRequestParam {
name: "developer__text_editor".into(),
arguments: Some(object!({
let editor_call = ToolCall {
name: "developer__text_editor".to_string(),
arguments: json!({
"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(),
@@ -868,12 +852,12 @@ warning: unused variable `x`
#[test]
fn test_text_editor_tool_view_code() {
let editor_call = CallToolRequestParam {
name: "developer__text_editor".into(),
arguments: Some(object!({
let editor_call = ToolCall {
name: "developer__text_editor".to_string(),
arguments: json!({
"command": "view",
"path": "/src/utils.py"
})),
}),
};
let _tool_request = ToolRequest {
id: "editor-view".to_string(),
@@ -918,11 +902,11 @@ def process_data(data: List[Dict]) -> List[Dict]:
#[test]
fn test_shell_tool_with_error_output() {
let error_call = CallToolRequestParam {
name: "developer__shell".into(),
arguments: Some(object!({
let error_call = ToolCall {
name: "developer__shell".to_string(),
arguments: json!({
"command": "python nonexistent_script.py"
})),
}),
};
let _tool_request = ToolRequest {
id: "shell-error".to_string(),
@@ -953,11 +937,11 @@ Command failed with exit code 2"#;
#[test]
fn test_shell_tool_complex_script_execution() {
let script_call = CallToolRequestParam {
name: "developer__shell".into(),
arguments: Some(object!({
let script_call = ToolCall {
name: "developer__shell".to_string(),
arguments: json!({
"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(),
@@ -999,11 +983,11 @@ Command failed with exit code 2"#;
#[test]
fn test_shell_tool_with_multi_command() {
let multi_call = CallToolRequestParam {
name: "developer__shell".into(),
arguments: Some(object!({
let multi_call = ToolCall {
name: "developer__shell".to_string(),
arguments: json!({
"command": "cd /tmp && ls -la | head -5 && pwd"
})),
}),
};
let _tool_request = ToolRequest {
id: "multi-cmd".to_string(),
@@ -1043,11 +1027,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 = CallToolRequestParam {
name: "developer__shell".into(),
arguments: Some(object!({
let grep_call = ToolCall {
name: "developer__shell".to_string(),
arguments: json!({
"command": "rg 'async fn' --type rust -n"
})),
}),
};
let tool_request = ToolRequest {
id: "grep-search".to_string(),
@@ -1086,11 +1070,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 = CallToolRequestParam {
name: "developer__shell".into(),
arguments: Some(object!({
let tool_call = ToolCall {
name: "developer__shell".to_string(),
arguments: json!({
"command": "echo '{\"test\": \"json\"}'"
})),
}),
};
let _tool_request = ToolRequest {
id: "json-test".to_string(),
@@ -1120,11 +1104,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 = CallToolRequestParam {
name: "developer__shell".into(),
arguments: Some(object!({
let npm_call = ToolCall {
name: "developer__shell".to_string(),
arguments: json!({
"command": "npm install express typescript @types/node --save-dev"
})),
}),
};
let tool_request = ToolRequest {
id: "npm-install".to_string(),