@agenticprimitives/mcp-runtime

中文文档
1.0.0-alpha.46发布于 2026/10/26MITTypeScriptES Module零依赖近 30 天下载 4142

Delegation-aware authorization middleware around the official MCP TypeScript SDK. The decision layer, not the SDK.

原始使用文档
文档目录7 节
  1. Quick start
  2. What ships
  3. How it's different
  4. Cross-delegation
  5. Validation
  6. Status
  7. License

@agenticprimitives/mcp-runtime

Part of Agentic Primitives — the open-source trust substrate for agentic applications: identity that can sign, authority checked at act time, evidence the owner carries. Developer kit · All packages

The same delegation that authorizes a web app session authorizes an MCP tool call. Most MCP servers gate tools with API keys or OAuth scopes — bearer credentials that say nothing about who delegated the authority, under which limits, or whether it was revoked five minutes ago. This package replaces that with the agenticprimitives delegation primitive: an EIP-712-signed, caveat-constrained, on-chain-revocable grant from a canonical Smart Agent. When the principal revokes, the tool stops working. When the time window closes, the tool stops working. No key rotation, no scope audit, no guessing.

Part of agenticprimitives — the trust substrate for the agent economy: one canonical Smart Agent identity with custody, delegation, naming, credentials, and audit evidence designed as one system.

This package is the decision layer, not the SDK. The official @modelcontextprotocol/sdk already provides tool/resource/prompt registration, transports, and OAuth 2.1 + PKCE + RFC-9728 + RFC-8707 plumbing (mandated by the 2026-03-15 MCP spec) — you bring it as a peer dependency. We add the bridge to @agenticprimitives/delegation + @agenticprimitives/tool-policy: one wrapper that turns "anyone with the URL" into "exactly the principals with a live, scoped grant." It also eliminated the ~65% authorization-code duplication observed across smart-agent's three mature MCP servers.

See spec.md → specs/205-mcp-runtime.md, and ADR-0004 for why middleware, not SDK.

Quick start

import { McpServer } from '@modelcontextprotocol/sdk/server';
import { withDelegation, createSqliteJtiStore } from '@agenticprimitives/mcp-runtime';

const config = {
  audience: 'urn:mcp:server:person',
  chainId: 31337,
  rpcUrl: process.env.RPC_URL!,
  delegationManager: process.env.DELEGATION_MANAGER_ADDRESS as `0x${string}`,
  enforcerMap,
  jtiStore: createSqliteJtiStore(db, 'token_usage'),
};

const server = new McpServer({ name: 'person-mcp', version: '0.1.0' });

server.registerTool({
  name: 'get_profile',
  inputSchema: { type: 'object', properties: { token: { type: 'string' } } },
  handler: withDelegation(config, async ({ principal }) => {
    return db.profiles.findUnique({ where: { ownerAddress: principal } });
  }),
});

The handler no longer touches auth. The wrapper runs the full pipeline on every call: HMAC envelope check → session-key signature → EIP-712 hash → on-chain isRevoked → ERC-1271 verify → caveat eval (fail-closed) → JTI usage tracking → tool-policy.evaluatePolicy → hand { principal, grants? } to the inner handler. Rejections return a single uniform auth-failed error — externally, a malformed token is indistinguishable from an expired, revoked, or caveat-failed one, so probing leaks nothing.

What ships

  • withDelegation — the tool-handler wrapper above; the headline feature.
  • JTI replay protection — createSqliteJtiStore, createPostgresJtiStore, createMemoryJtiStore; atomic single-use tracking under concurrent writers.
  • declareResource — joins tool-policy classification with MCP resource metadata.
  • verifyDelegationForResource — the low-level verification entry point.
  • Service-to-service MAC — generateServiceMac / verifyServiceMac for the inter-service HTTP envelope.
  • Test harness (/testing subpath) — MockDelegationSigner, createTestConfig, withMockedDelegationContext.
  • Classification lint (/lint subpath) — lintMcpClassification, MCP defaults over tool-policy.lintClassification.
  • Audit events — mcp-runtime.with-delegation.{accept,reject} and mcp-runtime.service-mac.{accept,reject}, correlation-stitched via a caller-supplied correlationId (spec 206).

How it's different

The competing pattern is OAuth scopes, API keys, and MCP auth middleware — server-side allow-lists checked against a bearer credential. Three structural gaps this package closes:

  • Provenance. A scope string says what; a delegation proves who granted it — the principal's Smart Agent signature, verified ERC-1271 against the account on chain. Every accepted call is attributable to a canonical address, not an API-key row.
  • Live revocation. API keys are revoked by rotating them everywhere they leaked. A delegation is revoked once, on chain; the wrapper checks isRevoked on every call.
  • One model across surfaces. The grant your user issued in a web app is the same grant your MCP server verifies — same caveats (time window, value cap, allowed methods), same revocation, same audit trail. ERC-8004 registries and agent discovery are being settled this year; the substrate that wins is the one where tool access, agent calls, and on-chain spend share a single authority model. That is the design center here.

We do not replace the MCP spec's transport-level OAuth — that stays in the official SDK. We answer the question OAuth cannot: on whose delegated authority is this tool executing right now?

Cross-delegation

Removed from the public surface in H7-B.8 (XPKG-002 / EXT-024 closure). The previous withCrossDelegation was a stub that unconditionally rejected. Per spec 100 §6, experimental capability lives behind a ./experimental subpath; when cross-delegation work resumes it lands there. See the production-readiness audit (PKG-mcp-runtime-001).

Validation

pnpm --filter @agenticprimitives/mcp-runtime typecheck
pnpm --filter @agenticprimitives/mcp-runtime test
pnpm check:forbidden-terms

Status

Testnet/pilot-ready. Production launch is gated on the public checklist in the root README.md — including third-party contract audit and governance key rotation. Track every security finding live in docs/audits/findings.yaml. Spec + API are stable; capability.manifest.json marks this package experimental until those gates clear.

License

UNLICENSED (internal monorepo, not published).

版本与发布记录

@agenticprimitives/mcp-runtime 共发布 45 个版本,首次发布于 2026/06/01;过去 12 个月发布了 45 个版本。

版本发布日期距今
1.0.0-alpha.46latest2026/10/2612 天前
1.0.0-alpha.452026/10/2612 天前
1.0.0-alpha.442026/10/1721 天前
1.0.0-alpha.432026/10/1722 天前
1.0.0-alpha.422026/10/1622 天前
1.0.0-alpha.412026/10/1622 天前

其他发布通道:alpha → 0.1.0-alpha.2。

关于 @agenticprimitives/mcp-runtime 的常见问题

@agenticprimitives/mcp-runtime 是什么?

Delegation-aware authorization middleware around the official MCP TypeScript SDK. The decision layer, not the SDK.

如何安装 @agenticprimitives/mcp-runtime?

在项目目录运行 npm install @agenticprimitives/mcp-runtime,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:viem(^2.52.2)、@agenticprimitives/audit(^1.0.0-alpha.46)、@agenticprimitives/types(^1.0.0-alpha.46)、@modelcontextprotocol/sdk(>=1.31.0 <2)、@agenticprimitives/delegation(^1.0.0-alpha.46)、@agenticprimitives/key-custody(^1.0.0-alpha.46)、@agenticprimitives/tool-policy(^1.0.0-alpha.46)、@agenticprimitives/rate-control(^0.0.0-alpha.5)、@agenticprimitives/verification-receipts(^0.0.0-alpha.21)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@agenticprimitives/mcp-runtime 支持 TypeScript 吗?

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

@agenticprimitives/mcp-runtime 支持 ESM 还是 CommonJS?

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

@agenticprimitives/mcp-runtime 可以商用吗?

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

@agenticprimitives/mcp-runtime 的下载量有多少?

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

@agenticprimitives/mcp-runtime 还在维护吗?

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