Skip to main content
Glama
Bluezeamer

PrecisionContextEngine

by Bluezeamer

PCE — Precision Context Engine

为 AI 编程 Agent 设计的代码库理解减负及加速层

大型代码库理解的最大成本不是"搜索",而是反复 grep、手工翻目录、拼接调用链带来的上下文消耗。PCE 通过 MCP 暴露的工具接口把入口定位、链路梳理、影响面分析从主 Agent 中拆出来:

  • 节省主 Agent 上下文:代码库调研由 PCE 独立完成,主 Agent 的上下文窗口不被探索过程消耗,得以在一轮会话中连续完成目标任务

  • 降低模型调用成本:PCE 的分析任务不依赖旗舰模型——推荐使用参数量小、速度快的轻量模型,性价比更高,响应更快

推荐模型(实测性价比均衡):xiaomi/mimo-v2-flash · openai/gpt-5.4-mini · openai/gpt-5.4-nano

工具一览

工具

用途

pce_init

绑定项目,构建索引与导航上下文

pce_query

定位入口、梳理模块职责与主干调用链

pce_impact

分析已知目标的影响边界、下游传播链与变更风险

pce_sync

代码变更后增量同步索引与认知状态

pce_status

查看初始化状态、索引信息与 staging 状态

典型工作流:

pce_init → pce_query → pce_impact → [修改代码] → pce_sync
  • 目标未知 → 先用 pce_query

  • 目标已知,评估波及面 → 用 pce_impact

  • 改完代码后 → 用 pce_sync


Related MCP server: Symbol Delta Ledger

快速接入(MCP)

推荐直接以 MCP 方式接入,无需手动启动服务。

Claude Code

在 MCP 配置文件中添加:

{
  "pce": {
    "command": "uvx",
    "args": [
      "--from",
      "git+https://github.com/Bluezeamer/PrecisionContextEngine",
      "pce",
      "serve"
    ],
    "env": {
      "PCE_PROVIDER": "openrouter",
      "PCE_MODEL": "openai/gpt-5.4-nano",
      "PCE_API_KEY": "your_api_key",
      "PCE_TEMPERATURE": "1.0",
      "PCE_AGENT_TIMEOUT": "1200"
    }
  }
}

Codex

[mcp_servers.pce]
command = "uvx"
startup_timeout_sec = 60
args = ["--python", "3.11", "--from", "git+https://github.com/Bluezeamer/PrecisionContextEngine", "pce", "serve"]
tool_timeout_sec = 1200

[mcp_servers.pce.env]
PCE_PROVIDER = "openrouter"
PCE_MODEL = "openai/gpt-5.4-nano"
PCE_API_BASE = "https://openrouter.ai/api/v1"
PCE_API_KEY = "your_api_key"
PCE_TEMPERATURE = "1.0"
PCE_AGENT_TIMEOUT = "1200"

[重要]提示词建议

经过实测MCP本身的工具调用提示词在各Agent内部的引导优先级权重不高,容易被淹没在大量的工具噪音里。因此为了强化主Agent适时使用PCE的倾向获得更好的使用体验,建议将AGENTS.md中的内容复制粘贴到你的目标Agent系统提示词约束中——例如对于claudecode来说是CLAUDE.md,对于codex来说是AGENTS.md


环境变量

变量

必填

说明

PCE_PROVIDER

LiteLLM provider,如 openrouter / openai / anthropic

PCE_MODEL

provider 下的模型名

PCE_API_KEY

对应模型的 API Key

PCE_API_BASE / PCE_BASE_URL

自定义兼容端点

PCE_TEMPERATURE

全局温度,默认 1.0

PCE_AGENT_TIMEOUT

Agent 总超时(秒),默认 600

PCE_COMPLETION_RETRIES_PER_MODEL

每模型 completion 重试次数,默认 3

PCE_MODEL_FALLBACKS

fallback 模型链,逗号分隔

完整示例见 .env.example


本地部署

环境要求:Python 3.11–3.12,uv

uv sync --all-extras
cp .env.example .env   # 按上表填写必填变量
uv run pce serve       # 以 stdio MCP server 方式运行

License

GPL-3.0

Available Tools

5 tools
pce_impactA

Purpose: The primary tool for analyzing the impact boundary of a known change target. Outputs direct call sites, direct consumers, main propagation chains, risks, and suggested modification order. When to use: Use when you already know which symbol, field, interface contract, or file to change, and want to understand what will be affected before making the change. Best practice: Provide an explicit target; if you know the file containing the symbol, also provide the file parameter to speed up resolution. Frame the question as a concrete change, e.g. 'modify field X', 'change function signature of Y', 'what breaks if file Z is deleted'. Avoid: If the target is still ambiguous or you are choosing between multiple candidates, do not use impact as a substitute for the discovery step — use pce_query first to converge on the target. If you only want to view local implementation or exact definitions, impact is not necessary.

ParametersJSON Schema
NameRequiredDescriptionDefault
fileNoFile path containing the symbol (optional, speeds up resolution if provided).
targetYesThe change target — a symbol name (e.g. UserSession) or file path.
change_typeYesType of change: modify | rename | delete | add_field | change_signature

TDQS

A4.7/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are present, so the description carries the full burden. It clearly frames the tool as an analysis step 'before making the change' and discloses its output behavior, which strongly implies it does not perform the modification itself. However, it never explicitly states whether it is strictly read-only or whether it has side effects such as caching or workspace state changes, leaving a small transparency gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is organized into short labeled sections — Purpose, When to use, Best practice, Avoid — and every sentence earns its place. It front-loads the core purpose and outputs before giving procedural guidance, and it avoids redundant filler.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a three-parameter tool with no output schema or annotations, the description is complete: it explains purpose, outputs, invocation best practices, and exclusions. It even routes ambiguous cases to the correct sibling tool, pce_query, which gives an agent everything needed to invoke pce_impact correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the schema already documents all three parameters. The description adds value beyond the schema by explaining that target should be explicit, that file can speed up resolution, and by recommending concrete change-framing examples like 'modify field X' or 'change function signature of Y'. It does not add much beyond the schema for change_type, but the extra guidance is meaningful.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb and resource ('analyzing the impact boundary of a known change target') and enumerates concrete outputs: direct call sites, direct consumers, main propagation chains, risks, and suggested modification order. It also differentiates itself from siblings by explicitly naming pce_query as the discovery tool, so an agent can distinguish impact analysis from query/search.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It gives explicit when-to-use conditions ('already know which symbol, field, interface contract, or file to change') and explicit avoid-conditions ('target is still ambiguous... use pce_query first'). It also clarifies that impact is unnecessary for viewing local implementations, leaving no ambiguity about when this tool should be selected.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

pce_initA

Purpose: Bind a target project and initialize the PCE runtime, building the index and navigation context required by query / impact / sync. When to use: Call this when entering a new project or the first time PCE is needed in a session. Do NOT call pce_query, pce_impact, pce_sync, or edit tools before pce_init succeeds. Best practice: Typically called once per session and awaited until success. Only call again when switching projects or retrying after a failure. Avoid: Do not use this as a code query tool; it establishes context but does not directly answer code questions.

ParametersJSON Schema
NameRequiredDescriptionDefault
project_pathYesAbsolute path to the target project root.

TDQS

A4.4/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full behavioral burden. It does disclose that the tool builds an index and navigation context, that it establishes context rather than answering code questions, and that it must succeed before dependent tools are used. It does not, however, describe side effects on disk, persistence, idempotency, or what success/failure returns, which would make the behavioral profile more complete.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well structured under Purpose, When to use, Best practice, and Avoid, with each section front-loaded and every sentence adding operational value. It is sufficiently concise and avoids redundancy while covering usage, sequencing, and scope.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a one-parameter initialization tool with no output schema and no annotations, the description covers the essential context: what it does, when to call it, its prerequisite status, and its relationship to siblings. It is slightly incomplete in not stating what a successful initialization returns or whether any external state is modified, but overall it is strong enough for an agent to call it correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, and the only parameter, project_path, is already described as 'Absolute path to the target project root.' The description adds no additional parameter-specific guidance beyond restating the notion of a 'target project,' so the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific action ('Bind a target project and initialize the PCE runtime') and the resource affected, and it explains the purpose by saying it builds 'the index and navigation context required by query / impact / sync.' It also distinguishes itself from siblings by explicitly warning not to use it as a code query tool.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description gives explicit conditions for use: call when entering a new project or when PCE is first needed, and do not call pce_query, pce_impact, pce_sync, or edit tools before pce_init succeeds. It also provides best practice context, saying it is typically called once per session and only again when switching projects or retrying after failure.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

pce_queryA

Purpose: The primary tool for codebase navigation and understanding. Best suited for project-level understanding, architecture overviews, major module responsibilities, entry points, main call chains, candidate file scopes, and overall project/module comprehension. When to use: Use when the target location is unclear. When you do not know which file contains the information, need to understand what the project or a subsystem does, need a rough architecture or module-level picture, want to find entry points / main call chains / module responsibilities, or need to narrow down the search scope — use this tool first. Do NOT manually traverse directories, broadly inspect the repo, or batch-read files before trying pce_query. Best practice: Prefer describing your question in natural language rather than just giving exact identifiers. This tool is especially appropriate for questions like what the project does, how a subsystem is organized, where a feature lives, or which modules participate in a workflow. You can request file:line references, name_path, candidate file lists, call chain summaries, or results grouped by module. Avoid: When you already know the exact file or exact identifier and only need to view local implementation or do exact string matching, pce_query is not necessary. If the target is already clear and the task becomes 'what will be affected by changing it', switch to pce_impact instead.

ParametersJSON Schema
NameRequiredDescriptionDefault
queryYesNatural language question, e.g. 'Where is the entry point for authentication logic?'

TDQS

A4.7/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

There are no annotations, so the description carries the behavioral burden. It explains the tool is exploratory/navigational, accepts natural-language questions, and can return structured navigation artifacts like file:line references, name_path, candidate file lists, call chain summaries, or grouped results. It does not explicitly state whether the operation is side-effect-free, but the read-only intent is strongly implied.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is longer than average but uses labeled sections (Purpose, When to use, Best practice, Avoid) that make it scannable and front-loaded. A little redundancy exists between 'Best suited for...' and 'especially appropriate for...', but every paragraph adds actionable guidance.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With no output schema, the description covers what the tool can return and what kinds of questions it answers. It also covers exclusions and sibling routing. Nothing essential for an agent to decide whether to invoke it is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema only describes 'query' as a natural-language question. The description adds substantial semantics: prefer natural language over exact identifiers, example question, what output styles can be requested, and appropriate question types. This goes well beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description names a specific verb ('query'), resource ('codebase'), and a set of concrete use cases (entry points, module responsibilities, call chains, narrowing search scope). It explicitly distinguishes itself from pce_impact, so an agent can tell them apart.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Contains explicit when-to-use and when-not-to-use guidance: use first when target location is unclear; avoid when exact file/identifier is known; switch to pce_impact for change-impact analysis. It even warns against manually traversing directories before trying this tool.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

pce_statusA

Purpose: Return current service and project status, including initialization phase, index statistics, staging area, and warnings. When to use: Use when you need to confirm whether PCE is available, whether the index has been built, or to diagnose init / query / impact / sync issues. Best practice: Treat this as a diagnostic tool. When unsure whether to call init or sync first, check status. Avoid: Do not use this as a code understanding tool; it does not locate entry points, call chains, or impact boundaries.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

TDQS

A4.4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the burden of behavioral disclosure. It does disclose that the tool is diagnostic and read-only in nature, and it lists what information is returned. However, it does not describe the output format, whether the tool performs any side effects, or what happens if the service is unavailable. The diagnostic framing is useful but the behavioral detail is thin.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is compact and well-structured with clear labeled sections: Purpose, When to use, Best practice, and Avoid. Every sentence earns its place, and the most important information (what the tool returns) is front-loaded. There is no redundancy or filler.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a zero-parameter diagnostic tool with no output schema, the description covers the essential information an agent needs: what the tool does, when to call it, and when not to call it. The only gap is the lack of detail about the exact shape or format of the returned status, but since there is no output schema, a bit more specificity about return values would make it fully complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has zero parameters, so there is no parameter semantics burden on the description. The schema is trivially complete (100% coverage with an empty properties object). The description adds value by explaining what the returned status contains, which is the closest analog to parameter semantics for a no-parameter tool.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb ('Return') and resource ('current service and project status'), and enumerates the exact contents: initialization phase, index statistics, staging area, and warnings. It also distinguishes itself from sibling tools by explicitly saying it is not a code understanding tool, which helps an agent tell it apart from pce_query and pce_impact.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit when-to-use guidance: confirm PCE availability, check whether the index has been built, or diagnose init/query/impact/sync issues. It also gives a best practice ('When unsure whether to call init or sync first, check status') and an explicit avoid statement ('Do not use this as a code understanding tool'), which routes the agent away from inappropriate alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

pce_syncA

Purpose: Synchronize Serena and PCE index state after codebase modifications, so subsequent query / impact calls work against the latest code. When to use: Use after completing a batch of code modifications, file deletions, renames, or structural changes. Best practice: Use this as a batch synchronization step; typically call once after completing a round of changes, rather than after every small edit. Avoid: Do not use this as a code understanding tool; it refreshes index state but does not explain code.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

TDQS

A4.4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full behavioral disclosure burden. It adds some useful context: 'refreshes index state' and explicitly states it 'does not explain code.' However, it does not disclose side effects, persistence, reversibility, or idempotence. For a mutation-like operation, this is a moderate but not severe gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with labeled sections (Purpose, When to use, Best practice, Avoid). It is front-loaded with the core purpose and every sentence provides actionable guidance without redundancy or fluff.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a zero-parameter tool, the description covers purpose, usage timing, best practice, and exclusions. It does not mention return values or behavior when the index is already in sync, but these are minor given the tool's simplicity and the presence of sibling tools like pce_status for checking state.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has zero parameters and 100% schema description coverage, so the baseline is 4. No parameter documentation is needed since there is nothing to explain.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb and resource: "Synchronize Serena and PCE index state" and explains its goal: "so subsequent query / impact calls work against the latest code." It clearly distinguishes itself from query/impact tools by positioning itself as a preparatory synchronization step, and the 'Avoid' section separates it from code understanding tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit 'When to use' guidance (after batch code modifications, deletions, renames, structural changes), 'Best practice' (one batch call per round of changes), and 'Avoid' (not for code understanding). This gives an agent clear decision criteria for when and how to invoke the tool.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 5 tool updatesv0.1.0
    • First observedpce_impact
    • First observedpce_init
    • First observedpce_query
    • First observedpce_status
    • First observedpce_sync

TDQS

A4.7/5.0

Scored across 5 tools

Disambiguation5/5

Each tool occupies a distinct lifecycle role: init sets up, status diagnoses, query discovers, impact analyzes changes, and sync refreshes. The descriptions explicitly warn against cross-use, particularly between query and impact, so an agent can reliably select the right tool.

Naming Consistency5/5

All tools share a consistent pce_ prefix and a single lowercase keyword, making the pattern immediately predictable. Although the second words mix verbs and nouns, the convention is uniform and readable.

Tool Count5/5

Five tools is well-scoped for a context engine: setup, status, discovery, impact analysis, and synchronization cover the core workflow without redundancy. No tool feels decorative or missing from the set.

Completeness5/5

The lifecycle is complete: init builds context, status verifies it, query consumes it for exploration, impact consumes it for change analysis, and sync brings it up to date after edits. There are no obvious dead ends for the stated purpose.

Maintenance

ActivityInactive
ResponsivenessUnresponsive

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    C
    maintenance
    Enables AI coding agents to query a pre-built semantic knowledge graph of code, reducing token usage and tool calls. Supports 16 tools for code exploration, analysis, and context building.
    5 npm
    7
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    Enables AI coding agents to analyze codebase behavior through entrypoints, call paths, and tests, providing impact analysis and context packs for code changes.
    MIT
  • A
    license
    Not graded
    quality
    B
    maintenance
    Enables LLM agents to efficiently understand and navigate a codebase by providing semantic search over symbols and a reference graph, replacing expensive grep/glob calls with structured tools like definition lookup, caller/callee queries, and change-impact analysis.
    2
    MIT