@ai-agent-context/mcp

中文文档
1.0.0发布于 2026/10/18MITTypeScriptES Module近 30 天下载 3767

Model Context Protocol adapter for ai-agent-context. Exposes the repository knowledge graph to MCP clients over stdio. Contains no business logic of its own.

原始使用文档
文档目录14 节
  1. Installation
  2. Running the server
  3. Client configuration
  4. Protocol support
  5. Compatibility matrix
  6. Verified against a client written by someone else
  7. Cancellation and timeouts
  8. Error handling
  9. Resources
  10. Prompts
  11. Tools
  12. Programmatic use
  13. Security
  14. License

@ai-agent-context/mcp

MCP (Model Context Protocol) adapter for ai-agent-context.

The adapter exposes the repository knowledge graph built by @ai-agent-context/core to MCP clients over stdio. It contains no analysis logic: every tool delegates to the core API, so the same guarantees (deterministic, local-only, evidence-backed) apply unchanged.

Installation

npm install @ai-agent-context/mcp

Running the server

agent-context-mcp --root /path/to/repository

The repository root defaults to AGENT_CONTEXT_ROOT, then to the current working directory. stdout carries JSON-RPC only; all diagnostics go to stderr.

Client configuration

Print the snippet for a supported client:

agent-context-mcp config claude-code
agent-context-mcp config cursor
agent-context-mcp config cline
agent-context-mcp config continue
agent-context-mcp config --list     # supported clients
agent-context-mcp config --all      # every client at once

Each snippet prints the value of the client's mcpServers field. Merge it into the existing file — the config file also carries unrelated settings, so replacing the file would destroy them.

ClientFileShape
Claude Code.mcp.jsonobject keyed by server name
Cursor.cursor/mcp.jsonobject keyed by server name
Cline (VS Code)cline_mcp_settings.jsonobject keyed by server name
Continue~/.continue/config.jsonarray

Running a local checkout instead of the published package:

agent-context-mcp config cursor --command node --command-arg /path/to/packages/mcp/dist/bin.js

Protocol support

The server is dual-era: it selects its behaviour from how the client opens.

EraRevisionsHow the client opens
Legacy2024-11-05, 2025-03-26, 2025-06-18, 2025-11-25initialize handshake
Modern2026-07-28per-request _meta, no handshake

Legacy negotiation. initialize is answered with the version the client asked for. When the client asks for a revision this server does not implement, it answers with the newest legacy revision it does — as the specification requires — so a client is never told to downgrade to a revision it did not request.

Modern negotiation. Every request carries io.modelcontextprotocol/protocolVersion in _meta. There is no handshake and no downgrade: a request naming an unsupported revision is refused with -32022 and a list of versions to retry with. A modern request that omits the required io.modelcontextprotocol/clientCapabilities is refused with -32602. Modern results carry resultType: "complete".

server/discover is implemented and reports supportedVersions, capabilities and server identity.

# what the server supports
{"jsonrpc":"2.0","id":"d1","method":"server/discover","params":{"_meta":{
  "io.modelcontextprotocol/protocolVersion":"2026-07-28",
  "io.modelcontextprotocol/clientCapabilities":{}}}}

Compatibility matrix

Client eraServerOutcome
Legacy (initialize)this serverWorks; answered with the requested or the newest legacy revision
Modern (_meta, server/discover)this serverWorks for 2026-07-28; other revisions get -32022 with a retry list
Legacymodern-only serverWould fail; not applicable here, this server is dual-era

Verified against a client written by someone else

Everything else that exercises this server — the packaged smoke test and the test suite — speaks JSON-RPC by hand, which means it checks the server against the same understanding of the protocol that wrote it.

npm run mcp:client

That drives the server with @modelcontextprotocol/sdk, the reference implementation, as a real client over stdio. The SDK parses and validates every message, negotiates the revision itself, and throws on anything off-specification. It runs in CI as mcp against a real client.

23 checks: the handshake and the negotiated revision, the tool list and every schema in it, six tool calls against a real repository, the compact/full size contract, and the fact that an argument the server rejects outright is a protocol error rather than a failed tool result.

Two things it established by disagreeing with the assumptions written into the check: an invalid detail value is rejected, not returned as a tool error — which is the correct behaviour, since returning isError would tell the agent the call ran and failed when it never ran; and compact is a size budget rather than a different question, keeping the same shape while dropping the evidence.

Not verified, stated on every run of the check. The reference SDK's newest revision is 2025-11-25, so no third-party client can exercise the modern _meta era yet; the negotiation helpers are unit-tested and the era itself is not. And the shipping desktop clients listed above are applications — launching one is outside what a command-line check can do. Those presets encode the documented configuration format of each client; confirm against your own installation before relying on them.

Verified here otherwise: legacy and modern sessions over a real stdio process, malformed input, cancellation and timeouts.

Cancellation and timeouts

notifications/cancelled stops a request: the response is suppressed, and a cancelled request is never answered — including by the timeout that follows it.

Every request is bounded by requestTimeoutMs (default 120000, 0 disables). An expired request is answered with -32603 and data.timeoutMs, and any late result is discarded.

Error handling

Errors use the JSON-RPC codes and the MCP-specific codes in the specification's reserved range:

CodeMeaning
-32600Invalid Request — message without a method
-32601Method not found
-32602Invalid params — unknown resource or prompt, failed argument validation, missing required _meta field
-32603Internal error, including a request that exceeded its timeout
-32021MissingRequiredClientCapabilityError
-32022UnsupportedProtocolVersionError, with data.supported

-32002 (resource not found, reserved by older revisions) is never emitted; unknown resources report -32602.

A tool that runs but fails is not a protocol error: the response carries isError: true with a human-readable payload, so the agent can read and act on the message.

Arguments are validated against the published JSON Schema before dispatch. Missing required fields, wrong primitive types, invalid enums and unknown properties are rejected with -32602 without starting repository analysis.

Resources

Read-only, exposed as MCP resources:

  • agent://repository/context
  • agent://repository/architecture
  • agent://repository/dependencies
  • agent://repository/conventions
  • agent://repository/decisions

Prompts

  • onboard_to_repository
  • review_change_impact
  • explain_architecture

Tools

ToolRequired arguments
get_repository_context—
get_context_for_tasktask
get_change_impacttarget
explain_modulepath
get_dependencies—
get_dependentsmodule
search_contextquery
get_architecture—
get_conventions—
get_decisions—
get_module_historytarget
get_revision_diffrevision
get_revision_snapshotrevision
detect_coverage_gaps—

Every tool accepts an optional root. All tools are bounded and carry a confidence and evidence for heuristic values; see the repository README.md for what each returns.

Programmatic use

import { McpServer, createMemoryTransport, SUPPORTED_PROTOCOL_VERSIONS } from '@ai-agent-context/mcp';

const transport = createMemoryTransport();
const server = new McpServer({ root: process.cwd(), transport, requestTimeoutMs: 30_000 });
server.start();
transport.push({ jsonrpc: '2.0', id: 1, method: 'server/discover', params: { _meta: {
  'io.modelcontextprotocol/protocolVersion': '2026-07-28',
  'io.modelcontextprotocol/clientCapabilities': {},
} } });
console.log(transport.sent);

Exported for embedders: McpServer, createStdioTransport, createMemoryTransport, the CLIENT_PRESETS set with presetById/renderPreset/renderAllPresets/serverArgv, the protocol helpers (SUPPORTED_PROTOCOL_VERSIONS, ErrorCode, negotiateLegacyVersion, isSupportedVersion, …), TOOL_DEFINITIONS, callTool and ContextPool.

MCP_PROTOCOL_VERSION is the legacy handshake default and is deprecated in favour of SUPPORTED_PROTOCOL_VERSIONS.

Security

The adapter inherits the core package's properties:

  • Local-only: no external API calls, no telemetry
  • Repository-scoped: tools accept a root, and the core rejects paths outside it
  • Read-only: tools, resources and prompts never modify the repository
  • Clean stdio channel: JSON-RPC on stdout, diagnostics on stderr
  • Secret filtering: sensitive files are skipped by the core, not by the adapter

See the repository SECURITY.md.

License

MIT

版本与发布记录

@ai-agent-context/mcp 共发布 30 个版本,首次发布于 2026/09/19;过去 12 个月发布了 30 个版本。

版本发布日期距今
1.0.0latest2026/10/1820 天前
0.18.02026/10/1820 天前
0.17.02026/10/1820 天前
0.16.02026/10/1820 天前
0.15.02026/10/1820 天前
0.14.12026/10/1820 天前

关于 @ai-agent-context/mcp 的常见问题

@ai-agent-context/mcp 是什么?

Model Context Protocol adapter for ai-agent-context. Exposes the repository knowledge graph to MCP clients over stdio. Contains no business logic of its own.

如何安装 @ai-agent-context/mcp?

在项目目录运行 npm install @ai-agent-context/mcp,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 agent-context-mcp,可以用 npx agent-context-mcp 直接运行。

@ai-agent-context/mcp 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ai-agent-context/mcp 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@ai-agent-context/mcp 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.11.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@ai-agent-context/mcp 可以商用吗?

@ai-agent-context/mcp 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ai-agent-context/mcp 的下载量有多少?

根据 npm 官方下载统计,@ai-agent-context/mcp 在 2026/10/05 – 2026/11/03 这 30 天内被下载 3,767 次,日均约 126 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ai-agent-context/mcp 还在维护吗?

最新版本 1.0.0 发布于 2026/10/18(20 天前);至今共发布 30 个版本,其中过去 12 个月发布了 30 个;首次发布于 2026/09/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。