Skip to content

Commit 0972462

Browse files
authored
Merge pull request #1291 from dcSpark/fix/default-search-tools
Add PDF Extractor and Download Pages as default web search tools.
2 parents 284a688 + 7183a38 commit 0972462

File tree

4 files changed

+91
-47
lines changed

4 files changed

+91
-47
lines changed

shinkai-bin/shinkai-node/src/llm_provider/execution/chains/generic_chain/generic_inference_chain.rs

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -821,32 +821,42 @@ impl GenericInferenceChain {
821821
.and_then(|config| config.web_search_enabled)
822822
.unwrap_or(false);
823823
if tools_allowed && web_search_enabled {
824-
// Check if web search tool is not already in the tools list
824+
// Check if web search related tools are not already in the tools list and add them
825825
let web_search_tool_key = "local:::__official_shinkai:::web_search";
826-
let has_web_search = tools
827-
.iter()
828-
.any(|tool| tool.tool_router_key().to_string_without_version() == web_search_tool_key);
829-
830-
if !has_web_search {
831-
// Add the web search tool
832-
if let Some(tool_router) = &tool_router {
833-
match tool_router.get_tool_by_name(web_search_tool_key).await {
834-
Ok(Some(web_search_tool)) => {
835-
tools.push(web_search_tool);
836-
}
837-
Ok(None) => {
838-
shinkai_log(
839-
ShinkaiLogOption::JobExecution,
840-
ShinkaiLogLevel::Error,
841-
&format!("Web search tool not found: {}", web_search_tool_key),
842-
);
843-
}
844-
Err(e) => {
845-
shinkai_log(
846-
ShinkaiLogOption::JobExecution,
847-
ShinkaiLogLevel::Error,
848-
&format!("Error retrieving web search tool: {:?}", e),
849-
);
826+
let download_pages_tool_key = "local:::__official_shinkai:::download_pages";
827+
let pdf_text_extractor_tool_key = "local:::__official_shinkai:::pdf_text_extractor";
828+
829+
let web_search_tools = vec![
830+
(web_search_tool_key, "Web search tool"),
831+
(download_pages_tool_key, "Download pages tool"),
832+
(pdf_text_extractor_tool_key, "PDF text extractor tool"),
833+
];
834+
835+
for (tool_key, tool_description) in web_search_tools {
836+
let has_tool = tools
837+
.iter()
838+
.any(|tool| tool.tool_router_key().to_string_without_version() == tool_key);
839+
840+
if !has_tool {
841+
if let Some(tool_router) = &tool_router {
842+
match tool_router.get_tool_by_name(tool_key).await {
843+
Ok(Some(tool)) => {
844+
tools.push(tool);
845+
}
846+
Ok(None) => {
847+
shinkai_log(
848+
ShinkaiLogOption::JobExecution,
849+
ShinkaiLogLevel::Error,
850+
&format!("{} not found: {}", tool_description, tool_key),
851+
);
852+
}
853+
Err(e) => {
854+
shinkai_log(
855+
ShinkaiLogOption::JobExecution,
856+
ShinkaiLogLevel::Error,
857+
&format!("Error retrieving {}: {:?}", tool_description, e),
858+
);
859+
}
850860
}
851861
}
852862
}

shinkai-libs/shinkai-mcp/src/mcp_methods.rs

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ pub mod tests_mcp_manager {
271271
let params_map = params.as_object().unwrap().clone();
272272

273273
let result = run_tool_via_command(
274-
"npx -y @modelcontextprotocol/server-everything".to_string(),
274+
"npx -y @modelcontextprotocol/server-everything@2025.9.12".to_string(),
275275
"add".to_string(),
276276
HashMap::new(),
277277
params_map,
@@ -295,7 +295,7 @@ pub mod tests_mcp_manager {
295295
"npx".to_string(),
296296
Some(vec![
297297
"-y".to_string(),
298-
"@modelcontextprotocol/server-everything".to_string(),
298+
"@modelcontextprotocol/server-everything@2025.9.12".to_string(),
299299
"sse".to_string(),
300300
]) as Option<Vec<String>>,
301301
Some(envs),
@@ -335,25 +335,31 @@ pub mod tests_mcp_manager {
335335

336336
#[tokio::test]
337337
async fn test_list_tools_via_command() {
338-
let result = list_tools_via_command("npx -y @modelcontextprotocol/server-everything", None).await;
338+
let result = list_tools_via_command("npx -y @modelcontextprotocol/server-everything@2025.9.12", None).await;
339339
assert!(result.is_ok());
340340
let unwrapped = result.unwrap();
341-
assert!(unwrapped.len() == 11);
342-
let tools = [
341+
342+
// Debug output to see actual tools
343+
println!("Actual number of tools: {}", unwrapped.len());
344+
println!("Actual tools: {:?}", unwrapped.iter().map(|t| &t.name).collect::<Vec<_>>());
345+
346+
// The MCP server-everything package now returns 10 tools
347+
assert_eq!(unwrapped.len(), 10, "Expected exactly 10 tools, got {}", unwrapped.len());
348+
349+
let expected_tools = [
343350
"echo",
344-
"add",
351+
"add",
345352
"longRunningOperation",
346353
"printEnv",
347354
"sampleLLM",
348355
"getTinyImage",
349356
"annotatedMessage",
350357
"getResourceReference",
351-
"startElicitation",
352358
"getResourceLinks",
353359
"structuredContent",
354360
];
355-
for tool in tools {
356-
assert!(unwrapped.iter().any(|t| t.name == tool));
361+
for tool in expected_tools {
362+
assert!(unwrapped.iter().any(|t| t.name == tool), "Missing expected tool: {}", tool);
357363
}
358364
}
359365

@@ -365,7 +371,7 @@ pub mod tests_mcp_manager {
365371
"npx".to_string(),
366372
Some(vec![
367373
"-y".to_string(),
368-
"@modelcontextprotocol/server-everything".to_string(),
374+
"@modelcontextprotocol/server-everything@2025.9.12".to_string(),
369375
"sse".to_string(),
370376
]) as Option<Vec<String>>,
371377
Some(envs),
@@ -390,22 +396,28 @@ pub mod tests_mcp_manager {
390396
});
391397
assert!(result.is_ok());
392398
let unwrapped = result.unwrap();
393-
assert!(unwrapped.len() == 11);
394-
let tools = [
399+
400+
// Debug output to see actual tools
401+
println!("SSE - Actual number of tools: {}", unwrapped.len());
402+
println!("SSE - Actual tools: {:?}", unwrapped.iter().map(|t| &t.name).collect::<Vec<_>>());
403+
404+
// The MCP server-everything package now returns 10 tools
405+
assert_eq!(unwrapped.len(), 10, "Expected exactly 10 tools, got {}", unwrapped.len());
406+
407+
let expected_tools = [
395408
"echo",
396-
"add",
409+
"add",
397410
"longRunningOperation",
398411
"printEnv",
399412
"sampleLLM",
400413
"getTinyImage",
401414
"annotatedMessage",
402415
"getResourceReference",
403-
"startElicitation",
404416
"getResourceLinks",
405417
"structuredContent",
406418
];
407-
for tool in tools {
408-
assert!(unwrapped.iter().any(|t| t.name == tool));
419+
for tool in expected_tools {
420+
assert!(unwrapped.iter().any(|t| t.name == tool), "Missing expected tool: {}", tool);
409421
}
410422
}
411423

@@ -417,7 +429,7 @@ pub mod tests_mcp_manager {
417429
"npx".to_string(),
418430
Some(vec![
419431
"-y".to_string(),
420-
"@modelcontextprotocol/server-everything".to_string(),
432+
"@modelcontextprotocol/server-everything@2025.9.12".to_string(),
421433
"streamableHttp".to_string(),
422434
]) as Option<Vec<String>>,
423435
Some(envs),
@@ -435,7 +447,29 @@ pub mod tests_mcp_manager {
435447
let result = list_tools_via_http("http://localhost:8002/mcp", None).await;
436448
assert!(result.is_ok());
437449
let unwrapped = result.unwrap();
438-
assert!(unwrapped.len() == 11);
450+
451+
// Debug output to see actual tools
452+
println!("HTTP - Actual number of tools: {}", unwrapped.len());
453+
println!("HTTP - Actual tools: {:?}", unwrapped.iter().map(|t| &t.name).collect::<Vec<_>>());
454+
455+
// The MCP server-everything package now returns 10 tools
456+
assert_eq!(unwrapped.len(), 10, "Expected exactly 10 tools, got {}", unwrapped.len());
457+
458+
let expected_tools = [
459+
"echo",
460+
"add",
461+
"longRunningOperation",
462+
"printEnv",
463+
"sampleLLM",
464+
"getTinyImage",
465+
"annotatedMessage",
466+
"getResourceReference",
467+
"getResourceLinks",
468+
"structuredContent",
469+
];
470+
for tool in expected_tools {
471+
assert!(unwrapped.iter().any(|t| t.name == tool), "Missing expected tool: {}", tool);
472+
}
439473
}
440474

441475
#[tokio::test]
@@ -446,7 +480,7 @@ pub mod tests_mcp_manager {
446480
"npx".to_string(),
447481
Some(vec![
448482
"-y".to_string(),
449-
"@modelcontextprotocol/server-everything".to_string(),
483+
"@modelcontextprotocol/server-everything@2025.9.12".to_string(),
450484
"streamableHttp".to_string(),
451485
]) as Option<Vec<String>>,
452486
Some(envs),

shinkai-libs/shinkai-message-primitives/src/schemas/mcp_server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ mod tests {
114114

115115
#[test]
116116
fn test_same_command_same_hash() {
117-
let server1 = create_test_server(Some("npx @modelcontextprotocol/server-everything".to_string()));
118-
let server2 = create_test_server(Some("npx @modelcontextprotocol/server-everything".to_string()));
117+
let server1 = create_test_server(Some("npx @modelcontextprotocol/server-everything@2025.9.12".to_string()));
118+
let server2 = create_test_server(Some("npx @modelcontextprotocol/server-everything@2025.9.12".to_string()));
119119

120120
let hash1 = server1.get_command_hash();
121121
let hash2 = server2.get_command_hash();

shinkai-libs/shinkai-tools-primitives/src/tools/mcp_server_tool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ mod tests {
190190
name: "@modelcontextprotocol/server-everything".to_string(),
191191
r#type: MCPServerType::Command,
192192
url: None,
193-
command: Some("npx -y @modelcontextprotocol/server-everything".to_string()),
193+
command: Some("npx -y @modelcontextprotocol/server-everything@2025.9.12".to_string()),
194194
is_enabled: true,
195195
env: None,
196196
},

0 commit comments

Comments
 (0)