Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

The official TypeScript SDK for Model Context Protocol servers and clients

License

NotificationsYou must be signed in to change notification settings

modelcontextprotocol/typescript-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Table of Contents

Overview

The Model Context Protocol allows applications to provide context for LLMs in a standardized way, separating the concerns of providing context from the actual LLM interaction. This TypeScript SDK implementsthe full MCP specification, making it easy to:

  • Create MCP servers that expose resources, prompts and tools
  • Build MCP clients that can connect to any MCP server
  • Use standard transports like stdio and Streamable HTTP

Installation

npm install @modelcontextprotocol/sdk zod

This SDK has arequired peer dependency onzod for schema validation. The SDK internally imports fromzod/v4, but maintains backwards compatibility with projects using Zod v3.25 or later. You can use either API in your code by importing fromzod/v3 orzod/v4:

Quick Start

To see the SDK in action end-to-end, start from the runnable examples insrc/examples:

  1. Install dependencies (from the SDK repo root):

    npm install
  2. Run the example Streamable HTTP server:

    npx tsx src/examples/server/simpleStreamableHttp.ts
  3. Run the interactive client in another terminal:

    npx tsx src/examples/client/simpleStreamableHttp.ts

This pair of examples demonstrates tools, resources, prompts, sampling, elicitation, tasks and logging. For a guided walkthrough and variations (stateless servers, JSON-only responses, SSE compatibility, OAuth, etc.), seedocs/server.md anddocs/client.md.

Core Concepts

Servers and transports

An MCP server is typically created withMcpServer and connected to a transport such as Streamable HTTP or stdio. The SDK supports:

  • Streamable HTTP for remote servers (recommended).
  • HTTP + SSE for backwards compatibility only.
  • stdio for local, process-spawned integrations.

Runnable server examples live undersrc/examples/server and are documented indocs/server.md.

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 detailed APIs, includingResourceTemplate, completions, and display-name metadata, are covered indocs/server.md, with runnable implementations insimpleStreamableHttp.ts.

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.

Conceptual overviews and links to runnable examples are in:

Key example servers include:

Clients

The high-levelClient class connects to MCP servers over different transports and exposes helpers likelistTools,callTool,listResources,readResource,listPrompts, andgetPrompt.

Runnable clients live undersrc/examples/client and are described indocs/client.md, including:

Node.js Web Crypto (globalThis.crypto) compatibility

Some parts of the SDK (for example, JWT-based client authentication inauth-extensions.ts viajose) rely on the Web Crypto API exposed asglobalThis.crypto.

Seedocs/faq.md for details on supported Node.js versions and how to polyfillglobalThis.crypto when running on older Node.js runtimes.

Examples

The SDK ships runnable examples undersrc/examples. Use these tables to find the scenario you care about and jump straight to the corresponding code and docs.

Server examples

ScenarioDescriptionExample file(s)Related docs
Streamable HTTP server (stateful)Feature-rich server with tools, resources, prompts, logging, tasks, sampling, and optional OAuth.simpleStreamableHttp.tsserver.md,capabilities.md
Streamable HTTP server (stateless)No session tracking; good for simple API-style servers.simpleStatelessStreamableHttp.tsserver.md
JSON response mode (no SSE)Streamable HTTP with JSON responses only and limited notifications.jsonResponseStreamableHttp.tsserver.md
Server notifications over Streamable HTTPDemonstrates server-initiated notifications using SSE with Streamable HTTP.standaloneSseWithGetStreamableHttp.tsserver.md
Deprecated HTTP+SSE serverLegacy HTTP+SSE transport for backwards-compatibility testing.simpleSseServer.tsserver.md
Backwards-compatible server (Streamable HTTP + SSE)Single server that supports both Streamable HTTP and legacy SSE clients.sseAndStreamableHttpCompatibleServer.tsserver.md
Form elicitation serverUses form elicitation to collect non-sensitive user input.elicitationFormExample.tscapabilities.md
URL elicitation serverDemonstrates URL-mode elicitation in an OAuth-protected server.elicitationUrlExample.tscapabilities.md
Sampling and tasks serverCombines tools, logging, sampling, and experimental task-based execution.toolWithSampleServer.tscapabilities.md
OAuth demo authorization serverIn-memory OAuth provider used with the example servers.demoInMemoryOAuthProvider.tsserver.md

Client examples

ScenarioDescriptionExample file(s)Related docs
Interactive Streamable HTTP clientCLI client that exercises tools, resources, prompts, elicitation, and tasks.simpleStreamableHttp.tsclient.md
Backwards-compatible client (Streamable HTTP → SSE)Tries Streamable HTTP first, then falls back to SSE on 4xx responses.streamableHttpWithSseFallbackClient.tsclient.md,server.md
SSE polling clientPolls a legacy SSE server and demonstrates notification handling.ssePollingClient.tsclient.md
Parallel tool calls clientShows how to run multiple tool calls in parallel.parallelToolCallsClient.tsclient.md
Multiple clients in parallelDemonstrates connecting multiple clients concurrently to the same server.multipleClientsParallel.tsclient.md
OAuth clientsExamples of client_credentials (basic and private_key_jwt) and reusable providers.simpleOAuthClient.ts,simpleOAuthClientProvider.ts,simpleClientCredentials.tsclient.md
URL elicitation clientWorks with the URL elicitation server to drive secure browser flows.elicitationUrlExample.tscapabilities.md

Shared utilities:

For more details on how to run these examples (including recommended commands and deployment diagrams), seesrc/examples/README.md.

Documentation

Contributing

Issues and pull requests are welcome on GitHub athttps://github.com/modelcontextprotocol/typescript-sdk.

License

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

About

The official TypeScript SDK for Model Context Protocol servers and clients

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors138


[8]ページ先頭

©2009-2025 Movatter.jp