1+ use anyhow:: Result ;
12use log:: info;
23use rmcp:: {
34 ErrorData as McpError ,
45 handler:: server:: wrapper:: Parameters ,
56 model:: { CallToolResult , Content } ,
67 tool, tool_router,
78} ;
9+ use tokio:: sync:: mpsc:: { Receiver , Sender } ;
810
911use super :: {
12+ ChipmunkAI , ClientCommunication , ServerCommunication ,
1013 ai_config:: AiConfig ,
11- ai_manager :: ChipmunkAI ,
12- parameters :: { FilterParameter , SearchFilter } ,
14+ parameters :: { SearchFilter , SearchFilterParameter } ,
15+ tasks :: Task ,
1316} ;
1417
1518#[ tool_router]
1619impl ChipmunkAI {
1720 #[ allow( dead_code) ]
18- pub fn new ( config : AiConfig ) -> Self {
21+ pub fn new (
22+ config : AiConfig ,
23+ prompt_rx : Receiver < String > ,
24+ task_tx : Sender < Task > ,
25+ ui_tx : Sender < String > ,
26+ ) -> Self {
1927 Self {
2028 config,
29+ prompt_rx,
30+ ui_tx,
31+ task_tx,
2132 tool_router : Self :: tool_router ( ) ,
2233 }
2334 }
@@ -29,15 +40,15 @@ Each filter can be customized with flags for regex matching, case sensitivity, a
2940
3041**Input Parameters:**
3142- `filters`: An array of filter objects, where each object contains:
32- - `filter ` (string): The text or pattern to search for
43+ - `value ` (string): The text or pattern to search for
3344 - `is_regex` (boolean): true if the filter is a regular expression pattern
3445 - `ignore_case` (boolean): true for case-insensitive matching
3546 - `is_word` (boolean): true to match whole words only (word boundary matching)
3647
3748**Usage Examples:**
3849
3950Single filter:
40- - Input: [{"filter ": "error", "is_regex": false, "ignore_case": false, "is_word": false}]
51+ - Input: [{"value ": "error", "is_regex": false, "ignore_case": false, "is_word": false}]
4152- Use case: Find exact matches of "error"
4253
4354Multiple filters:
@@ -61,10 +72,11 @@ When the user provides natural language instructions, interpret them as follows:
6172- "regex pattern \\d+" → set is_regex: true
6273- "find ERROR, WARNING, and CRITICAL" → three separate filters
6374"# ) ]
64- async fn apply_filters (
75+ async fn apply_search_filters (
6576 & self ,
66- Parameters ( param) : Parameters < FilterParameter > ,
77+ Parameters ( param) : Parameters < SearchFilterParameter > ,
6778 ) -> Result < CallToolResult , McpError > {
79+ tracing:: debug!( "MCP: Apply search filter call received" ) ;
6880 let filters = param
6981 . filters
7082 . iter ( )
@@ -75,10 +87,16 @@ When the user provides natural language instructions, interpret them as follows:
7587 ignore_case : f. ignore_case ,
7688 } )
7789 . collect :: < Vec < SearchFilter > > ( ) ;
78- info ! ( "Received Filters from the LLM Agent: {filters:?}" ) ;
79- // TODO: Apply filter via channel
90+ tracing:: debug!( "MCP: Received Filters from the LLM Agent: {filters:?}" ) ;
91+ self . task_tx
92+ . send ( Task :: ApplyFilter {
93+ filters : filters. clone ( ) ,
94+ } )
95+ . await
96+ . map_err ( |e| McpError :: internal_error ( format ! ( "Failed to send task: {}" , e) , None ) ) ?;
97+ tracing:: debug!( "MCP: Sent ApplyFilter task to the task processor: {filters:?}" ) ;
8098 Ok ( CallToolResult :: success ( vec ! [ Content :: json(
81- "Applied filters to the logs" ,
99+ "Applied filters to the logs: {filters:?} " ,
82100 ) ?] ) )
83101 }
84102}
0 commit comments