Skip to main content

lean_ctx/tools/registered/
ctx_provider.rs

1use rmcp::model::Tool;
2use rmcp::ErrorData;
3use serde_json::{json, Map, Value};
4
5use crate::server::tool_trait::{McpTool, ToolContext, ToolOutput};
6use crate::tool_defs::tool_def;
7
8pub struct CtxProviderTool;
9
10impl McpTool for CtxProviderTool {
11    fn name(&self) -> &'static str {
12        "ctx_provider"
13    }
14
15    fn tool_def(&self) -> Tool {
16        tool_def(
17            "ctx_provider",
18            "External context provider (GitLab-first). Actions: gitlab_issues (list), gitlab_issue (show by iid), gitlab_mrs (list MRs), gitlab_pipelines (list pipelines). \
19             Requires GITLAB_TOKEN or LEAN_CTX_GITLAB_TOKEN.",
20            json!({
21                "type": "object",
22                "properties": {
23                    "action": {
24                        "type": "string",
25                        "enum": ["gitlab_issues", "gitlab_issue", "gitlab_mrs", "gitlab_pipelines"],
26                        "description": "Provider action"
27                    },
28                    "state": {
29                        "type": "string",
30                        "description": "Filter by state (opened, closed, merged, all)"
31                    },
32                    "labels": {
33                        "type": "string",
34                        "description": "Comma-separated labels filter"
35                    },
36                    "iid": {
37                        "type": "integer",
38                        "description": "Issue/MR IID for single-item lookup"
39                    },
40                    "status": {
41                        "type": "string",
42                        "description": "Pipeline status filter (running, success, failed)"
43                    },
44                    "limit": {
45                        "type": "integer",
46                        "description": "Max results (default 20, max 100)"
47                    }
48                }
49            }),
50        )
51    }
52
53    fn handle(
54        &self,
55        args: &Map<String, Value>,
56        _ctx: &ToolContext,
57    ) -> Result<ToolOutput, ErrorData> {
58        let result = crate::tools::ctx_provider::handle(args);
59        Ok(ToolOutput::simple(result))
60    }
61}