lean_ctx/tools/registered/
ctx_provider.rs1use 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 providers (GitHub, GitLab, more). \
19 Use action=discover to list available providers. \
20 Use action=query with provider+resource for registry-based access. \
21 Legacy GitLab actions still supported. \
22 Set GITHUB_TOKEN or GITLAB_TOKEN to enable providers.",
23 json!({
24 "type": "object",
25 "properties": {
26 "action": {
27 "type": "string",
28 "enum": [
29 "discover",
30 "query",
31 "gitlab_issues",
32 "gitlab_issue",
33 "gitlab_mrs",
34 "gitlab_pipelines"
35 ],
36 "description": "Provider action. 'discover' lists all providers. 'query' uses registry routing (requires provider+resource)."
37 },
38 "provider": {
39 "type": "string",
40 "description": "Provider ID for action=query (e.g. 'github', 'gitlab')"
41 },
42 "resource": {
43 "type": "string",
44 "description": "Resource type for action=query (e.g. 'issues', 'pull_requests', 'actions')"
45 },
46 "mode": {
47 "type": "string",
48 "enum": ["compact", "chunks"],
49 "description": "Output mode for action=query. 'compact' (default) returns formatted text. 'chunks' returns ContentChunk metadata for BM25/embedding ingest."
50 },
51 "state": {
52 "type": "string",
53 "description": "Filter by state (open, closed, merged, all)"
54 },
55 "labels": {
56 "type": "string",
57 "description": "Comma-separated labels filter (GitLab)"
58 },
59 "iid": {
60 "type": "integer",
61 "description": "Issue/MR IID for single-item lookup (GitLab)"
62 },
63 "status": {
64 "type": "string",
65 "description": "Pipeline/Actions status filter (running, success, failed)"
66 },
67 "limit": {
68 "type": "integer",
69 "description": "Max results (default 20, max 100)"
70 }
71 },
72 "required": ["action"]
73 }),
74 )
75 }
76
77 fn handle(
78 &self,
79 args: &Map<String, Value>,
80 ctx: &ToolContext,
81 ) -> Result<ToolOutput, ErrorData> {
82 let result = crate::tools::ctx_provider::handle(args, ctx);
83 Ok(ToolOutput::simple(result))
84 }
85}