From 7cb65d491bf5bb51d8adb585d6d5f51060b892a2 Mon Sep 17 00:00:00 2001 From: Guillermo Valin Date: Wed, 17 Sep 2025 17:31:08 -0300 Subject: [PATCH 1/2] Add PDF Extractor and Download Pages as default web search tools. --- .../generic_chain/generic_inference_chain.rs | 60 +++++++++++-------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/shinkai-bin/shinkai-node/src/llm_provider/execution/chains/generic_chain/generic_inference_chain.rs b/shinkai-bin/shinkai-node/src/llm_provider/execution/chains/generic_chain/generic_inference_chain.rs index a189b36fb..2cb531e5d 100644 --- a/shinkai-bin/shinkai-node/src/llm_provider/execution/chains/generic_chain/generic_inference_chain.rs +++ b/shinkai-bin/shinkai-node/src/llm_provider/execution/chains/generic_chain/generic_inference_chain.rs @@ -821,32 +821,42 @@ impl GenericInferenceChain { .and_then(|config| config.web_search_enabled) .unwrap_or(false); if tools_allowed && web_search_enabled { - // Check if web search tool is not already in the tools list + // Check if web search related tools are not already in the tools list and add them let web_search_tool_key = "local:::__official_shinkai:::web_search"; - let has_web_search = tools - .iter() - .any(|tool| tool.tool_router_key().to_string_without_version() == web_search_tool_key); - - if !has_web_search { - // Add the web search tool - if let Some(tool_router) = &tool_router { - match tool_router.get_tool_by_name(web_search_tool_key).await { - Ok(Some(web_search_tool)) => { - tools.push(web_search_tool); - } - Ok(None) => { - shinkai_log( - ShinkaiLogOption::JobExecution, - ShinkaiLogLevel::Error, - &format!("Web search tool not found: {}", web_search_tool_key), - ); - } - Err(e) => { - shinkai_log( - ShinkaiLogOption::JobExecution, - ShinkaiLogLevel::Error, - &format!("Error retrieving web search tool: {:?}", e), - ); + let download_pages_tool_key = "local:::__official_shinkai:::download_pages"; + let pdf_text_extractor_tool_key = "local:::__official_shinkai:::pdf_text_extractor"; + + let web_search_tools = vec![ + (web_search_tool_key, "Web search tool"), + (download_pages_tool_key, "Download pages tool"), + (pdf_text_extractor_tool_key, "PDF text extractor tool"), + ]; + + for (tool_key, tool_description) in web_search_tools { + let has_tool = tools + .iter() + .any(|tool| tool.tool_router_key().to_string_without_version() == tool_key); + + if !has_tool { + if let Some(tool_router) = &tool_router { + match tool_router.get_tool_by_name(tool_key).await { + Ok(Some(tool)) => { + tools.push(tool); + } + Ok(None) => { + shinkai_log( + ShinkaiLogOption::JobExecution, + ShinkaiLogLevel::Error, + &format!("{} not found: {}", tool_description, tool_key), + ); + } + Err(e) => { + shinkai_log( + ShinkaiLogOption::JobExecution, + ShinkaiLogLevel::Error, + &format!("Error retrieving {}: {:?}", tool_description, e), + ); + } } } } From 7183a38309c1b90c2bdc602a4f17945c5fdb3a3b Mon Sep 17 00:00:00 2001 From: Guillermo Valin Date: Wed, 17 Sep 2025 18:05:34 -0300 Subject: [PATCH 2/2] Pin server-everything MCP server version. --- shinkai-libs/shinkai-mcp/src/mcp_methods.rs | 72 ++++++++++++++----- .../src/schemas/mcp_server.rs | 4 +- .../src/tools/mcp_server_tool.rs | 2 +- 3 files changed, 56 insertions(+), 22 deletions(-) diff --git a/shinkai-libs/shinkai-mcp/src/mcp_methods.rs b/shinkai-libs/shinkai-mcp/src/mcp_methods.rs index 541663677..6e8b035cc 100644 --- a/shinkai-libs/shinkai-mcp/src/mcp_methods.rs +++ b/shinkai-libs/shinkai-mcp/src/mcp_methods.rs @@ -271,7 +271,7 @@ pub mod tests_mcp_manager { let params_map = params.as_object().unwrap().clone(); let result = run_tool_via_command( - "npx -y @modelcontextprotocol/server-everything".to_string(), + "npx -y @modelcontextprotocol/server-everything@2025.9.12".to_string(), "add".to_string(), HashMap::new(), params_map, @@ -295,7 +295,7 @@ pub mod tests_mcp_manager { "npx".to_string(), Some(vec![ "-y".to_string(), - "@modelcontextprotocol/server-everything".to_string(), + "@modelcontextprotocol/server-everything@2025.9.12".to_string(), "sse".to_string(), ]) as Option>, Some(envs), @@ -335,25 +335,31 @@ pub mod tests_mcp_manager { #[tokio::test] async fn test_list_tools_via_command() { - let result = list_tools_via_command("npx -y @modelcontextprotocol/server-everything", None).await; + let result = list_tools_via_command("npx -y @modelcontextprotocol/server-everything@2025.9.12", None).await; assert!(result.is_ok()); let unwrapped = result.unwrap(); - assert!(unwrapped.len() == 11); - let tools = [ + + // Debug output to see actual tools + println!("Actual number of tools: {}", unwrapped.len()); + println!("Actual tools: {:?}", unwrapped.iter().map(|t| &t.name).collect::>()); + + // The MCP server-everything package now returns 10 tools + assert_eq!(unwrapped.len(), 10, "Expected exactly 10 tools, got {}", unwrapped.len()); + + let expected_tools = [ "echo", - "add", + "add", "longRunningOperation", "printEnv", "sampleLLM", "getTinyImage", "annotatedMessage", "getResourceReference", - "startElicitation", "getResourceLinks", "structuredContent", ]; - for tool in tools { - assert!(unwrapped.iter().any(|t| t.name == tool)); + for tool in expected_tools { + assert!(unwrapped.iter().any(|t| t.name == tool), "Missing expected tool: {}", tool); } } @@ -365,7 +371,7 @@ pub mod tests_mcp_manager { "npx".to_string(), Some(vec![ "-y".to_string(), - "@modelcontextprotocol/server-everything".to_string(), + "@modelcontextprotocol/server-everything@2025.9.12".to_string(), "sse".to_string(), ]) as Option>, Some(envs), @@ -390,22 +396,28 @@ pub mod tests_mcp_manager { }); assert!(result.is_ok()); let unwrapped = result.unwrap(); - assert!(unwrapped.len() == 11); - let tools = [ + + // Debug output to see actual tools + println!("SSE - Actual number of tools: {}", unwrapped.len()); + println!("SSE - Actual tools: {:?}", unwrapped.iter().map(|t| &t.name).collect::>()); + + // The MCP server-everything package now returns 10 tools + assert_eq!(unwrapped.len(), 10, "Expected exactly 10 tools, got {}", unwrapped.len()); + + let expected_tools = [ "echo", - "add", + "add", "longRunningOperation", "printEnv", "sampleLLM", "getTinyImage", "annotatedMessage", "getResourceReference", - "startElicitation", "getResourceLinks", "structuredContent", ]; - for tool in tools { - assert!(unwrapped.iter().any(|t| t.name == tool)); + for tool in expected_tools { + assert!(unwrapped.iter().any(|t| t.name == tool), "Missing expected tool: {}", tool); } } @@ -417,7 +429,7 @@ pub mod tests_mcp_manager { "npx".to_string(), Some(vec![ "-y".to_string(), - "@modelcontextprotocol/server-everything".to_string(), + "@modelcontextprotocol/server-everything@2025.9.12".to_string(), "streamableHttp".to_string(), ]) as Option>, Some(envs), @@ -435,7 +447,29 @@ pub mod tests_mcp_manager { let result = list_tools_via_http("http://localhost:8002/mcp", None).await; assert!(result.is_ok()); let unwrapped = result.unwrap(); - assert!(unwrapped.len() == 11); + + // Debug output to see actual tools + println!("HTTP - Actual number of tools: {}", unwrapped.len()); + println!("HTTP - Actual tools: {:?}", unwrapped.iter().map(|t| &t.name).collect::>()); + + // The MCP server-everything package now returns 10 tools + assert_eq!(unwrapped.len(), 10, "Expected exactly 10 tools, got {}", unwrapped.len()); + + let expected_tools = [ + "echo", + "add", + "longRunningOperation", + "printEnv", + "sampleLLM", + "getTinyImage", + "annotatedMessage", + "getResourceReference", + "getResourceLinks", + "structuredContent", + ]; + for tool in expected_tools { + assert!(unwrapped.iter().any(|t| t.name == tool), "Missing expected tool: {}", tool); + } } #[tokio::test] @@ -446,7 +480,7 @@ pub mod tests_mcp_manager { "npx".to_string(), Some(vec![ "-y".to_string(), - "@modelcontextprotocol/server-everything".to_string(), + "@modelcontextprotocol/server-everything@2025.9.12".to_string(), "streamableHttp".to_string(), ]) as Option>, Some(envs), diff --git a/shinkai-libs/shinkai-message-primitives/src/schemas/mcp_server.rs b/shinkai-libs/shinkai-message-primitives/src/schemas/mcp_server.rs index bf3cf8d99..4738a9044 100644 --- a/shinkai-libs/shinkai-message-primitives/src/schemas/mcp_server.rs +++ b/shinkai-libs/shinkai-message-primitives/src/schemas/mcp_server.rs @@ -114,8 +114,8 @@ mod tests { #[test] fn test_same_command_same_hash() { - let server1 = create_test_server(Some("npx @modelcontextprotocol/server-everything".to_string())); - let server2 = create_test_server(Some("npx @modelcontextprotocol/server-everything".to_string())); + let server1 = create_test_server(Some("npx @modelcontextprotocol/server-everything@2025.9.12".to_string())); + let server2 = create_test_server(Some("npx @modelcontextprotocol/server-everything@2025.9.12".to_string())); let hash1 = server1.get_command_hash(); let hash2 = server2.get_command_hash(); diff --git a/shinkai-libs/shinkai-tools-primitives/src/tools/mcp_server_tool.rs b/shinkai-libs/shinkai-tools-primitives/src/tools/mcp_server_tool.rs index 4972d5c4c..50841ae9e 100644 --- a/shinkai-libs/shinkai-tools-primitives/src/tools/mcp_server_tool.rs +++ b/shinkai-libs/shinkai-tools-primitives/src/tools/mcp_server_tool.rs @@ -190,7 +190,7 @@ mod tests { name: "@modelcontextprotocol/server-everything".to_string(), r#type: MCPServerType::Command, url: None, - command: Some("npx -y @modelcontextprotocol/server-everything".to_string()), + command: Some("npx -y @modelcontextprotocol/server-everything@2025.9.12".to_string()), is_enabled: true, env: None, },