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, Jira, Postgres, custom). \
19 action=discover|list: list registered providers. \
20 action=status: provider health + cache metrics. \
21 action=refresh: invalidate cache + re-fetch (provider= optional). \
22 action=configure: show config (resource=paths|template for details). \
23 action=query: provider+resource for data access. \
24 Legacy GitLab actions still supported.",
25 json!({
26 "type": "object",
27 "properties": {
28 "action": {
29 "type": "string",
30 "enum": [
31 "discover",
32 "list",
33 "status",
34 "refresh",
35 "configure",
36 "query",
37 "mcp_resources",
38 "gitlab_issues",
39 "gitlab_issue",
40 "gitlab_mrs",
41 "gitlab_pipelines"
42 ],
43 "description": "Provider action. 'discover'/'list' lists all. 'status' shows health+cache. 'refresh' invalidates+re-fetches. 'configure' shows config. 'query' uses registry routing."
44 },
45 "provider": {
46 "type": "string",
47 "description": "Provider ID (e.g. 'github', 'gitlab', 'jira', 'mcp:my-kb'). Required for query, optional for refresh (omit to refresh all)."
48 },
49 "resource": {
50 "type": "string",
51 "description": "Resource type for action=query (e.g. 'issues', 'pull_requests'). For configure: 'paths'|'template'|'show'."
52 },
53 "mode": {
54 "type": "string",
55 "enum": ["compact", "chunks"],
56 "description": "Output mode for action=query. 'compact' (default) or 'chunks' for BM25/embedding ingest."
57 },
58 "state": {
59 "type": "string",
60 "description": "Filter by state (open, closed, merged, all)"
61 },
62 "labels": {
63 "type": "string",
64 "description": "Comma-separated labels filter (GitLab)"
65 },
66 "iid": {
67 "type": "integer",
68 "description": "Issue/MR IID for single-item lookup (GitLab)"
69 },
70 "status": {
71 "type": "string",
72 "description": "Pipeline/Actions status filter (running, success, failed)"
73 },
74 "limit": {
75 "type": "integer",
76 "description": "Max results (default 20, max 100)"
77 }
78 },
79 "required": ["action"]
80 }),
81 )
82 }
83
84 fn handle(
85 &self,
86 args: &Map<String, Value>,
87 ctx: &ToolContext,
88 ) -> Result<ToolOutput, ErrorData> {
89 let result = crate::tools::ctx_provider::handle(args, ctx);
90 Ok(ToolOutput::simple(result))
91 }
92}