### Quick Start: Streamable HTTP Server and Client Source: https://ts.sdk.modelcontextprotocol.io/ A step-by-step guide to running the example Streamable HTTP server and its interactive client. ```APIDOC ## 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): ```bash npm install ``` 2. **Run the example Streamable HTTP server**: ```bash npx tsx src/examples/server/simpleStreamableHttp.ts ``` 3. **Run the interactive client in another terminal**: ```bash 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](documents/server.html) and [docs/client.md](documents/client.html). ``` -------------------------------- ### Clone and Install Dependencies Source: https://modelcontextprotocol.io/extensions/apps/build Clone the ext-apps repository and install the necessary dependencies for the basic-host example. This setup is required before running the test interface. ```bash git clone https://github.com/modelcontextprotocol/ext-apps.git cd ext-apps/examples/basic-host npm install ``` -------------------------------- ### Run MCP Apps with basic-host Source: https://apps.extensions.modelcontextprotocol.io/api Instructions to clone, install, and start the basic-host reference implementation for running MCP Apps examples locally. This involves using git, npm, and starting a local server. ```bash git clone https://github.com/modelcontextprotocol/ext-apps.git cd ext-apps npm install npm start ``` -------------------------------- ### Run MCP Client with Weather Server Quickstart Source: https://modelcontextprotocol.io/docs/develop/build-client Example command to run the .NET client connected to the weather server quickstart project. ```bash dotnet run -- path/to/QuickstartWeatherServer ``` -------------------------------- ### Run MCP Client with Weather Server Example Source: https://modelcontextprotocol.io/docs/develop/build-client Example command to run the MCP client with the weather server from the quickstart tutorial. This demonstrates connecting to a specific server implementation. ```bash python client.py .../quickstart-resources/weather-server-python/weather.py ``` -------------------------------- ### Initialize MCP Server in C# Source: https://modelcontextprotocol.io/llms-full.txt Example of starting an MCP server with authorization logging and running the application. ```csharp Console.WriteLine($"Starting MCP server with authorization at {serverUrl}"); Console.WriteLine($"Using Keycloak server at {authorizationServerUrl}"); Console.WriteLine($"Protected Resource Metadata URL: {serverUrl}.well-known/oauth-protected-resource"); Console.WriteLine("Exposed Math tools: Add, Multiply"); Console.WriteLine("Press Ctrl+C to stop the server"); app.Run(serverUrl); ``` -------------------------------- ### Example MCP Server Command Source: https://modelcontextprotocol.io/docs/tools/inspector This example shows how to run an MCP server with specific package names and arguments. Ensure the package name and arguments are correct for your server setup. ```bash mcp-server --package-name "my-package" --args ... ``` -------------------------------- ### Basic Host Integration Example Source: https://modelcontextprotocol.io/llms-full.txt Demonstrates how to integrate the App Bridge SDK for rendering MCP Apps in a host application. This example shows the fundamental setup for message passing and security. ```javascript import { AppBridge } from '@modelcontextprotocol/app-bridge'; const bridge = new AppBridge({ // Configuration options for the bridge }); // Example of using the bridge to render an app bridge.renderApp({ appId: 'my-app', // Other app-specific options }); ``` -------------------------------- ### Setup Project on Linux/macOS Source: https://modelcontextprotocol.io/docs/develop/build-client Commands to set up a new project using MCP on Linux or macOS. This includes activating a virtual environment, installing packages with `uv`, and removing boilerplate files. ```bash # Activate virtual environment source .venv/bin/activate # Install required packages uv add mcp anthropic python-dotenv # Remove boilerplate files rm main.py # Create our main file touch client.py ``` -------------------------------- ### Running Client with Weather Tutorial Server Source: https://modelcontextprotocol.io/docs/develop/build-client Example command to run the client specifically with the weather tutorial server. ```bash java -jar build/libs/kotlin-mcp-client-0.1.0-all.jar .../samples/weather-stdio-server/build/libs/weather-stdio-server-0.1.0-all.jar ``` -------------------------------- ### Initialize a new .NET project Source: https://modelcontextprotocol.io/docs/develop/build-client Use the dotnet CLI to create a new console application for the QuickstartClient. ```shellscript dotnet new console -n QuickstartClient ``` -------------------------------- ### Get Weather Function Call Example Source: https://modelcontextprotocol.io/specification/2025-06-18/server/tools Example of a request to the LLM to get weather information for a specific location. ```APIDOC ## POST /llms ### Description This endpoint processes natural language requests and returns structured output, potentially including function calls. ### Method POST ### Endpoint /llms ### Request Body - **jsonrpc** (string) - Required - The JSON-RPC protocol version. - **method** (string) - Required - The method to call, e.g., "get_weather". - **params** (object) - Required - Parameters for the method. - **location** (string) - Required - The location for which to get the weather. ### Request Example ```json { "jsonrpc": "2.0", "method": "get_weather", "params": { "location": "New York" } } ``` ### Response #### Success Response (200) - **jsonrpc** (string) - The JSON-RPC protocol version. - **id** (number) - The ID of the request. - **result** (object) - The result of the method call. - **content** (string) - The weather information. #### Response Example ```json { "jsonrpc": "2.0", "id": 2, "result": { "content": "The weather in New York is sunny with a temperature of 75 degrees Fahrenheit." } } ``` ``` -------------------------------- ### Initialize Client Structure Source: https://modelcontextprotocol.io/docs/develop/build-client Basic setup for the Program.cs file including host builder and configuration loading. ```csharp using Anthropic.SDK; using Microsoft.Extensions.AI; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using ModelContextProtocol.Client; using ModelContextProtocol.Protocol.Transport; var builder = Host.CreateApplicationBuilder(args); builder.Configuration .AddEnvironmentVariables() .AddUserSecrets(); ``` -------------------------------- ### Initialize Go Project Source: https://modelcontextprotocol.io/llms-full.txt Commands to initialize the Go module, install the MCP SDK, and create the main server file. ```bash # Initialize Go module go mod init weather # Install dependencies go get github.com/modelcontextprotocol/go-sdk/mcp # Create our server file touch main.go ``` ```powershell # Create a new directory for our project md weather cd weather # Initialize Go module go mod init weather # Install dependencies go get github.com/modelcontextprotocol/go-sdk/mcp # Create our server file new-item main.go ``` -------------------------------- ### Run Test Host for MCP App Source: https://apps.extensions.modelcontextprotocol.io/api/documents/Quickstart.html Initiates the test host application, which is used to interact with and test MCP applications. This involves cloning the `ext-apps` repository, installing its dependencies, and then starting the basic host example. ```bash git clone https://github.com/modelcontextprotocol/ext-apps.git cd ext-appsnpm install cd examples/basic-host npm start ``` -------------------------------- ### Start local documentation server Source: https://modelcontextprotocol.io/community/contributing Launch a live preview of the documentation at http://localhost:3000 with hot reloading enabled. ```shellscript npm run serve:docs ``` -------------------------------- ### PyPI Package Installation Example Source: https://modelcontextprotocol.io/docs/tools/inspector Example of installing a PyPI package using the inspector. This command is used for packages available on the Python Package Index. ```shellscript npx @modelcontextprotocol/inspector uvx package-name > args> ``` -------------------------------- ### Initialize Client and Configure Options Source: https://modelcontextprotocol.io/docs/develop/build-client Example showing the initialization of the client with API authentication and the definition of chat options. ```javascript client = new APIAuthentication(builder.Configuration["ANTHROPIC_API_KEY"])) .Messages .AsBuilder() .UseFunctionInvocation() .Build(); var options = new ChatOptions { MaxOutputTokens = 1000 ``` -------------------------------- ### Example HTTP GET Request to MCP Source: https://modelcontextprotocol.io/specification/draft/basic/authorization This example demonstrates a valid HTTP GET request to an MCP resource, adhering to the specified token handling requirements. Access tokens must not be included in the URI query string. ```http GET /mcp HTTP/1.1 Host: mcp.example.com Authorization: Bearer ``` -------------------------------- ### GET /mcp Source: https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization Example of an authorized request to an MCP server endpoint. ```APIDOC ## GET /mcp ### Description An example request to the MCP server endpoint demonstrating the use of a Bearer token for authorization. ### Method GET ### Endpoint /mcp ### Request Example GET /mcp HTTP/1.1 Host: mcp.example.com Authorization: Bearer eyJhbGciOiJIUzI1NiIs... ``` -------------------------------- ### Configure Server Path Examples Source: https://modelcontextprotocol.io/llms-full.txt Examples of relative, absolute, and Windows-specific path formats for server scripts. ```bash # Relative path uv run client.py ./server/weather.py # Absolute path uv run client.py /Users/username/projects/mcp-server/weather.py # Windows path (either format works) uv run client.py C:/projects/mcp-server/weather.py uv run client.py C:\\projects\\mcp-server\\weather.py ``` -------------------------------- ### GET /mcp Source: https://modelcontextprotocol.io/specification/latest/basic/authorization Example of an authenticated request to an MCP server using a Bearer token. ```APIDOC ## GET /mcp ### Description An example request to an MCP server endpoint demonstrating the use of an Authorization header with a Bearer token. ### Method GET ### Endpoint /mcp ### Request Example GET /mcp HTTP/1.1 Host: mcp.example.com Authorization: Bearer eyJhbGciOiJIUzI1NiIs... ``` -------------------------------- ### Initialize and Run MCP Client Source: https://modelcontextprotocol.io/docs/develop/build-client Demonstrates how to instantiate an MCPClient, connect to a server using command-line arguments, and start a chat loop within a try-catch block. ```javascript .span, {\n className: \ ``` ```javascript const mcpClient = new MCPClient();\n try {\n await mcpClient.connectToServer(process.argv[2]);\n await mcpClient.chatLoop();\n } catch (e) {\n console ``` -------------------------------- ### HTTP Request with Bearer Token Source: https://modelcontextprotocol.io/llms-full.txt Example of an authenticated HTTP GET request to an MCP server. ```http GET /mcp HTTP/1.1 Host: mcp.example.com Authorization: Bearer eyJhbGciOiJIUzI1NiIs... ``` -------------------------------- ### Install SDK and Project Dependencies Source: https://modelcontextprotocol.io/docs/develop/build-client Commands to install the required AI and MCP SDKs, development types, and initialize a source file. ```bash # Install dependencies npm install @anthropic-ai/sdk @modelcontextprotocol/sdk dotenv # Install dev dependencies npm install -D @types/node typescript # Create source file new-item index.ts ``` -------------------------------- ### Setting Up the MCP Project Source: https://modelcontextprotocol.io/llms-full.txt Commands to initialize a new Python project, create a virtual environment, and install dependencies. ```bash # Create a new directory for our project uv init weather cd weather # Create virtual environment and activate it uv venv source .venv/bin/activate # Install dependencies uv add "mcp[cli]" httpx # Create our server file touch weather.py ``` ```powershell # Create a new directory for our project uv init weather cd weather # Create virtual environment and activate it uv venv .venv\Scripts\activate # Install dependencies uv add mcp[cli] httpx # Create our server file new-item weather.py ``` -------------------------------- ### Initialize Project Environment Source: https://modelcontextprotocol.io/llms-full.txt Commands to create the project directory, initialize npm, and install necessary dependencies. ```bash # Create a new directory for our project mkdir weather cd weather # Initialize a new npm project npm init -y # Install dependencies npm install @modelcontextprotocol/sdk zod@3 npm install -D @types/node typescript # Create our files mkdir src touch src/index.ts ``` ```powershell # Create a new directory for our project md weather cd weather # Initialize a new npm project npm init -y # Install dependencies npm install @modelcontextprotocol/sdk zod@3 npm install -D @types/node typescript # Create our files md src new-item src\index.ts ``` -------------------------------- ### Begin Tool Call Example Source: https://modelcontextprotocol.io/seps/1686-tasks This example shows how to start a tool call with specific parameters and options, including the method 'tools/call'. It's designed for scenarios where you need to invoke a tool and expect a structured result. ```typescript const request = await this.beginRequest({ method: "tools/call", params: {}, resultSchema:, options: }); return request; ``` -------------------------------- ### Initialize Project on Unix-like Systems Source: https://modelcontextprotocol.io/docs/develop/build-client Commands for installing dependencies and creating a source file on macOS or Linux. ```bash # Install dev dependencies npm install -D @types/node typescript # Create source file touch index.ts ``` -------------------------------- ### Get Task Request Example Source: https://modelcontextprotocol.io/seps/1686-tasks A JSON-RPC request to retrieve the state of a task. This is used by requestors to query task status. ```json { "jsonrpc": "2.0" } ``` -------------------------------- ### Completion Request Example Source: https://modelcontextprotocol.io/llms-full.txt A client sends this request to the server to get completion suggestions for a given prompt reference and argument. ```json { "ref": { "module": "my_module", "name": "my_prompt" }, "argument": { "name": "my_argument", "value": "initial value" }, "context": { "arguments": { "other_argument": "resolved value" } } } ``` -------------------------------- ### Setup Project on Windows Source: https://modelcontextprotocol.io/docs/develop/build-client Commands to set up a new project using MCP on Windows. This involves initializing a project directory and navigating into it using `uv`. ```powershell # Create project directory uv init mcp-client cd mcp-client ``` -------------------------------- ### JSON-RPC Request Example Source: https://modelcontextprotocol.io/specification/2025-11-25/basic/lifecycle Illustrates a JSON-RPC request to get LLM capabilities. Ensure the 'jsonrpc', 'method', and 'id' fields are correctly set. ```json { "jsonrpc": "2.0", "method": "llm/capabilities", "id": 1 } ``` -------------------------------- ### Initialize MCP Client Environment (macOS/Linux) Source: https://modelcontextprotocol.io/llms-full.txt Sets up a new Python project directory, creates and activates a virtual environment, installs necessary packages, and prepares the main client file. ```bash # Create project directory uv init mcp-client cd mcp-client # Create virtual environment uv venv # Activate virtual environment source .venv/bin/activate # Install required packages uv add mcp anthropic python-dotenv # Remove boilerplate files rm main.py # Create our main file touch client.py ``` -------------------------------- ### Minimal Initial Scope Source: https://modelcontextprotocol.io/specification/2025-11-25/basic/security_best_practices Example of a minimal initial scope for low-risk discovery and read operations. This is a recommended starting point for client applications. ```plaintext mcp:tools-basic ``` -------------------------------- ### Initialize MCP Client Project on Windows Source: https://modelcontextprotocol.io/docs/develop/build-client Commands to set up the project structure, virtual environment, and install necessary dependencies. ```powershell # Create project directory uv init mcp-client cd mcp-client # Create virtual environment uv venv # Activate virtual environment .venv\Scripts\activate # Install required packages uv add mcp anthropic python-dotenv # Remove boilerplate files del main.py # Create our main file ``` -------------------------------- ### Run MCP Application Commands Source: https://modelcontextprotocol.io/extensions/apps/build Commands to install dependencies, build the project, and start the server. Ensure you are in the application directory before executing these commands. ```shellscript npm install && npm run build && npm run serve ``` ```powershell npm install; npm run build; npm run serve ``` -------------------------------- ### Initialize MCP Client Environment (Windows) Source: https://modelcontextprotocol.io/llms-full.txt Sets up a new Python project directory, creates and activates a virtual environment, installs necessary packages, and prepares the main client file. ```powershell # Create project directory uv init mcp-client cd mcp-client # Create virtual environment uv venv # Activate virtual environment .venv\Scripts\activate # Install required packages uv add mcp anthropic python-dotenv # Remove boilerplate files del main.py # Create our main file new-item client.py ``` -------------------------------- ### Example: Getting Travel Planning Context Source: https://modelcontextprotocol.io/docs/learn/server-concepts Demonstrates how to use the protocol to retrieve context for travel planning, including calendar data, travel documents, and past itineraries. ```APIDOC ## Example: Getting Travel Planning Context This section illustrates how resources can be leveraged for travel planning scenarios. ### Resources Used: * **Calendar data**: `calendar://events/2024` - Used to check user availability. * **Travel documents**: `file:///Documents/Travel/passport.pdf` - Used to access important documents. * **Previous itineraries**: `trips://history/barcelona-2023` - Used to reference past trips and preferences. ### AI Application Process: The AI application retrieves these resources and decides how to process them, potentially using embeddings, keyword search, or passing raw data directly to the model. In this example, calendar data, weather information, and travel preferences are provided to the model to enable it to check availability, look up weather patterns, and reference past travel preferences. ``` -------------------------------- ### Bash Command to Run Client Source: https://modelcontextprotocol.io/llms-full.txt Example command to run the Python MCP client with a specified server script. Ensure `uv` is installed and the path to your server script is correct. ```bash uv run client.py path/to/server.py # python server ``` -------------------------------- ### Setup MCP Client Source: https://modelcontextprotocol.io/docs/develop/build-client Implementation of the StdioClientTransport and tool listing logic. ```csharp var (command, arguments) = GetCommandAndArguments(args); var clientTransport = new StdioClientTransport(new() { Name = "Demo Server", Command = command, Arguments = arguments, }); await using var mcpClient = await McpClient.CreateAsync(clientTransport); var tools = await mcpClient.ListToolsAsync(); foreach (var tool in tools) { Console.WriteLine($"Connected to server with tools: {tool.Name}"); } ``` -------------------------------- ### Initial Claude API Call Example Source: https://modelcontextprotocol.io/docs/develop/build-client This snippet shows an initial API call to Claude, likely for processing a query or task. It's a starting point for LLM interactions. ```javascript # Initial Claude API call. response = ```