From 227bd3bce1e5181e1f6f78fde853adc81bf0252c Mon Sep 17 00:00:00 2001 From: Wolfvin Date: Wed, 1 Jul 2026 03:50:11 +0000 Subject: [PATCH] =?UTF-8?q?feat(mcp):=20expose=20arch-metrics,=20memory,?= =?UTF-8?q?=20export-snapshot,=20import-snapshot=20as=20MCP=20tools=20?= =?UTF-8?q?=E2=80=94=20closes=20#121?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PRs #107, #109, #110 added 4 new CLI commands but did not register them in the MCP server's _TOOL_DEFINITIONS dict. AI agents using CodeLens via MCP (Claude Desktop, Cursor, etc.) could not invoke these features. Added 4 tool definitions with full JSON Schema parameter specs: - arch-metrics: workspace, format, top - memory: workspace, action (write|read|list|delete), name, content - export-snapshot: workspace, output - import-snapshot: workspace, input, merge MCP tool count: 50 → 54. CLI command count remains 67 (some CLI commands like 'init', 'serve', 'watch' are intentionally not exposed as MCP tools because they don't make sense in an MCP context). The MCP server's _dynamic_tool_definitions() mechanism (line 1387) already auto-generates tool definitions for any CLI command not in _TOOL_DEFINITIONS, but the auto-generated specs lack parameter schemas (everything is treated as opaque 'workspace' + 'args'). The explicit definitions added here give AI agents proper parameter discovery. --- scripts/mcp_server.py | 113 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/scripts/mcp_server.py b/scripts/mcp_server.py index da26552a..6f8e1a78 100644 --- a/scripts/mcp_server.py +++ b/scripts/mcp_server.py @@ -986,6 +986,119 @@ "required": ["workspace"] } }, + # ── Issue #121: MCP tools for commands added in #107, #109, #110 ── + "arch-metrics": { + "description": ( + "Compute architecture metrics: fan-in, fan-out, instability " + "(fan_out / (fan_in + fan_out)), and god-module flags. Requires " + "a prior 'scan' to populate the graph. Useful for spotting " + "highly-depended-on modules (low instability) vs. leaf modules " + "(high instability) and detecting god modules with excessive fan-in." + ), + "parameters": { + "type": "object", + "properties": { + "workspace": { + "type": "string", + "description": "Path to workspace root directory" + }, + "format": { + "type": "string", + "enum": ["json", "markdown", "ai", "sarif", "compact"], + "description": "Output format (default: ai — normalized schema)", + "default": "ai" + }, + "top": { + "type": "integer", + "description": "Limit results to top N modules by instability (default: 50)", + "default": 50 + } + }, + "required": ["workspace"] + } + }, + "memory": { + "description": ( + "Serena-style markdown memory system for cross-session AI context. " + "Actions: write , read , list, delete . " + "Memories are stored as .codelens/memories/.md (project scope) " + "or ~/.codelens/memories/global/.md (global scope). 'mem:NAME' " + "references in content are validated — broken refs emit warnings but " + "the write always succeeds." + ), + "parameters": { + "type": "object", + "properties": { + "workspace": { + "type": "string", + "description": "Path to workspace root directory" + }, + "action": { + "type": "string", + "enum": ["write", "read", "list", "delete"], + "description": "Memory action to perform" + }, + "name": { + "type": "string", + "description": "Memory name (required for write/read/delete). Must start with a letter; letters/digits/_/-/. only." + }, + "content": { + "type": "string", + "description": "Memory content in markdown (required for write). May include 'mem:NAME' references." + } + }, + "required": ["workspace", "action"] + } + }, + "export-snapshot": { + "description": ( + "Export the CodeLens graph (nodes + edges + metadata) as a " + "compressed .codelens.gz snapshot for sharing across team members " + "or CI environments. Snapshot contains graph metadata only — no " + "file content. Companion to import-snapshot." + ), + "parameters": { + "type": "object", + "properties": { + "workspace": { + "type": "string", + "description": "Path to workspace root directory" + }, + "output": { + "type": "string", + "description": "Output path (default: /.codelens/snapshot.codelens.gz)" + } + }, + "required": ["workspace"] + } + }, + "import-snapshot": { + "description": ( + "Import a CodeLens snapshot (.codelens.gz) into the workspace DB. " + "Useful for CI: run scan on a build machine, export snapshot, " + "import on developer machines to skip the parse cost. Mode " + "'replace' (default) wipes existing graph; 'merge' adds to it." + ), + "parameters": { + "type": "object", + "properties": { + "workspace": { + "type": "string", + "description": "Path to workspace root directory" + }, + "input": { + "type": "string", + "description": "Input snapshot path (default: /.codelens/snapshot.codelens.gz)" + }, + "merge": { + "type": "boolean", + "description": "Merge with existing graph instead of replacing (default: False)", + "default": False + } + }, + "required": ["workspace"] + } + }, }