Skip to content

Commit b920b77

Browse files
TOOL-519: Mock LLM client prototype
1 parent e80f2b4 commit b920b77

File tree

5 files changed

+92
-16
lines changed

5 files changed

+92
-16
lines changed

application/apps/indexer/mcp/src/client/llm.rs

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/// Mock
2+
use rmcp::serde_json;
3+
use std::time::Duration;
4+
use tokio::time::sleep;
5+
6+
use super::{LlmClient, LlmRequest, LlmResponse, McpError};
7+
8+
pub struct MockLlmClient;
9+
10+
impl LlmClient for MockLlmClient {
11+
async fn complete(&self, messages: Vec<LlmRequest>) -> Result<LlmResponse, McpError> {
12+
match messages.last() {
13+
Some(LlmRequest::UserPrompt { content }) => {
14+
// Wait 5 seconds to simulate the LLm processing
15+
sleep(Duration::from_secs(5)).await;
16+
// TODO: Try using content as filter value insead
17+
let filter_value = "icmp_seq=13";
18+
let tool_call = LlmResponse::ToolCall {
19+
tool_name: "apply_filter".into(),
20+
arguments: serde_json::json!({
21+
"filters": [
22+
{
23+
"value": filter_value,
24+
"is_regex": false,
25+
"ignore_case": true,
26+
"is_word": true
27+
}
28+
]
29+
}),
30+
};
31+
Ok(tool_call)
32+
}
33+
Some(LlmRequest::ToolResult { content }) => {
34+
// Wait 3 seconds to simulate the LLm processing
35+
sleep(Duration::from_secs(3)).await;
36+
let final_response = LlmResponse::FinalResponse {
37+
content: format!("Final LLM Answer: Tool result {}", content),
38+
};
39+
Ok(final_response)
40+
}
41+
_ => Err(McpError::Generic {
42+
message: "Mock LLM Client received unsupported request".into(),
43+
}),
44+
}
45+
}
46+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use rmcp::serde_json::Value;
2+
3+
use crate::types::McpError;
4+
5+
pub mod mock;
6+
7+
// Client requests to the LLM
8+
pub enum LlmRequest {
9+
SystemPrompt { content: String },
10+
UserPrompt { content: String },
11+
ToolResult { content: String },
12+
}
13+
14+
// LLM responses to the client
15+
pub enum LlmResponse {
16+
FinalResponse { content: String },
17+
ToolCall { tool_name: String, arguments: Value },
18+
}
19+
20+
pub trait LlmClient: Send + Sync {
21+
async fn complete(&self, messages: Vec<LlmRequest>) -> Result<LlmResponse, McpError>;
22+
}
23+
24+
pub enum LlmConfig {
25+
Mock,
26+
// TODO: Add other LlmConfig variants here. E.g.:
27+
// OpenAi { api_key: String, model: String },
28+
}
29+
30+
pub enum LlmBackend {
31+
Mock(mock::MockLlmClient),
32+
// OpenAi(openai::OpenAiClient),
33+
}
34+
35+
impl LlmClient for LlmBackend {
36+
async fn complete(&self, messages: Vec<LlmRequest>) -> Result<LlmResponse, McpError> {
37+
match self {
38+
LlmBackend::Mock(client) => client.complete(messages).await,
39+
}
40+
}
41+
}

application/apps/indexer/mcp/src/client/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use tokio::{select, sync::mpsc};
44

55
use rmcp::{
66
RoleClient,
7-
model::{ClientInfo, Implementation, InitializeRequestParam},
7+
model::{CallToolRequestParam, ClientInfo, Implementation, InitializeRequestParam},
88
service::{RunningService, ServiceExt},
99
transport::StreamableHttpClientTransport,
1010
};
@@ -71,7 +71,7 @@ impl MCPClient {
7171
},
7272
};
7373

74-
let mcp_service = client_info
74+
let mcp_service: RunningService<RoleClient, InitializeRequestParam> = client_info
7575
.serve(transport)
7676
.await
7777
.map_err(|e| McpError::Generic {
@@ -83,6 +83,7 @@ impl MCPClient {
8383
let chipmunk_to_client_rx = self.chipmunk_to_client_rx;
8484

8585
let tools = mcp_service.list_tools(Default::default()).await?;
86+
warn!("Available tools: {:?}", tools);
8687

8788
let chipmunk_response_tx = self.client_to_chipmunk_tx.clone();
8889

application/apps/indexer/mcp/src/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@ pub struct McpChannelEndpoints {
2020
}
2121

2222
pub fn new() -> (McpServer, MCPClient, McpChannelEndpoints) {
23-
let llm_config = LlmConfig::Dummy {
24-
api_key: String::default(),
25-
model: None,
26-
};
23+
let llm_config = LlmConfig::Mock {};
2724
let mcp_config = McpConfig {
28-
url: String::from("http//:localhost:8080/chipmunk_mcp"),
25+
url: String::from("http//:localhost:8181"),
2926
};
3027
let (mcp_client, chipmunk_to_client_tx, client_to_chipmunk_rx) =
3128
MCPClient::new(mcp_config, llm_config);

0 commit comments

Comments
 (0)