@contextvm/mcp-sdk

中文文档
1.30.0发布于 2026/06/19MITTypeScriptESM + CJS近 30 天下载 4635

Lightweight stdio-focused Model Context Protocol SDK for TypeScript

原始使用文档
文档目录17 节
  1. Overview
  2. Fork Scope
  3. Installation
  4. Quick Start
  5. Core Concepts
  6. Servers and transports
  7. Tools, resources, prompts
  8. Capabilities: sampling, elicitation, and tasks
  9. JSON Schema validation (opt-in)
  10. Clients
  11. Node.js compatibility
  12. Package Exports
  13. Publishing Notes
  14. Documentation
  15. Release Workflow
  16. Contributing
  17. License

@contextvm/mcp-sdk MIT licensed

Table of Contents

Overview

@contextvm/mcp-sdk is a lightweight fork of the upstream MCP TypeScript SDK tailored for ContextVM and other local-process integrations that only need the MCP protocol core plus stdio transport.

This fork keeps the core protocol runtime and high-level client/server APIs while intentionally removing the HTTP, SSE, WebSocket, Express, Hono, and OAuth-oriented surfaces that added weight without helping the stdio use case.

It makes it easy to:

  • Create MCP servers that expose resources, prompts, and tools
  • Build MCP clients that can connect to local MCP servers
  • Use the retained stdio transport with a smaller dependency footprint

Fork Scope

Supported in this package:

Explicitly not included in this fork:

  • Streamable HTTP transport
  • Legacy SSE transport
  • Express and Hono integrations
  • OAuth/auth helper stack
  • Browser/web transport layers

Installation

npm install @contextvm/mcp-sdk zod

This SDK has a required peer dependency on zod for schema validation. The package internally imports from zod/v4, while remaining compatible with projects using Zod v3.25 or later.

Quick Start

import { McpServer } from '@contextvm/mcp-sdk/server';
import { StdioServerTransport } from '@contextvm/mcp-sdk/server/stdio';
import { z } from 'zod';

const server = new McpServer({
    name: 'example-server',
    version: '1.0.0'
});

server.tool('echo', { message: z.string() }, async ({ message }) => ({
    content: [{ type: 'text', text: message }]
}));

const transport = new StdioServerTransport();
await server.connect(transport);

Core Concepts

Servers and transports

An MCP server is typically created with McpServer and connected to StdioServerTransport for local, process-spawned integrations.

Tools, resources, prompts

  • Tools let LLMs ask your server to take actions (computation, side effects, network calls).
  • Resources expose read-only data that clients can surface to users or models.
  • Prompts are reusable templates that help users talk to models in a consistent way.

The retained server surface still includes tools, resources, prompts, completions, logging, elicitation, sampling, and experimental tasks.

Capabilities: sampling, elicitation, and tasks

The SDK includes higher-level capabilities for richer workflows:

  • Sampling: server-side tools can ask connected clients to run LLM completions.
  • Form elicitation: tools can request non-sensitive input via structured forms.
  • URL elicitation: servers can ask users to complete secure flows in a browser (e.g., API key entry, payments, OAuth).
  • Tasks (experimental): long-running tool calls can be turned into tasks that you poll or resume later.

JSON Schema validation (opt-in)

Tool outputSchema validation (on the client) and elicitation response validation (on the server) are opt-in. By default the SDK does not bundle a JSON Schema validator, so these responses are returned without validation.

To enable validation, import AjvJsonSchemaValidator from the dedicated subpath and pass it to the client and/or server:

import { Client } from '@contextvm/mcp-sdk/client';
import { AjvJsonSchemaValidator } from '@contextvm/mcp-sdk/validation/ajv';

const client = new Client(
    { name: 'my-client', version: '1.0.0' },
    { jsonSchemaValidator: new AjvJsonSchemaValidator() }
);

Keeping validation opt-in means the ajv runtime is only loaded when you actually import the validator — consumers that don't need output validation ship a smaller bundle. Note that McpServer still validates its own tool inputs/outputs against their Zod schemas directly (via Zod), independent of this optional JSON Schema validator.

These higher-level capabilities are preserved in the stdio-focused fork.

Clients

The high-level Client class connects to MCP servers over the retained StdioClientTransport and exposes helpers like listTools, callTool, listResources, readResource, listPrompts, and getPrompt.

Node.js compatibility

This fork targets Node.js 18+ and is optimized for local stdio-based integrations.

Package Exports

  • @contextvm/mcp-sdk
  • @contextvm/mcp-sdk/client
  • @contextvm/mcp-sdk/client/stdio
  • @contextvm/mcp-sdk/server
  • @contextvm/mcp-sdk/server/stdio
  • @contextvm/mcp-sdk/experimental
  • @contextvm/mcp-sdk/experimental/tasks

Publishing Notes

This package is intended to be published as a public npm package under the @contextvm/mcp-sdk name. The published tarball only includes dist output.

Documentation

Release Workflow

Build the publishable package with npm run build, inspect the tarball with npm pack --dry-run, and publish with npm publish --access public once the @contextvm/mcp-sdk scope is ready.

Contributing

Issues and pull requests are welcome on GitHub at https://github.com/ContextVM/mcp-sdk.

License

This project is licensed under the MIT License—see the LICENSE file for details.

版本与发布记录

@contextvm/mcp-sdk 共发布 11 个版本,首次发布于 2026/03/22;过去 12 个月发布了 11 个版本。

版本发布日期距今
1.30.0latest2026/06/194 个月前
1.29.32026/06/194 个月前
1.29.22026/06/184 个月前
1.29.12026/06/124 个月前
1.29.02026/06/124 个月前
1.28.02026/03/267 个月前

其他发布通道:next → 1.27.1-contextvm.2。

关于 @contextvm/mcp-sdk 的常见问题

@contextvm/mcp-sdk 是什么?

Lightweight stdio-focused Model Context Protocol SDK for TypeScript

如何安装 @contextvm/mcp-sdk?

在项目目录运行 npm install @contextvm/mcp-sdk,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:zod(^3.25 || ^4.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@contextvm/mcp-sdk 支持 TypeScript 吗?

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

@contextvm/mcp-sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@contextvm/mcp-sdk 需要什么版本的 Node.js?

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

@contextvm/mcp-sdk 可以商用吗?

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

@contextvm/mcp-sdk 的下载量有多少?

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

@contextvm/mcp-sdk 还在维护吗?

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