lean_ctx_server/tools/registered/
ctx_provider.rs1use rmcp::ErrorData;
4use rmcp::model::Tool;
5use serde_json::{Map, Value, json};
6
7use crate::server::tool_trait::{McpTool, ToolContext, ToolOutput};
8use lean_ctx::tool_defs::tool_def;
9
10pub struct CtxProviderTool;
11
12impl McpTool for CtxProviderTool {
13 fn name(&self) -> &'static str {
14 "ctx_provider"
15 }
16
17 fn tool_def(&self) -> Tool {
18 tool_def(
19 "ctx_provider",
20 "Query GitHub, GitLab, Jira, Postgres, MCP bridges, custom REST.\n\
21 WORKFLOW: action=list first to discover configured providers.\n\
22 ANTIPATTERN: not for file content — use ctx_compose/ctx_read instead.\n\
23 provider=id (github|gitlab|jira|mcp:<name>); resource=issues|pull_requests.\n\
24 Data flows through consolidation pipeline; results searchable via ctx_search (action=\"semantic\").",
25 json!({
26 "type": "object",
27 "properties": {
28 "action": {
29 "type": "string",
30 "description": "discover|list|status|refresh|configure|query|mcp_resources|gitlab_issues|gitlab_issue|gitlab_mrs|gitlab_pipelines"
31 },
32 "provider": {
33 "type": "string",
34 "description": "github|gitlab|jira|emspace|mcp:<name>"
35 },
36 "resource": {
37 "type": "string",
38 "description": "issues|pull_requests|paths|template|show"
39 },
40 "project": { "type": "string", "description": "Provider project/repository identifier" },
41 "query": { "type": "string", "description": "Provider-side search query" },
42 "id": { "type": "string", "description": "Provider resource identifier" },
43 "mode": { "type": "string", "description": "compact|text (with bodies)|chunks|snapshot (versioned bounded JSON)" },
44 "state": { "type": "string", "description": "open|closed|merged|all" },
45 "labels": { "type": "string", "description": "Comma-separated labels" },
46 "iid": { "type": "integer", "description": "Issue/MR IID" },
47 "status": { "type": "string", "description": "Pipeline status filter" },
48 "limit": { "type": "integer", "description": "Max results" }
49 },
50 "required": ["action"]
51 }),
52 )
53 }
54
55 fn handle(
56 &self,
57 args: &Map<String, Value>,
58 ctx: &ToolContext,
59 ) -> Result<ToolOutput, ErrorData> {
60 let result = crate::tools::ctx_provider::handle(args, ctx);
61 if crate::tools::ctx_provider::is_snapshot_request(args) {
62 let original_tokens = lean_ctx::core::tokens::count_tokens(&result);
63 let mut output = ToolOutput::simple(result);
64 output.original_tokens = original_tokens;
65 output.mode = Some("snapshot".to_owned());
66 Ok(output)
67 } else {
68 Ok(ToolOutput::simple(result))
69 }
70 }
71
72 fn produces_machine_readable(&self, args: Option<&Map<String, Value>>) -> bool {
73 args.is_some_and(crate::tools::ctx_provider::is_snapshot_request)
74 }
75}