Home / Servers

@modelcontextprotocol/sdk

by modelcontextprotocol

MCP TypeScript SDK NPM Version MIT licensed

<details> <summary>Table of Contents</summary> </details>

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 implements the 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 a required peer dependency on zod for schema validation. The SDK internally imports from zod/v4, but maintains backwards compatibility with projects using Zod v3.25 or later. You can use either API in your code by importing from zod/v3 or zod/v4:

Quick Start

To see the SDK in action end-to-end, start from the runnable examples in src/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.), see docs/server.md and docs/client.md.

Core Concepts

Servers and transports

An MCP server is typically created with McpServer 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 under src/examples/server and are documented in docs/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, including ResourceTemplate, completions, and display-name metadata, are covered in docs/server.md, with runnable implementations in simpleStreamableHttp.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:

Related servers

n8n

by n8n-io

Fair-code workflow automation platform with native AI capabilities. Combine visual building with custom code, self-host or cloud, 400+ integrations.

NOASSERTION198,904

@modelcontextprotocol/server-everything

Official

by modelcontextprotocol

MCP server that exercises all the features of the MCP protocol

89,105

@modelcontextprotocol/server-filesystem

Official

by modelcontextprotocol

MCP server for filesystem access

SEE LICENSE IN LICENSE89,105

mcp-server-fetch

Official

by modelcontextprotocol

A Model Context Protocol server providing tools to fetch and convert web content for usage by LLMs

89,105