Codecanvas

io.github.donggyun112由 GitHub 账号 donggyun112 发布v0.1.20更新于 Oct 24, 2026

Python code intelligence for coding agents: call paths, control flow, and change impact.

已验证STDIO仅桌面开发者工具数据与分析

概览

AI 生成的概览

面向 Python 的本地静态分析 MCP 服务器,回答调用路径、控制流、副作用与变更影响等问题。

可以做什么
  • 了解项目:查看当前分析根目录、文件数量、缓存与嵌套项目候选,并列出 FastAPI 路由、脚本和公开导出。
  • 定位代码:按精确、语义或混合名称搜索函数、方法和类。
  • 解释行为:给出函数的分支、带守卫的返回与抛出、下游调用与副作用,或结构化的分支树。
  • 追踪调用:向上遍历直接或传递调用者,向下遍历项目内部被调用者并归因副作用。
  • 核对断言与变更:保守验证某源函数是否可达目标,并把 diff 或 git 引用映射到改动函数与受影响入口。
  • 复现状态类缺陷:将函数的状态读写与调用方提供的 schema 比对,并运行聚焦的状态转换用例。
适用场景
适合编码助手在不逐文件阅读的情况下理解陌生或大型 Python 项目,例如查找谁调用了某函数、副作用发生在哪里、在何种守卫下会抛出异常,或某次改动影响哪些路由。它补充而非替代 grep 与语言服务器。
运行要求
通过 stdio 在本地运行,使用 uvx 从 PyPI 包 codecanvas-mcp 启动,因此需先安装 uv。需要 Python 3.10 或更高版本,且被分析项目须为 Python。首次调用工具时需传入绝对路径 project_path。可选变量 CODECANVAS_MAX_FILES、CODECANVAS_BATCH_SIZE、CODECANVAS_THROTTLE_MS 用于调整大项目行为。无需账号、API 密钥或远程服务。
安装前请注意
静态分析不等于运行时事实:推断或歧义的调用边、截断标记与 safe_to_summarize 应视为限定条件,结果也会被截断。服务器会读取项目文件并在本地写入 .codecanvas 缓存目录。simulate_state_transition 会在独立进程中导入并执行受信任的项目代码,这不是安全沙箱,代码仍可能访问文件系统、网络或子进程,并可能有导入期副作用。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Codecanvas,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

[CodeCanvas MCP — Trace the truth]

CodeCanvas MCP

[PyPI] [Python] [License: MIT]

Understand an unfamiliar Python system before spending thousands of tokens reading it file by file.

CodeCanvas is a local static-analysis Model Context Protocol server for Python. It turns project-wide call paths and control flow into compact, citation-ready answers about branches, callers, callees, side effects, and change impact.

The benchmark now spans pinned revisions of Google ADK, LangGraph, and FastAPI. On an Apple M4 Pro, measured cold analysis ranged from 4.38s to 61.62s, and median warm find_symbols latency ranged from 48.264ms to 293.778ms across those repositories. In a controlled 54-session agent suite, both conditions kept the same built-in code-search tools; the treatment added only logic_flow. That single addition used a median 22.95% fewer total tokens across three paired repetitions, demonstrating meaningful incremental value on top of ordinary code exploration. Uncached tokens increased by 0.78%, and the answers are not yet blind-graded. See the methodology, full tables, and limitations.

Use it to answer questions such as:

  • Who calls this function, directly or transitively?
  • What can this function reach, and where do side effects happen?
  • Under which guards can this return or exception occur?
  • Does this source really reach that target in the requested mode?
  • Which API routes, scripts, or public exports are affected by a diff?

CodeCanvas is Python-only and requires Python 3.10 or newer.

See the difference

Ask one question:

text
Use logic_flow on UserService.update_user. Show its branches, outcomes,downstream effects, and evidence quality.

Excerpt from the actual response on the included FastAPI sample:

json
{  "function": "app.services.user_service.UserService.update_user",  "source": "app/services/user_service.py:13",  "flow": [    "15  user = await self.user_repo.find_by_id(...)",    "16  if user is None:",    "17      → return None",    "18  → return await self.user_repo.update(user_id, user)"  ],  "outcomes": [    {"at": 17, "detail": "None", "guards": ["user is None"]},    {"at": 18, "detail": "await self.user_repo.update(user_id, user)", "guards": []}  ],  "downstream": [    {      "function": "app.repositories.user_repo.UserRepository.find_by_id",      "location": "app/repositories/user_repo.py:13",      "effects": ["db"]    },    {      "function": "app.repositories.user_repo.UserRepository.update",      "location": "app/repositories/user_repo.py:18",      "effects": ["db"]    }  ],  "evidence_grade": "inferred",  "safe_to_summarize": false,  "response_guidance": "Do not turn inferred call edges into unconditional claims."}

That single response exposes the early return, success path, downstream database work, exact source locations, and how cautiously the agent may summarize the result.

Quick start

Install uv if uvx is not already available. The repository includes one shared plugin package with native manifests for both Claude Code and Codex. Install it from the CodeCanvas marketplace:

bash
# Claude Codeclaude plugin marketplace add donggyun112/codecanvasclaude plugin install codecanvas@codecanvas
# Codexcodex plugin marketplace add donggyun112/codecanvascodex plugin add codecanvas@codecanvas

Both plugins start uvx codecanvas-mcp and expose the complete tool catalog. See the plugin package for local-checkout testing and validation commands.

If your client does not support plugins, register the server directly. For Claude Code:

bash
claude mcp add codecanvas -- uvx codecanvas-mcp

That command exposes the complete tool catalog. Keep the full catalog enabled when your MCP client supports on-demand tool discovery or tool search: the client can load the relevant schemas only when they are needed, so the other CodeCanvas tools remain available without paying their schema cost on every model request.

toml
[mcp_servers.codecanvas]command = "uvx"args = ["codecanvas-mcp"]

If your client eagerly injects every enabled tool schema into every model request, use this compatibility profile instead:

toml
[mcp_servers.codecanvas]command = "uvx"args = ["codecanvas-mcp"]enabled_tools = ["logic_flow", "who_calls", "call_tree"]

The three-tool allow-list is a fallback for eager-schema clients, not a recommendation to discard the rest of CodeCanvas. For another MCP client, use the equivalent stdio configuration:

json
{  "mcpServers": {    "codecanvas": {      "command": "uvx",      "args": ["codecanvas-mcp"]    }  }}

Pass an absolute project_path on the first tool call. CodeCanvas remembers the last explicitly selected project for the rest of the server session.

With the complete catalog enabled, project_status reports candidate analysis roots for nested Python projects. Compact-profile users should pass the intended nested root explicitly.

Teach your agent when to use it

Adding tools does not guarantee that an agent will choose them at the right time. Put a short instruction like this in AGENTS.md, CLAUDE.md, or the equivalent file used by your coding agent:

markdown
## Code analysis
Use CodeCanvas before text search when you need to know:
- how a Python function branches, returns, and produces side effects;- who calls it directly or transitively;- what it reaches downstream through project-internal calls.
Pass `project_path` once, then reuse the active project. Treat`safe_to_summarize: false`, inferred edges, ambiguity, and truncation asqualifications rather than unconditional facts.
Start with `logic_flow`. Use `who_calls` for upstream impact and `call_tree`for a deeper downstream trace.

Then ask your agent naturally:

text
Use logic_flow first to understand checkout without repeated source searches.What calls UserService.update_user, up to three hops?What does checkout reach downstream, including HTTP or database effects?

With the complete catalog enabled, CodeCanvas can also answer:

text
List the entrypoints in this project.Under exactly what conditions can authenticate raise?Verify that dry-run publish reaches _call_api.Analyze the impact of the current diff.

Why not just grep or an LSP?

CodeCanvas complements both. It is for behavioral questions that otherwise require repeated searches and manual reconstruction.

NeedgrepLSPCodeCanvas
Exact textBest fitNot its jobKeep using grep
Definitions and direct referencesManualBest fitResolves symbols inside structural results
Transitive callers and calleesRepeated manual hopsReferences are not a call pathBounded upstream and downstream graphs
Branch guards and outcomesRead and reconstruct sourceUsually not modeledStructured flow and guarded returns/raises
Side effects and change impactInfer manuallyUsually not modeledEffects attributed through call paths and entrypoints
UncertaintyNo confidence modelResolution-dependentEvidence grade, ambiguity, truncation, and guidance

What makes the answers trustworthy

Static analysis is not runtime truth, so CodeCanvas makes uncertainty visible instead of hiding it.

Every successful MCP response identifies the selected analysis_root and includes metadata that helps an agent decide how strongly it may state the result:

  • evidence_grade describes the strength of the resolved evidence.
  • inferred_edge_count and ambiguous_calls expose uncertain call edges.
  • truncated says whether the bounded response omitted results.
  • safe_to_summarize says whether the result supports an unconditional claim.
  • response_guidance explains how to qualify a result when it does not.

verify_claim goes further by combining candidate call paths with branch and return/raise guards. It returns true, false, or uncertain; unsupported qualifiers and inferred-only paths cannot silently become a definite true.

Tools

Discover and understand

ToolUse it for
project_statusInspect the active root, Python file count, cache, worker interpreter, and nested project candidates
list_entrypointsFind FastAPI routes, scripts, function entrypoints, and distributed library exports
find_symbolsLocate functions, methods, and classes with exact-first name, semantic, or hybrid search
logic_flowGet one compact, citation-ready view of a function's branches, outcomes, downstream calls, and effects
what_doesTriage a function from its signature, docstring, calls, effects, exceptions, and direct risk
function_flowInspect a structured branch tree with subjects, conditions, scopes, and nesting
reaching_conditionsGet the enclosing guards for each return or raise, plus complexity and unreachable code

Follow behavior and assess change

ToolUse it for
who_callsWalk direct or transitive callers upstream
call_treeWalk project-internal callees downstream and attribute direct/transitive effects
verify_claimConservatively check a qualified source reaches target claim against paths and guards
analyze_impactMap an inline diff or git ref to changed functions and affected entrypoints/public surfaces

Reproduce state-shaped bugs

ToolUse it for
validate_state_schemaCompare a function's state reads, writes, and mapping returns with a caller-provided schema
simulate_state_transitionExecute focused generated or explicit state cases with invariants and dependency overrides

Large result sets are capped. Use each tool's filter, kind, path, depth, or pagination arguments to narrow the answer before treating it as complete.

How it works

  1. Select a project. CodeCanvas resolves and remembers an explicit Python project root. Ambiguous nested roots must be selected rather than guessed.
  2. Build structural indexes. Python AST analysis builds a project-wide call graph and per-function control-flow data. Extractors add FastAPI routes and Depends() chains, scripts, generic function entrypoints, and package exports.
  3. Reuse compatible analysis. The call graph and entrypoints are cached in <project>/.codecanvas/; an in-process builder is reused during the MCP session.
  4. Project compact answers. Each MCP tool queries the shared analysis and returns bounded results with origin, evidence, ambiguity, and truncation metadata.

The default analysis limit is 5,000 Python files. Tune large-project behavior with:

VariableDefaultDescription
CODECANVAS_MAX_FILES5000Maximum Python files to analyze
CODECANVAS_BATCH_SIZE50Files processed before yielding
CODECANVAS_THROTTLE_MS10Delay between batches in milliseconds

Safety and limitations

  • CodeCanvas analyzes Python source; it does not model every possible dynamic import, monkey patch, reflection path, or runtime value.
  • Inferred and ambiguous edges are reported as qualifications, not promoted to definite evidence.
  • Static-analysis tools read project files and write the local .codecanvas/ cache. No remote CodeCanvas service is required.
  • simulate_state_transition is different: it imports and executes trusted project code in a separate process. It is isolation for focused repros, not a security sandbox. Project code may still access the filesystem, network, or subprocesses and may have import-time side effects.
  • The simulator prefers <project>/.venv or venv, then the same directories in the parent project. Use python_executable to choose explicitly and check the returned worker metadata when imports fail.

Evidence

The measured local latency suite covers three pinned projects with 148–1,650 Python files and 4,468–16,960 indexed functions. It reports cold analysis, first and warm search latency, and eight-worker throughput; the raw result is committed with the benchmark artifacts.

The model-backed evaluation covers frozen tasks and hidden rubrics for Google ADK, LangGraph, and FastAPI. It compares built-in code exploration plus logic_flow against the same built-in exploration alone. Across 54 isolated sessions, three paired repetitions produced a suite-wide median of 22.95% fewer server-reported total tokens. All 27 treatment sessions completed the required tool call, providing direct evidence that one CodeCanvas tool adds meaningful value without replacing the agent's existing search tools. Uncached input plus output increased by a median 0.78%, and the answers are not yet blind-graded, so this is not yet an efficiency-at-equal-quality or billing-cost claim.

See the full methodology, result tables, reproduction commands, and audit artifacts.

Development

bash
git clone https://github.com/donggyun112/codecanvas.gitcd codecanvas/coreuv sync --extra devcd ..core/.venv/bin/python -m pytest

The package source lives under core/. The root test configuration runs both the product tests in tests/ and the package-level tests in core/tests/.

Issues and focused reproduction cases are welcome: https://github.com/donggyun112/codecanvas/issues.

License

CodeCanvas MCP is open-source software licensed under the MIT License.

来源:README.md,提交 e427af4

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.1.20最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分