Skip to content

Commit bf4a75b

Browse files
Execute chipmunk search call for ApplyFilter message
1 parent 6223dba commit bf4a75b

File tree

6 files changed

+58
-26
lines changed

6 files changed

+58
-26
lines changed

application/apps/indexer/mcp/src/server/messages.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,11 @@ pub enum McpServerToChipmunk {
1111
},
1212
}
1313

14-
// TODO: Mock
15-
pub type SearchFilter = String;
14+
// TODO: MOCK
15+
#[derive(Debug)]
16+
pub struct SearchFilter {
17+
pub value: String,
18+
pub is_regex: bool,
19+
pub ignore_case: bool,
20+
pub is_word: bool,
21+
}

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ impl McpServer {
4040

4141
let (response_tx, response_rx) = oneshot::channel();
4242

43-
let filters = vec![SearchFilter::from("Test")];
43+
let filters = vec![SearchFilter {
44+
value: String::from("icmp_seq=13"),
45+
is_regex: false,
46+
ignore_case: true,
47+
is_word: true,
48+
}];
4449

4550
let message = McpServerToChipmunk::ApplyFilter {
4651
filters,
@@ -54,10 +59,18 @@ impl McpServer {
5459
return;
5560
}
5661

57-
if let Err(err) = response_rx.await {
58-
error!(
59-
"[Chipmunk] -X-> [MCP server]: server failed to receive response: ApplyFilter: {err}"
60-
);
62+
match response_rx.await {
63+
Err(err) => {
64+
error!(
65+
"[Chipmunk] -X-> [MCP server]: server failed to receive response: ApplyFilter: {err}"
66+
);
67+
}
68+
Ok(result) => {
69+
error!(
70+
"[Chipmunk] --> [MCP server]: ✅ Received response: {:?}",
71+
result
72+
)
73+
}
6174
}
6275
}
6376
}

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,16 @@ use std::fmt;
33
#[derive(Debug)]
44
pub enum McpError {
55
Generic { message: String },
6+
ApplyFilter { message: String },
67
}
78

89
impl fmt::Display for McpError {
910
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1011
match self {
1112
McpError::Generic { message } => write!(f, "{}", message),
13+
McpError::ApplyFilter { message } => write!(f, "{}", message),
1214
}
1315
}
1416
}
1517

1618
impl std::error::Error for McpError {}
17-
18-
impl McpError {
19-
pub fn generic(message: impl Into<String>) -> Self {
20-
McpError::Generic {
21-
message: message.into(),
22-
}
23-
}
24-
}

application/apps/indexer/session/src/mcp_api/mod.rs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
use crate::operations::{Operation, OperationKind};
12
use crate::state::SessionStateAPI;
23
use crate::tracker::OperationTrackerAPI;
34
use log::error;
45
use mcp::McpChannelEndpoints;
56
use mcp::client::messages::{McpChipmunkToClient, McpClientToChipmunk};
67
use mcp::server::messages::McpServerToChipmunk;
8+
use mcp::types::McpError;
9+
use processor::search::filter::SearchFilter;
710
use tokio::select;
811
use tokio::sync::mpsc;
912
use tokio::sync::mpsc::UnboundedSender;
13+
use uuid::Uuid;
1014

1115
#[derive(Debug, Clone)]
1216
pub struct McpApi {
@@ -43,30 +47,43 @@ impl McpApi {
4347
}
4448

4549
pub async fn run(
50+
session_uuid: Uuid,
4651
mut server_to_chipmunk_rx: tokio::sync::mpsc::Receiver<McpServerToChipmunk>,
4752
mut client_to_chipmunk_rx: tokio::sync::mpsc::Receiver<McpClientToChipmunk>,
53+
tx_operations: UnboundedSender<Operation>,
4854
state_api: SessionStateAPI,
4955
tracker_api: OperationTrackerAPI,
5056
tx_callback_events: UnboundedSender<stypes::CallbackEvent>,
5157
) {
5258
loop {
5359
select! {
54-
Some(message) = server_to_chipmunk_rx.recv() => {
55-
match message {
60+
Some(server_request) = server_to_chipmunk_rx.recv() => {
61+
match server_request {
5662
McpServerToChipmunk::ApplyFilter {filters, response_tx} => {
57-
// TODO: Impelment functionality
58-
// state_api.set_matches(None, None).await;
5963

60-
if let Err(err) = response_tx.send(Ok(())) {
61-
error!("\t[Chipmunk] -X-> [MCP server]: chipmunk failed to send response: ApplyFilter: {:?}", err);
62-
}
64+
error!(
65+
"[Chipmunk] received filters: {:?}", filters
66+
);
67+
68+
let filters = filters.iter().map(|f| SearchFilter::new(f.value.clone(), f.is_regex, f.ignore_case, f.is_word)).collect();
6369

70+
// Create a new Operation
71+
let operation = Operation::new(
72+
session_uuid,
73+
OperationKind::Search { filters },
74+
);
75+
76+
if let Err(err) = tx_operations.send(operation) {
77+
let _ = response_tx.send(Err(McpError::ApplyFilter {message: err.to_string(),}));
78+
} else {
79+
let _ = response_tx.send(Ok(()));
80+
}
6481

6582
}
6683
}
6784
}
68-
Some(message) = client_to_chipmunk_rx.recv() => {
69-
match message {
85+
Some(client_request) = client_to_chipmunk_rx.recv() => {
86+
match client_request {
7087
McpClientToChipmunk::Response {..} => {
7188
// TODO: Implement functionality
7289
}

application/apps/indexer/session/src/session.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ impl Session {
105105
async {
106106
join!(
107107
mcp_api::run(
108+
uuid,
108109
mcp_server_to_chipmunk_rx,
109110
mcp_client_to_chipmunk_rx,
111+
tx_operations.clone(),
110112
state_api.clone(),
111113
tracker_api.clone(),
112114
tx_callback_events.clone(),

application/apps/indexer/session/src/state/api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use tokio_util::sync::CancellationToken;
2929
use uuid::Uuid;
3030

3131
pub enum Api {
32-
// TODO: Do we need to keep track of context. E.g. store a promptID?
32+
// TODO: Can this be removed? Do we need to keep track of context. E.g. store a promptID?
3333
SendChatPrompt(String),
3434
SetSessionFile(
3535
(
@@ -266,7 +266,7 @@ impl Display for Api {
266266
}
267267

268268
#[derive(Clone, Debug)]
269-
pub struct SessionStateAPI {
269+
pub struct SessionStateAPI {
270270
tx_api: UnboundedSender<Api>,
271271
tracker: OperationTrackerAPI,
272272
closing_token: CancellationToken,

0 commit comments

Comments
 (0)