1use crate::server::MySemanticEngine;
2use serde::Deserialize;
3use std::sync::Arc;
4
5#[derive(Debug, Deserialize)]
7pub struct QueryGraphParams {
8 pub query: String,
9 pub limit: Option<u32>,
10}
11
12#[derive(Debug, Deserialize)]
14pub struct AddObservationParams {
15 pub text: String,
16 pub source: Option<String>,
17}
18
19pub struct McpServer {
22 _engine: Arc<MySemanticEngine>,
23}
24
25impl McpServer {
26 pub fn new(engine: Arc<MySemanticEngine>) -> Self {
27 Self { _engine: engine }
28 }
29
30 pub fn list_tools(&self) -> Vec<String> {
32 vec![
33 "query_knowledge_graph".to_string(),
34 "add_observation".to_string(),
35 "validate_hypothesis".to_string(),
36 ]
37 }
38
39 pub async fn call_tool(
42 &self,
43 tool_name: &str,
44 arguments: serde_json::Value,
45 ) -> Result<serde_json::Value, String> {
46 match tool_name {
47 "query_knowledge_graph" => {
48 let params: QueryGraphParams = serde_json::from_value(arguments)
49 .map_err(|e| format!("Invalid arguments: {}", e))?;
50 self.query_knowledge_graph(params).await
51 }
52 "add_observation" => {
53 let params: AddObservationParams = serde_json::from_value(arguments)
54 .map_err(|e| format!("Invalid arguments: {}", e))?;
55 self.add_observation(params).await
56 }
57 _ => Err(format!("Tool not found: {}", tool_name)),
58 }
59 }
60
61 async fn query_knowledge_graph(
62 &self,
63 _params: QueryGraphParams,
64 ) -> Result<serde_json::Value, String> {
65 Ok(serde_json::json!({
68 "results": [
69 { "node_id": 1, "content": "Mock result for query", "score": 0.9 }
70 ]
71 }))
72 }
73
74 async fn add_observation(
75 &self,
76 _params: AddObservationParams,
77 ) -> Result<serde_json::Value, String> {
78 Ok(serde_json::json!({
80 "status": "success",
81 "nodes_added": 1 }))
83 }
84}