Skip to main content

lean_ctx/tools/registered/
ctx_routes.rs

1use rmcp::model::Tool;
2use rmcp::ErrorData;
3use serde_json::{json, Map, Value};
4
5use crate::server::tool_trait::{get_str, McpTool, ToolContext, ToolOutput};
6use crate::tool_defs::tool_def;
7
8pub struct CtxRoutesTool;
9
10impl McpTool for CtxRoutesTool {
11    fn name(&self) -> &'static str {
12        "ctx_routes"
13    }
14
15    fn tool_def(&self) -> Tool {
16        tool_def(
17            "ctx_routes",
18            "List HTTP routes/endpoints extracted from the project. Supports Express, Flask, FastAPI, Actix, Spring, Rails, Next.js.",
19            json!({
20                "type": "object",
21                "properties": {
22                    "method": { "type": "string", "description": "Optional: GET, POST, PUT, DELETE" },
23                    "path": { "type": "string", "description": "Optional: path prefix filter, e.g. /api/users" }
24                }
25            }),
26        )
27    }
28
29    fn handle(
30        &self,
31        args: &Map<String, Value>,
32        ctx: &ToolContext,
33    ) -> Result<ToolOutput, ErrorData> {
34        let method = get_str(args, "method");
35        // "path" here is an HTTP route prefix, not a filesystem path
36        let path_prefix = get_str(args, "path");
37
38        let result = crate::tools::ctx_routes::handle(
39            method.as_deref(),
40            path_prefix.as_deref(),
41            &ctx.project_root,
42        );
43
44        Ok(ToolOutput::simple(result))
45    }
46}