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();実際のものを作る準備はできましたか?ステップバイステップのチュートリアルに従ってください:
最初のサーバーを構築する —
npm initからツール呼び出しまでの stdio 気象警報サーバー最初のクライアントを構築する — そのサーバーに接続し、ツールを一覧表示して呼び出す
チュートリアル以外の実行可能なエンドツーエンドの例については、以下を参照してください:
examples/README.md— 実行可能で自己検証可能なクライアント/サーバーの例のペア(ディレクトリごとに1つのストーリー)
ドキュメント
サーバーを構築する — 最初の MCP サーバーをステップバイステップで
クライアントを構築する — 最初の MCP クライアントをステップバイステップで
ドキュメントサイト — 完全なガイド:ツール、リソース、プロンプト、HTTP および stdio での提供、クライアント、OAuth、移行
トラブルシューティング — 一般的なエラーとその修正
ドキュメントをローカルでビルドする
ドキュメントサイトをローカルで作業するには:
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/)This server cannot be deployed
Maintenance
Related MCP Connectors
A simple Typescript MCP server built using the official MCP Typescript SDK and smithery/cli. This…
A TypeScript MCP server for Home Assistant, enabling programmatic management of entities, automati…
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
The Mercado Pago MCP Server implements the Model Context Protocol to provide AI agents and LLMs with access to Mercado Pago's APIs and tools within compatible development environments. It acts as an intermediary that translates Mercado Pago resources into executable functions (tools) that AI applications can invoke to perform actions and automate flows. The server simplifies integration, enables using documentation to implement or improve code, and optimizes operations through natural language interactions without manual implementations.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceA TypeScript framework for building Model Context Protocol (MCP) servers with automatic discovery and loading of tools, resources, and prompts.12 npm-
- AlicenseNot gradedqualityDmaintenanceA 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 npmAGPL 3.0
- AlicenseAqualityDmaintenanceA 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.6ISC
- AlicenseBqualityDmaintenanceA TypeScript MCP server boilerplate providing example tools and resources for rapid development of custom Model Context Protocol servers.8ISC