@@ -15,10 +15,10 @@ use crate::{api::AppState, auth_middleware::RequireAuth};
1515
1616use super :: {
1717 error:: { McpError , McpErrorResponse } ,
18- tools,
18+ prompts , resources , tools,
1919 types:: {
20- InitializeParams , InitializeResult , JsonRpcRequest , JsonRpcResponse , ToolsCallParams ,
21- ToolsListResult , JSONRPC_VERSION ,
20+ InitializeParams , InitializeResult , JsonRpcRequest , JsonRpcResponse , PromptsGetParams ,
21+ ResourcesReadParams , ToolsCallParams , ToolsListResult , JSONRPC_VERSION ,
2222 } ,
2323} ;
2424
@@ -94,6 +94,11 @@ async fn route_method(
9494 "notifications/initialized" => handle_initialized_notification ( request) ,
9595 "tools/list" => handle_tools_list ( request) ,
9696 "tools/call" => handle_tools_call ( state, current_user, request) . await ,
97+ "resources/list" => handle_resources_list ( state, current_user, request) . await ,
98+ "resources/read" => handle_resources_read ( state, current_user, request) . await ,
99+ "resources/templates/list" => handle_resource_templates_list ( request) ,
100+ "prompts/list" => handle_prompts_list ( request) ,
101+ "prompts/get" => handle_prompts_get ( request) ,
97102 "ping" => handle_ping ( request) ,
98103 _ => Err ( McpError :: MethodNotFound ( request. method . clone ( ) ) ) ,
99104 }
@@ -221,6 +226,87 @@ fn handle_ping(request: &JsonRpcRequest) -> Result<(JsonRpcResponse, Option<Stri
221226 Ok ( ( response, None ) )
222227}
223228
229+ /// Handle the resources/list method.
230+ async fn handle_resources_list (
231+ state : & AppState ,
232+ current_user : & loom_server_auth:: CurrentUser ,
233+ request : & JsonRpcRequest ,
234+ ) -> Result < ( JsonRpcResponse , Option < String > ) , McpError > {
235+ tracing:: info!(
236+ user_id = %current_user. user. id,
237+ "MCP resources/list request"
238+ ) ;
239+
240+ let result = resources:: list_resources ( state, current_user) . await ?;
241+ let response = JsonRpcResponse :: success ( request. id . clone ( ) , serde_json:: to_value ( result) ?) ;
242+ Ok ( ( response, None ) )
243+ }
244+
245+ /// Handle the resources/read method.
246+ async fn handle_resources_read (
247+ state : & AppState ,
248+ current_user : & loom_server_auth:: CurrentUser ,
249+ request : & JsonRpcRequest ,
250+ ) -> Result < ( JsonRpcResponse , Option < String > ) , McpError > {
251+ let params: ResourcesReadParams = request
252+ . params
253+ . as_ref ( )
254+ . map ( |v| serde_json:: from_value ( v. clone ( ) ) )
255+ . transpose ( )
256+ . map_err ( |e| McpError :: InvalidParams ( format ! ( "Invalid resources/read params: {e}" ) ) ) ?
257+ . ok_or_else ( || McpError :: InvalidParams ( "resources/read requires params" . to_string ( ) ) ) ?;
258+
259+ tracing:: info!(
260+ uri = %params. uri,
261+ user_id = %current_user. user. id,
262+ "MCP resources/read request"
263+ ) ;
264+
265+ let result = resources:: read_resource ( state, current_user, & params. uri ) . await ?;
266+ let response = JsonRpcResponse :: success ( request. id . clone ( ) , serde_json:: to_value ( result) ?) ;
267+ Ok ( ( response, None ) )
268+ }
269+
270+ /// Handle the resources/templates/list method.
271+ fn handle_resource_templates_list (
272+ request : & JsonRpcRequest ,
273+ ) -> Result < ( JsonRpcResponse , Option < String > ) , McpError > {
274+ let result = resources:: list_resource_templates ( ) ;
275+ let response = JsonRpcResponse :: success ( request. id . clone ( ) , serde_json:: to_value ( result) ?) ;
276+ Ok ( ( response, None ) )
277+ }
278+
279+ /// Handle the prompts/list method.
280+ fn handle_prompts_list (
281+ request : & JsonRpcRequest ,
282+ ) -> Result < ( JsonRpcResponse , Option < String > ) , McpError > {
283+ let result = prompts:: list_prompts ( ) ;
284+ let response = JsonRpcResponse :: success ( request. id . clone ( ) , serde_json:: to_value ( result) ?) ;
285+ Ok ( ( response, None ) )
286+ }
287+
288+ /// Handle the prompts/get method.
289+ fn handle_prompts_get (
290+ request : & JsonRpcRequest ,
291+ ) -> Result < ( JsonRpcResponse , Option < String > ) , McpError > {
292+ let params: PromptsGetParams = request
293+ . params
294+ . as_ref ( )
295+ . map ( |v| serde_json:: from_value ( v. clone ( ) ) )
296+ . transpose ( )
297+ . map_err ( |e| McpError :: InvalidParams ( format ! ( "Invalid prompts/get params: {e}" ) ) ) ?
298+ . ok_or_else ( || McpError :: InvalidParams ( "prompts/get requires params" . to_string ( ) ) ) ?;
299+
300+ tracing:: info!(
301+ prompt_name = %params. name,
302+ "MCP prompts/get request"
303+ ) ;
304+
305+ let result = prompts:: get_prompt ( & params. name , & params. arguments ) ?;
306+ let response = JsonRpcResponse :: success ( request. id . clone ( ) , serde_json:: to_value ( result) ?) ;
307+ Ok ( ( response, None ) )
308+ }
309+
224310impl From < serde_json:: Error > for McpError {
225311 fn from ( err : serde_json:: Error ) -> Self {
226312 McpError :: Internal ( format ! ( "JSON serialization error: {err}" ) )
0 commit comments