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
+24 -23
View File
@@ -3,13 +3,12 @@ use std::fs::File;
use std::path::PathBuf;
use std::{env, fs};
use rmcp::model::Content;
use serde_json::json;
use rmcp::model::{CallToolRequestParam, Content};
use rmcp::object;
use tokio_util::sync::CancellationToken;
use goose::agents::extension::{Envs, ExtensionConfig};
use goose::agents::extension_manager::ExtensionManager;
use mcp_core::ToolCall;
use test_case::test_case;
@@ -21,66 +20,66 @@ enum TestMode {
#[test_case(
vec!["npx", "-y", "@modelcontextprotocol/server-everything"],
vec![
ToolCall::new("echo", json!({"message": "Hello, world!"})),
ToolCall::new("add", json!({"a": 1, "b": 2})),
ToolCall::new("longRunningOperation", json!({"duration": 1, "steps": 5})),
ToolCall::new("structuredContent", json!({"location": "11238"})),
CallToolRequestParam { name: "echo".into(), arguments: Some(object!({"message": "Hello, world!" })) },
CallToolRequestParam { name: "add".into(), arguments: Some(object!({"a": 1, "b": 2 })) },
CallToolRequestParam { name: "longRunningOperation".into(), arguments: Some(object!({"duration": 1, "steps": 5 })) },
CallToolRequestParam { name: "structuredContent".into(), arguments: Some(object!({"location": "11238"})) },
],
vec![]
)]
#[test_case(
vec!["github-mcp-server", "stdio"],
vec![
ToolCall::new("get_file_contents", json!({
CallToolRequestParam { name: "get_file_contents".into(), arguments: Some(object!({
"owner": "block",
"repo": "goose",
"path": "README.md",
"sha": "ab62b863c1666232a67048b6c4e10007a2a5b83c"
})),
}))},
],
vec!["GITHUB_PERSONAL_ACCESS_TOKEN"]
)]
#[test_case(
vec!["uvx", "mcp-server-fetch"],
vec![
ToolCall::new("fetch", json!({
CallToolRequestParam { name: "fetch".into(), arguments: Some(object!({
"url": "https://example.com",
})),
})) }
],
vec![]
)]
#[test_case(
vec!["cargo", "run", "--quiet", "-p", "goose-server", "--bin", "goosed", "--", "mcp", "developer"],
vec![
ToolCall::new("text_editor", json!({
CallToolRequestParam { name: "text_editor".into(), arguments: Some(object!({
"command": "view",
"path": "~/goose/crates/goose/tests/tmp/goose.txt"
})),
ToolCall::new("text_editor", json!({
}))},
CallToolRequestParam { name: "text_editor".into(), arguments: Some(object!({
"command": "str_replace",
"path": "~/goose/crates/goose/tests/tmp/goose.txt",
"old_str": "# goose",
"new_str": "# goose (modified by test)"
})),
}))},
// Test shell command to verify file was modified
ToolCall::new("shell", json!({
CallToolRequestParam { name: "shell".into(), arguments: Some(object!({
"command": "cat ~/goose/crates/goose/tests/tmp/goose.txt"
})),
})) },
// Test text_editor tool to restore original content
ToolCall::new("text_editor", json!({
CallToolRequestParam { name: "text_editor".into(), arguments: Some(object!({
"command": "str_replace",
"path": "~/goose/crates/goose/tests/tmp/goose.txt",
"old_str": "# goose (modified by test)",
"new_str": "# goose"
})),
ToolCall::new("list_windows", json!({})),
}))},
CallToolRequestParam { name: "list_windows".into(), arguments: Some(object!({})) },
],
vec![]
)]
#[tokio::test]
async fn test_replayed_session(
command: Vec<&str>,
tool_calls: Vec<ToolCall>,
tool_calls: Vec<CallToolRequestParam>,
required_envs: Vec<&str>,
) {
let replay_file_name = command
@@ -159,10 +158,12 @@ async fn test_replayed_session(
#[allow(clippy::redundant_closure_call)]
let result = (async || -> Result<(), Box<dyn std::error::Error>> {
extension_manager.add_extension(extension_config).await?;
let mut results = Vec::new();
for tool_call in tool_calls {
let tool_call = ToolCall::new(format!("test__{}", tool_call.name), tool_call.arguments);
let tool_call = CallToolRequestParam {
name: format!("test__{}", tool_call.name).into(),
arguments: tool_call.arguments,
};
let result = extension_manager
.dispatch_tool_call(tool_call, CancellationToken::default())
.await;