Skip to main content
Glama
dilipbaviskar

MCP TypeScript SDK

MCP TypeScript SDK

概要

Model Context Protocol (MCP) は、アプリケーションが LLM にコンテキストを提供するための標準化された方法を提供し、コンテキストの提供と実際の LLM インタラクションの関心事を分離します。

このリポジトリには、MCP 仕様の TypeScript SDK 実装が含まれています。Node.js、Bun、Deno で動作し、以下を提供します:

  • MCP サーバー ライブラリ(ツール/リソース/プロンプト、Streamable HTTP、stdio、認証ヘルパー)

  • MCP クライアント ライブラリ(トランスポート、高レベルヘルパー、OAuth ヘルパー)

  • 特定のランタイム/フレームワーク向けのオプションの ミドルウェアパッケージ(Express、Fastify、Hono、Node.js HTTP)

  • 実行可能な 例(examples/ 以下)

Related MCP server: MCP - Model Context Protocol TypeScript SDK

パッケージ

このモノレポは分割されたパッケージを公開しています:

  • @modelcontextprotocol/server: MCP サーバーを構築

  • @modelcontextprotocol/client: MCP クライアントを構築

ツールとプロンプトのスキーマは Standard Schema を使用します — Zod v4、Valibot、ArkType、または互換性のある任意のライブラリを持ち込んでください。

これらは意図的に薄いアダプターです:新しい MCP 機能やビジネスロジックを導入すべきではありません。詳細は packages/middleware/README.md を参照してください。

  • @modelcontextprotocol/node: IncomingMessage / ServerResponse 用の Node.js Streamable HTTP トランスポートラッパー

  • @modelcontextprotocol/express: Express ヘルパー(アプリのデフォルト + Host ヘッダー検証)

  • @modelcontextprotocol/fastify: Fastify ヘルパー(アプリのデフォルト + Host ヘッダー検証)

  • @modelcontextprotocol/hono: Hono ヘルパー(アプリのデフォルト + JSON ボディ解析フック + Host ヘッダー検証)

インストール

サーバー

npm install @modelcontextprotocol/server
# or
bun add @modelcontextprotocol/server
# or
deno add npm:@modelcontextprotocol/server

クライアント

npm install @modelcontextprotocol/client
# or
bun add @modelcontextprotocol/client
# or
deno add npm:@modelcontextprotocol/client

オプションのミドルウェアパッケージ

SDK は、MCP を特定のランタイムやウェブフレームワーク(Express、Fastify、Hono、Node.js http など)に 配線する のに役立つオプションの「ミドルウェア」パッケージも公開しています。

これらのパッケージは意図的に薄いアダプターであり、追加の MCP 機能やビジネスロジックを導入すべきではありません。詳細は packages/middleware/README.md を参照してください。

# Node.js HTTP (IncomingMessage/ServerResponse) Streamable HTTP transport:
npm install @modelcontextprotocol/node

# Express integration:
npm install @modelcontextprotocol/express express

# Fastify integration:
npm install @modelcontextprotocol/fastify fastify

# Hono integration:
npm install @modelcontextprotocol/hono hono

はじめに

MCP サーバーは次のようになります。この最小限の例では、stdio 上で単一の greet ツールを公開します:

import { McpServer } from '@modelcontextprotocol/server';
import { StdioServerTransport } from '@modelcontextprotocol/server/stdio';
import * as z from 'zod/v4';

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

server.registerTool(
    'greet',
    {
        description: 'Greet someone by name',
        inputSchema: z.object({ name: z.string() })
    },
    async ({ name }) => ({
        content: [{ type: 'text', text: `Hello, ${name}!` }]
    })
);

async function main() {
    const transport = new StdioServerTransport();
    await server.connect(transport);
}

main();

実際のものを作る準備はできましたか?ステップバイステップのチュートリアルに従ってください:

チュートリアル以外の実行可能なエンドツーエンドの例については、以下を参照してください:

  • examples/README.md — 実行可能で自己検証可能なクライアント/サーバーの例のペア(ディレクトリごとに1つのストーリー)

ドキュメント

ドキュメントをローカルでビルドする

ドキュメントサイトをローカルで作業するには:

pnpm docs:api      # Generate the API reference markdown (output: docs/api/)
pnpm docs:dev      # Start the VitePress dev server for the V2 site
pnpm docs:build    # Build the V2 site (output: docs/.vitepress/dist/)
pnpm docs:multi    # Build the combined V1 + V2 site (output: tmp/docs-combined/)

Maintenance

ActivityMaintained
ResponsivenessSyncing

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    A TypeScript wrapper library for the Model Context Protocol SDK that provides a simplified interface for creating MCP servers with tools, resources, and prompts without needing to work directly with the protocol.
    19 npm
    AGPL 3.0
  • A
    license
    A
    quality
    D
    maintenance
    A starter project for rapidly developing Model Context Protocol servers using TypeScript and the official SDK. It includes pre-implemented examples of tools and resources to help developers jumpstart their custom MCP server development.
    6
    ISC
  • A
    license
    B
    quality
    D
    maintenance
    A TypeScript MCP server boilerplate providing example tools and resources for rapid development of custom Model Context Protocol servers.
    8
    ISC