Skip to content

Conversation

ochafik
Copy link
Contributor

@ochafik ochafik commented Oct 1, 2025

Draft reference implementation + examples for SEP-1577 - Sampling With Tools

cc/ @bhosmer-ant

Motivation and Context

This allows & demonstrates tool call loops in MCP servers using improvements to sampling proposed in modelcontextprotocol/modelcontextprotocol#1577

How Has This Been Tested?

# The sampling backfill uses the Claude API
export ANTHROPIC_API_KEY=...

npx -y @modelcontextprotocol/inspector \
  npx -y --silent tsx src/examples/backfill/backfillSampling.ts \
    -- \
    npx -y --silent tsx src/examples/server/toolLoopSampling.ts

Then give a prompt to the localResearch tool such as summarize the main classes. It crunches for a while (logs tool calls on the fly) then should give its final output w/ the full tool loop transcript as debug content:

CleanShot 2025-10-01 at 19 21 57
see final output


Now I have a comprehensive understanding of the sampling-related classes and types. Let me compile this information:

## Classes and Types Involved with Sampling

Based on my search through the codebase, here are the key classes and types related to sampling in the Model Context Protocol (MCP) TypeScript SDK:

### Core Sampling Types

**Message Types:**
- **`SamplingMessage`** - Discriminated union of `UserMessage` and `AssistantMessage`
- **`UserMessage`** - A message from the user (server) with role "user"
- **`AssistantMessage`** - A message from the assistant (LLM) with role "assistant"

**Content Types for Messages:**
- **`UserMessageContent`** - Union of: `TextContent`, `ImageContent`, `AudioContent`, `ToolResultContent`
- **`AssistantMessageContent`** - Union of: `TextContent`, `ImageContent`, `AudioContent`, `ToolCallContent`

**Content Blocks:**
- **`TextContent`** - Text-based content with annotations
- **`ImageContent`** - Base64-encoded image data with MIME type
- **`AudioContent`** - Base64-encoded audio data with MIME type
- **`ToolCallContent`** - Tool call request from LLM (type: "tool_use")
- **`ToolResultContent`** - Tool execution result (type: "tool_result")

### Request/Response Types

- **`CreateMessageRequest`** - Request from server to sample an LLM via client (method: "sampling/createMessage")
  - Contains: messages, systemPrompt, maxTokens, temperature, tools, toolChoice, modelPreferences, etc.
  
- **`CreateMessageResult`** - Client's response to sampling request
  - Contains: model name, stopReason, role ("assistant"), content

### Model Selection Types

- **`ModelPreferencesSchema`** - Server's preferences for model selection
  - `hints`: Optional array of `ModelHint`
  - `costPriority`: 0-1 priority for cost
  - `speedPriority`: 0-1 priority for latency
  - `intelligencePriority`: 0-1 priority for capabilities

- **`ModelHintSchema`** - Hints for model selection
  - `name`: Optional model name hint

### Tool-Related Types

- **`ToolChoice`** - Controls tool usage behavior
  - `mode`: "auto" | "required" | "none"
  - `disable_parallel_tool_use`: Optional boolean

- **`Tool`** - Tool definition with name, description, and inputSchema

### Capabilities

- **`ClientCapabilities.sampling`** - Indicates client supports sampling
  - `sampling.tools`: Supports tools and tool_choice parameters
  - `sampling.context`: Supports includeContext parameter (soft-deprecated)

### Classes with Sampling Methods

**Server Class** (`src/server/index.ts`):
- **`createMessage(params, options)`** - Method to request LLM sampling from client
  - Validates client has sampling capability
  - Sends "sampling/createMessage" request

**Client Class** (`src/client/index.ts`):
- Handles incoming "sampling/createMessage" requests from server
  - Validates sampling capability is declared
  - Routes to request handler

### Key Constants

- **Stop Reasons**: "endTurn", "stopSequence", "maxTokens", "toolUse", "refusal", "other"
- **Method**: "sampling/createMessage"

### Schemas (Zod validators)

All types have corresponding Zod schemas for validation:
- `SamplingMessageSchema`
- `CreateMessageRequestSchema`
- `CreateMessageResultSchema`
- `ModelPreferencesSchema`
- `ToolChoiceSchema`
- And all content type schemas

This sampling system enables MCP servers to request LLM completions from connected clients, with full support for tool calling, multi-modal content (text, images, audio), and model selection preferences.
see debug output

--- Debug Transcript (30 messages) ---
[
  {
    "role": "user",
    "content": {
      "type": "text",
      "text": "find classes and types involved w/ sampling"
    }
  },
  {
    "role": "assistant",
    "content": [
      {
        "type": "text",
        "text": "I'll help you find classes and types related to sampling. Let me search through the codebase."
      },
      {
        "type": "tool_use",
        "name": "ripgrep",
        "id": "toolu_01URJF7aBdPZA9evsr4roJB3",
        "input": {
          "pattern": "(class|type|interface|struct)\\s+\\w*[Ss]ampl\\w*",
          "path": "."
        }
      }
    ]
  },
  {
    "role": "user",
    "content": [
      {
        "type": "tool_result",
        "toolUseId": "toolu_01URJF7aBdPZA9evsr4roJB3",
        "content": {
          "output": "{\"type\":\"begin\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"}}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type SamplingMessage = Infer<typeof SamplingMessageSchema>;\\n\"},\"line_number\":1816,\"absolute_offset\":57122,\"submatches\":[{\"match\":{\"text\":\"type SamplingMessage\"},\"start\":7,\"end\":27}]}}\n{\"type\":\"end\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"binary_offset\":null,\"stats\":{\"elapsed\":{\"secs\":0,\"nanos\":235208,\"human\":\"0.000235s\"},\"searches\":1,\"searches_with_match\":1,\"bytes_searched\":59122,\"bytes_printed\":433,\"matched_lines\":1,\"matches\":1}}}\n{\"data\":{\"elapsed_total\":{\"human\":\"0.015519s\",\"nanos\":15519042,\"secs\":0},\"stats\":{\"bytes_printed\":433,\"bytes_searched\":59122,\"elapsed\":{\"human\":\"0.000235s\",\"nanos\":235208,\"secs\":0},\"matched_lines\":1,\"matches\":1,\"searches\":1,\"searches_with_match\":1}},\"type\":\"summary\"}\n"
        }
      }
    ]
  },
  {
    "role": "assistant",
    "content": [
      {
        "type": "tool_use",
        "name": "ripgrep",
        "id": "toolu_01M2bsv4TXKLzVEkaNgGBqnz",
        "input": {
          "pattern": "[Ss]ampl(ing|e)",
          "path": "."
        }
      }
    ]
  },
  {
    "role": "user",
    "content": [
      {
        "type": "tool_result",
        "toolUseId": "toolu_01M2bsv4TXKLzVEkaNgGBqnz",
        "content": {
          "output": "{\"type\":\"begin\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/README.md\"}}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/README.md\"},\"lines\":{\"text\":\"  - [Sampling](#sampling)\\n\"},\"line_number\":15,\"absolute_offset\":471,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":5,\"end\":13},{\"match\":{\"text\":\"sampling\"},\"start\":16,\"end\":24}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/README.md\"},\"lines\":{\"text\":\"### Sampling\\n\"},\"line_number\":388,\"absolute_offset\":11447,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":4,\"end\":12}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/README.md\"},\"lines\":{\"text\":\"MCP servers can request LLM completions from connected clients that support sampling.\\n\"},\"line_number\":390,\"absolute_offset\":11461,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":76,\"end\":84}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/README.md\"},\"lines\":{\"text\":\"  name: \\\"tools-with-sample-server\\\",\\n\"},\"line_number\":398,\"absolute_offset\":11773,\"submatches\":[{\"match\":{\"text\":\"sample\"},\"start\":20,\"end\":26}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/README.md\"},\"lines\":{\"text\":\"// Tool that uses LLM sampling to summarize any text\\n\"},\"line_number\":402,\"absolute_offset\":11834,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":22,\"end\":30}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/README.md\"},\"lines\":{\"text\":\"    // Call the LLM through MCP sampling\\n\"},\"line_number\":412,\"absolute_offset\":12091,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":32,\"end\":40}]}}\n{\"type\":\"end\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/README.md\"},\"binary_offset\":null,\"stats\":{\"elapsed\":{\"secs\":0,\"nanos\":73000,\"human\":\"0.000073s\"},\"searches\":1,\"searches_with_match\":1,\"bytes_searched\":38168,\"bytes_printed\":1838,\"matched_lines\":6,\"matches\":7}}}\n{\"type\":\"begin\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.test.ts\"}}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.test.ts\"},\"lines\":{\"text\":\"    SamplingMessageSchema,\\n\"},\"line_number\":14,\"absolute_offset\":326,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":4,\"end\":12}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.test.ts\"},\"lines\":{\"text\":\"    describe(\\\"SEP-1577: Sampling with Tools\\\", () => {\\n\"},\"line_number\":325,\"absolute_offset\":11881,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":24,\"end\":32}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.test.ts\"},\"lines\":{\"text\":\"        describe(\\\"SamplingMessage\\\", () => {\\n\"},\"line_number\":553,\"absolute_offset\":20691,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":18,\"end\":26}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.test.ts\"},\"lines\":{\"text\":\"                const result = SamplingMessageSchema.safeParse(message);\\n\"},\"line_number\":560,\"absolute_offset\":20965,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":31,\"end\":39}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.test.ts\"},\"lines\":{\"text\":\"                const result = SamplingMessageSchema.safeParse(message);\\n\"},\"line_number\":573,\"absolute_offset\":21465,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":31,\"end\":39}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.test.ts\"},\"lines\":{\"text\":\"                    method: \\\"sampling/createMessage\\\",\\n\"},\"line_number\":584,\"absolute_offset\":21887,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":29,\"end\":37}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.test.ts\"},\"lines\":{\"text\":\"                    method: \\\"sampling/createMessage\\\",\\n\"},\"line_number\":602,\"absolute_offset\":22572,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":29,\"end\":37}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.test.ts\"},\"lines\":{\"text\":\"                    method: \\\"sampling/createMessage\\\",\\n\"},\"line_number\":637,\"absolute_offset\":24082,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":29,\"end\":37}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.test.ts\"},\"lines\":{\"text\":\"        describe(\\\"ClientCapabilities with sampling\\\", () => {\\n\"},\"line_number\":733,\"absolute_offset\":27866,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":42,\"end\":50}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.test.ts\"},\"lines\":{\"text\":\"            test(\\\"should validate capabilities with sampling.tools\\\", () => {\\n\"},\"line_number\":734,\"absolute_offset\":27927,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":52,\"end\":60}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.test.ts\"},\"lines\":{\"text\":\"                    sampling: {\\n\"},\"line_number\":736,\"absolute_offset\":28043,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":20,\"end\":28}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.test.ts\"},\"lines\":{\"text\":\"                    expect(result.data.sampling?.tools).toBeDefined();\\n\"},\"line_number\":744,\"absolute_offset\":28321,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":39,\"end\":47}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.test.ts\"},\"lines\":{\"text\":\"            test(\\\"should validate capabilities with sampling.context\\\", () => {\\n\"},\"line_number\":748,\"absolute_offset\":28427,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":52,\"end\":60}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.test.ts\"},\"lines\":{\"text\":\"                    sampling: {\\n\"},\"line_number\":750,\"absolute_offset\":28545,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":20,\"end\":28}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.test.ts\"},\"lines\":{\"text\":\"                    expect(result.data.sampling?.context).toBeDefined();\\n\"},\"line_number\":758,\"absolute_offset\":28825,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":39,\"end\":47}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.test.ts\"},\"lines\":{\"text\":\"                    sampling: {\\n\"},\"line_number\":764,\"absolute_offset\":29039,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":20,\"end\":28}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.test.ts\"},\"lines\":{\"text\":\"                    expect(result.data.sampling?.context).toBeDefined();\\n\"},\"line_number\":773,\"absolute_offset\":29354,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":39,\"end\":47}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.test.ts\"},\"lines\":{\"text\":\"                    expect(result.data.sampling?.tools).toBeDefined();\\n\"},\"line_number\":774,\"absolute_offset\":29427,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":39,\"end\":47}]}}\n{\"type\":\"end\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.test.ts\"},\"binary_offset\":null,\"stats\":{\"elapsed\":{\"secs\":0,\"nanos\":71500,\"human\":\"0.000072s\"},\"searches\":1,\"searches_with_match\":1,\"bytes_searched\":29556,\"bytes_printed\":5592,\"matched_lines\":18,\"matches\":18}}}\n{\"type\":\"begin\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/cli.ts\"}}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/cli.ts\"},\"lines\":{\"text\":\"        sampling: {},\\n\"},\"line_number\":24,\"absolute_offset\":801,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":8,\"end\":16}]}}\n{\"type\":\"end\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/cli.ts\"},\"binary_offset\":null,\"stats\":{\"elapsed\":{\"secs\":0,\"nanos\":50250,\"human\":\"0.000050s\"},\"searches\":1,\"searches_with_match\":1,\"bytes_searched\":4005,\"bytes_printed\":368,\"matched_lines\":1,\"matches\":1}}}\n{\"type\":\"begin\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/spec.types.test.ts\"}}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/spec.types.test.ts\"},\"lines\":{\"text\":\"  SamplingMessage: (\\n\"},\"line_number\":338,\"absolute_offset\":8815,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":2,\"end\":10}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/spec.types.test.ts\"},\"lines\":{\"text\":\"    sdk: RemovePassthrough<SDKTypes.SamplingMessage>,\\n\"},\"line_number\":339,\"absolute_offset\":8836,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":36,\"end\":44}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/spec.types.test.ts\"},\"lines\":{\"text\":\"    spec: SpecTypes.SamplingMessage\\n\"},\"line_number\":340,\"absolute_offset\":8890,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":20,\"end\":28}]}}\n{\"type\":\"end\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/spec.types.test.ts\"},\"binary_offset\":null,\"stats\":{\"elapsed\":{\"secs\":0,\"nanos\":24292,\"human\":\"0.000024s\"},\"searches\":1,\"searches_with_match\":1,\"bytes_searched\":18265,\"bytes_printed\":983,\"matched_lines\":3,\"matches\":3}}}\n{\"type\":\"begin\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/shared/protocol.test.ts\"}}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/shared/protocol.test.ts\"},\"lines\":{\"text\":\"      sampling: {},\\n\"},\"line_number\":657,\"absolute_offset\":21617,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":6,\"end\":14}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/shared/protocol.test.ts\"},\"lines\":{\"text\":\"      sampling: {},\\n\"},\"line_number\":675,\"absolute_offset\":21958,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":6,\"end\":14}]}}\n{\"type\":\"end\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/shared/protocol.test.ts\"},\"binary_offset\":null,\"stats\":{\"elapsed\":{\"secs\":0,\"nanos\":24833,\"human\":\"0.000025s\"},\"searches\":1,\"searches_with_match\":1,\"bytes_searched\":23298,\"bytes_printed\":678,\"matched_lines\":2,\"matches\":2}}}\n{\"type\":\"begin\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/tmp3/client.py\"}}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/tmp3/client.py\"},\"lines\":{\"text\":\"# Optional: create a sampling callback\\n\"},\"line_number\":26,\"absolute_offset\":543,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":21,\"end\":29}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/tmp3/client.py\"},\"lines\":{\"text\":\"async def handle_sampling_message(\\n\"},\"line_number\":27,\"absolute_offset\":582,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":17,\"end\":25}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/tmp3/client.py\"},\"lines\":{\"text\":\"            read, write, #sampling_callback=handle_sampling_message\\n\"},\"line_number\":44,\"absolute_offset\":1057,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":26,\"end\":34},{\"match\":{\"text\":\"sampling\"},\"start\":51,\"end\":59}]}}\n{\"type\":\"end\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/tmp3/client.py\"},\"binary_offset\":null,\"stats\":{\"elapsed\":{\"secs\":0,\"nanos\":21917,\"human\":\"0.000022s\"},\"searches\":1,\"searches_with_match\":1,\"bytes_searched\":1667,\"bytes_printed\":1028,\"matched_lines\":3,\"matches\":4}}}\n{\"type\":\"begin\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/client/index.ts\"}}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/client/index.ts\"},\"lines\":{\"text\":\"      case \\\"sampling/createMessage\\\":\\n\"},\"line_number\":302,\"absolute_offset\":8638,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":12,\"end\":20}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/client/index.ts\"},\"lines\":{\"text\":\"        if (!this._capabilities.sampling) {\\n\"},\"line_number\":303,\"absolute_offset\":8675,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":32,\"end\":40}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/client/index.ts\"},\"lines\":{\"text\":\"            `Client does not support sampling capability (required for ${method})`,\\n\"},\"line_number\":305,\"absolute_offset\":8746,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":37,\"end\":45}]}}\n{\"type\":\"end\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/client/index.ts\"},\"binary_offset\":null,\"stats\":{\"elapsed\":{\"secs\":0,\"nanos\":21791,\"human\":\"0.000022s\"},\"searches\":1,\"searches_with_match\":1,\"bytes_searched\":14369,\"bytes_printed\":1028,\"matched_lines\":3,\"matches\":3}}}\n{\"type\":\"begin\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/client/index.test.ts\"}}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/client/index.test.ts\"},\"lines\":{\"text\":\"        sampling: {},\\n\"},\"line_number\":59,\"absolute_offset\":1633,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":8,\"end\":16}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/client/index.test.ts\"},\"lines\":{\"text\":\"        sampling: {},\\n\"},\"line_number\":117,\"absolute_offset\":3101,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":8,\"end\":16}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/client/index.test.ts\"},\"lines\":{\"text\":\"        sampling: {},\\n\"},\"line_number\":167,\"absolute_offset\":4261,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":8,\"end\":16}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/client/index.test.ts\"},\"lines\":{\"text\":\"          sampling: {},\\n\"},\"line_number\":228,\"absolute_offset\":5600,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":10,\"end\":18}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/client/index.test.ts\"},\"lines\":{\"text\":\"          sampling: {},\\n\"},\"line_number\":294,\"absolute_offset\":7020,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":10,\"end\":18}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/client/index.test.ts\"},\"lines\":{\"text\":\"          sampling: {},\\n\"},\"line_number\":361,\"absolute_offset\":8460,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":10,\"end\":18}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/client/index.test.ts\"},\"lines\":{\"text\":\"        sampling: {},\\n\"},\"line_number\":423,\"absolute_offset\":9681,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":8,\"end\":16}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/client/index.test.ts\"},\"lines\":{\"text\":\"        sampling: {},\\n\"},\"line_number\":578,\"absolute_offset\":13424,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":8,\"end\":16}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/client/index.test.ts\"},\"lines\":{\"text\":\"  // This should work because sampling is a declared capability\\n\"},\"line_number\":583,\"absolute_offset\":13468,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":30,\"end\":38}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/client/index.test.ts\"},\"lines\":{\"text\":\"  // This should throw because sampling is not a declared capability\\n\"},\"line_number\":625,\"absolute_offset\":14526,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":31,\"end\":39}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/client/index.test.ts\"},\"lines\":{\"text\":\"  }).toThrow(\\\"Client does not support sampling capability\\\");\\n\"},\"line_number\":635,\"absolute_offset\":14818,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":38,\"end\":46}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/client/index.test.ts\"},\"lines\":{\"text\":\"        sampling: {},\\n\"},\"line_number\":691,\"absolute_offset\":16325,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":8,\"end\":16}]}}\n{\"type\":\"end\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/client/index.test.ts\"},\"binary_offset\":null,\"stats\":{\"elapsed\":{\"secs\":0,\"nanos\":32708,\"human\":\"0.000033s\"},\"searches\":1,\"searches_with_match\":1,\"bytes_searched\":31981,\"bytes_printed\":3547,\"matched_lines\":12,\"matches\":12}}}\n{\"type\":\"begin\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/backfill/backfillSampling.ts\"}}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/backfill/backfillSampling.ts\"},\"lines\":{\"text\":\"    This example implements an stdio MCP proxy that backfills sampling requests using the Claude API.\\n\"},\"line_number\":2,\"absolute_offset\":3,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":62,\"end\":70}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/backfill/backfillSampling.ts\"},\"lines\":{\"text\":\"        npx -y --silent tsx src/examples/backfill/backfillSampling.ts -- \\\\\\n\"},\"line_number\":6,\"absolute_offset\":168,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":58,\"end\":66}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/backfill/backfillSampling.ts\"},\"lines\":{\"text\":\"            sampling_models: Array.from(models),\\n\"},\"line_number\":184,\"absolute_offset\":6133,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":12,\"end\":20}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/backfill/backfillSampling.ts\"},\"lines\":{\"text\":\"            sampling_default_model: defaultModel,\\n\"},\"line_number\":185,\"absolute_offset\":6182,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":12,\"end\":20}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/backfill/backfillSampling.ts\"},\"lines\":{\"text\":\"                if (hint.name !== undefined && backfillMeta.sampling_models.includes(hint.name)) {\\n\"},\"line_number\":192,\"absolute_offset\":6465,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":60,\"end\":68}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/backfill/backfillSampling.ts\"},\"lines\":{\"text\":\"        return backfillMeta.sampling_default_model!;\\n\"},\"line_number\":198,\"absolute_offset\":6778,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":28,\"end\":36}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/backfill/backfillSampling.ts\"},\"lines\":{\"text\":\"    let clientSupportsSampling: boolean | undefined;\\n\"},\"line_number\":201,\"absolute_offset\":6838,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":22,\"end\":30}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/backfill/backfillSampling.ts\"},\"lines\":{\"text\":\"                    if (!(clientSupportsSampling = !!message.params.capabilities.sampling)) {\\n\"},\"line_number\":220,\"absolute_offset\":7667,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":40,\"end\":48},{\"match\":{\"text\":\"sampling\"},\"start\":81,\"end\":89}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/backfill/backfillSampling.ts\"},\"lines\":{\"text\":\"                        message.params.capabilities.sampling = {}\\n\"},\"line_number\":221,\"absolute_offset\":7761,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":52,\"end\":60}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/backfill/backfillSampling.ts\"},\"lines\":{\"text\":\"                } else if (isCreateMessageRequest(message)) {// && !clientSupportsSampling) {\\n\"},\"line_number\":224,\"absolute_offset\":7948,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":82,\"end\":90}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/backfill/backfillSampling.ts\"},\"lines\":{\"text\":\"                        sendInternalError(\\\"includeContext != none not supported by MCP sampling backfill\\\");\\n\"},\"line_number\":226,\"absolute_offset\":8122,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":87,\"end\":95}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/backfill/backfillSampling.ts\"},\"lines\":{\"text\":\"                    if (!clientSupportsSampling) {\\n\"},\"line_number\":277,\"absolute_offset\":11064,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":39,\"end\":47}]}}\n{\"type\":\"end\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/backfill/backfillSampling.ts\"},\"binary_offset\":null,\"stats\":{\"elapsed\":{\"secs\":0,\"nanos\":35125,\"human\":\"0.000035s\"},\"searches\":1,\"searches_with_match\":1,\"bytes_searched\":12972,\"bytes_printed\":4310,\"matched_lines\":12,\"matches\":13}}}\n{\"type\":\"begin\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/server/index.ts\"}}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/server/index.ts\"},\"lines\":{\"text\":\"      case \\\"sampling/createMessage\\\":\\n\"},\"line_number\":160,\"absolute_offset\":4926,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":12,\"end\":20}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/server/index.ts\"},\"lines\":{\"text\":\"        if (!this._clientCapabilities?.sampling) {\\n\"},\"line_number\":161,\"absolute_offset\":4963,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":39,\"end\":47}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/server/index.ts\"},\"lines\":{\"text\":\"            `Client does not support sampling (required for ${method})`,\\n\"},\"line_number\":163,\"absolute_offset\":5041,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":37,\"end\":45}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/server/index.ts\"},\"lines\":{\"text\":\"      case \\\"sampling/createMessage\\\":\\n\"},\"line_number\":239,\"absolute_offset\":7199,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":12,\"end\":20}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/server/index.ts\"},\"lines\":{\"text\":\"        if (!this._capabilities.sampling) {\\n\"},\"line_number\":240,\"absolute_offset\":7236,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":32,\"end\":40}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/server/index.ts\"},\"lines\":{\"text\":\"            `Server does not support sampling (required for ${method})`,\\n\"},\"line_number\":242,\"absolute_offset\":7307,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":37,\"end\":45}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/server/index.ts\"},\"lines\":{\"text\":\"      { method: \\\"sampling/createMessage\\\", params },\\n\"},\"line_number\":337,\"absolute_offset\":9859,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":17,\"end\":25}]}}\n{\"type\":\"end\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/server/index.ts\"},\"binary_offset\":null,\"stats\":{\"elapsed\":{\"secs\":0,\"nanos\":32917,\"human\":\"0.000033s\"},\"searches\":1,\"searches_with_match\":1,\"bytes_searched\":12402,\"bytes_printed\":2222,\"matched_lines\":7,\"matches\":7}}}\n{\"type\":\"begin\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"}}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"     * Present if the client supports sampling from an LLM.\\n\"},\"line_number\":286,\"absolute_offset\":8610,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":38,\"end\":46}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"    sampling: z.optional(\\n\"},\"line_number\":288,\"absolute_offset\":8678,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":4,\"end\":12}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"           * Present if the client supports tools and tool_choice parameters in sampling requests.\\n\"},\"line_number\":297,\"absolute_offset\":9009,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":80,\"end\":88}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"/* Sampling */\\n\"},\"line_number\":1183,\"absolute_offset\":36712,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":3,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\" * The server's preferences for model selection, requested of the client during sampling.\\n\"},\"line_number\":1197,\"absolute_offset\":36926,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":80,\"end\":88}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"     * How much to prioritize sampling speed (latency) when selecting a model.\\n\"},\"line_number\":1210,\"absolute_offset\":37326,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":30,\"end\":38}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\" * Controls tool usage behavior in sampling requests.\\n\"},\"line_number\":1221,\"absolute_offset\":37662,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":35,\"end\":43}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\" * A message from the user (server) in a sampling conversation.\\n\"},\"line_number\":1248,\"absolute_offset\":38409,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":41,\"end\":49}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\" * A message from the assistant (LLM) in a sampling conversation.\\n\"},\"line_number\":1270,\"absolute_offset\":39132,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":43,\"end\":51}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export const SamplingMessageSchema = z.discriminatedUnion(\\\"role\\\", [\\n\"},\"line_number\":1289,\"absolute_offset\":39903,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":13,\"end\":21}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\" * A request from the server to sample an LLM via the client. The client has full discretion over which model to select. The client should also inform the user before beginning sampling, to allow them to inspect the request (human in the loop) and decide whether to approve it.\\n\"},\"line_number\":1295,\"absolute_offset\":40027,\"submatches\":[{\"match\":{\"text\":\"sample\"},\"start\":32,\"end\":38},{\"match\":{\"text\":\"sampling\"},\"start\":177,\"end\":185}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"  method: z.literal(\\\"sampling/createMessage\\\"),\\n\"},\"line_number\":1298,\"absolute_offset\":40374,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":21,\"end\":29}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"    messages: z.array(SamplingMessageSchema),\\n\"},\"line_number\":1300,\"absolute_offset\":40464,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":22,\"end\":30}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"     * An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt.\\n\"},\"line_number\":1302,\"absolute_offset\":40518,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":61,\"end\":69}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"     * Requires clientCapabilities.sampling.context.\\n\"},\"line_number\":1308,\"absolute_offset\":40898,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":35,\"end\":43}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"     * The maximum number of tokens to sample, as requested by the server. The client MAY choose to sample fewer tokens than requested.\\n\"},\"line_number\":1313,\"absolute_offset\":41086,\"submatches\":[{\"match\":{\"text\":\"sample\"},\"start\":39,\"end\":45},{\"match\":{\"text\":\"sample\"},\"start\":100,\"end\":106}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"     * Requires clientCapabilities.sampling.tools.\\n\"},\"line_number\":1327,\"absolute_offset\":41682,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":35,\"end\":43}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"     * Requires clientCapabilities.sampling.tools and tools parameter.\\n\"},\"line_number\":1332,\"absolute_offset\":41830,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":35,\"end\":43}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\" * The client's response to a sampling/create_message request from the server. The client should inform the user before returning the sampled message, to allow them to inspect the response (human in the loop) and decide whether to allow the server to see it.\\n\"},\"line_number\":1339,\"absolute_offset\":41970,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":30,\"end\":38},{\"match\":{\"text\":\"sample\"},\"start\":134,\"end\":140}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"   * The reason why sampling stopped.\\n\"},\"line_number\":1347,\"absolute_offset\":42390,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":20,\"end\":28}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"/* Sampling */\\n\"},\"line_number\":1812,\"absolute_offset\":56922,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":3,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type SamplingMessage = Infer<typeof SamplingMessageSchema>;\\n\"},\"line_number\":1816,\"absolute_offset\":57122,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":12,\"end\":20},{\"match\":{\"text\":\"Sampling\"},\"start\":43,\"end\":51}]}}\n{\"type\":\"end\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"binary_offset\":null,\"stats\":{\"elapsed\":{\"secs\":0,\"nanos\":55917,\"human\":\"0.000056s\"},\"searches\":1,\"searches_with_match\":1,\"bytes_searched\":59122,\"bytes_printed\":7426,\"matched_lines\":22,\"matches\":26}}}\n{\"type\":\"begin\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/server/index.test.ts\"}}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/server/index.test.ts\"},\"lines\":{\"text\":\"        sampling: {},\\n\"},\"line_number\":232,\"absolute_offset\":5601,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":8,\"end\":16}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/server/index.test.ts\"},\"lines\":{\"text\":\"  // Implement request handler for sampling/createMessage\\n\"},\"line_number\":237,\"absolute_offset\":5645,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":35,\"end\":43}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/server/index.test.ts\"},\"lines\":{\"text\":\"  expect(server.getClientCapabilities()).toEqual({ sampling: {} });\\n\"},\"line_number\":258,\"absolute_offset\":6182,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":51,\"end\":59}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/server/index.test.ts\"},\"lines\":{\"text\":\"  // This should work because sampling is supported by the client\\n\"},\"line_number\":260,\"absolute_offset\":6251,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":30,\"end\":38}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/server/index.test.ts\"},\"lines\":{\"text\":\"  // This should still throw because sampling is not supported by the client\\n\"},\"line_number\":348,\"absolute_offset\":8296,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":37,\"end\":45}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/server/index.test.ts\"},\"lines\":{\"text\":\"        sampling: {},\\n\"},\"line_number\":736,\"absolute_offset\":17082,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":8,\"end\":16}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/server/index.test.ts\"},\"lines\":{\"text\":\"        sampling: {},\\n\"},\"line_number\":748,\"absolute_offset\":17245,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":8,\"end\":16}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/server/index.test.ts\"},\"lines\":{\"text\":\"        sampling: {},\\n\"},\"line_number\":804,\"absolute_offset\":18467,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":8,\"end\":16}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/server/index.test.ts\"},\"lines\":{\"text\":\"        sampling: {},\\n\"},\"line_number\":817,\"absolute_offset\":18671,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":8,\"end\":16}]}}\n{\"type\":\"end\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/server/index.test.ts\"},\"binary_offset\":null,\"stats\":{\"elapsed\":{\"secs\":0,\"nanos\":23542,\"human\":\"0.000024s\"},\"searches\":1,\"searches_with_match\":1,\"bytes_searched\":23829,\"bytes_printed\":2771,\"matched_lines\":9,\"matches\":9}}}\n{\"type\":\"begin\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.ts\"}}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.ts\"},\"lines\":{\"text\":\"  This example demonstrates a tool loop using MCP sampling with locally defined tools.\\n\"},\"line_number\":2,\"absolute_offset\":3,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":50,\"end\":58}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.ts\"},\"lines\":{\"text\":\"      npx -y --silent tsx src/examples/backfill/backfillSampling.ts -- \\\\\\n\"},\"line_number\":9,\"absolute_offset\":298,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":56,\"end\":64}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.ts\"},\"lines\":{\"text\":\"        npx -y --silent tsx src/examples/server/toolLoopSampling.ts\\n\"},\"line_number\":10,\"absolute_offset\":371,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":56,\"end\":64}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.ts\"},\"lines\":{\"text\":\"  SamplingMessage,\\n\"},\"line_number\":23,\"absolute_offset\":873,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":2,\"end\":10}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.ts\"},\"lines\":{\"text\":\" * Defines the local tools available to the LLM during sampling.\\n\"},\"line_number\":189,\"absolute_offset\":5332,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":55,\"end\":63}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.ts\"},\"lines\":{\"text\":\" * Runs a tool loop using sampling.\\n\"},\"line_number\":277,\"absolute_offset\":7975,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":26,\"end\":34}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.ts\"},\"lines\":{\"text\":\"): Promise<{ answer: string; transcript: SamplingMessage[]; usage: AggregatedUsage }> {\\n\"},\"line_number\":283,\"absolute_offset\":8139,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":41,\"end\":49}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.ts\"},\"lines\":{\"text\":\"  const messages: SamplingMessage[] = [\\n\"},\"line_number\":284,\"absolute_offset\":8227,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":18,\"end\":26}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.ts\"},\"lines\":{\"text\":\"    // SamplingMessage now supports arrays of content\\n\"},\"line_number\":340,\"absolute_offset\":10385,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":7,\"end\":15}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.ts\"},\"lines\":{\"text\":\"  name: \\\"tool-loop-sampling-server\\\",\\n\"},\"line_number\":405,\"absolute_offset\":12821,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":19,\"end\":27}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.ts\"},\"lines\":{\"text\":\"// Register the localResearch tool that uses sampling with a tool loop\\n\"},\"line_number\":409,\"absolute_offset\":12883,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":42,\"end\":50}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.ts\"},\"lines\":{\"text\":\"  console.error(\\\"MCP Tool Loop Sampling Server is running...\\\");\\n\"},\"line_number\":478,\"absolute_offset\":15008,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":31,\"end\":39}]}}\n{\"type\":\"end\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.ts\"},\"binary_offset\":null,\"stats\":{\"elapsed\":{\"secs\":0,\"nanos\":34375,\"human\":\"0.000034s\"},\"searches\":1,\"searches_with_match\":1,\"bytes_searched\":15211,\"bytes_printed\":4038,\"matched_lines\":12,\"matches\":12}}}\n{\"type\":\"begin\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"}}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\" * Tests for toolLoopSampling.ts\\n\"},\"line_number\":2,\"absolute_offset\":4,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":21,\"end\":29}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"  SamplingMessage,\\n\"},\"line_number\":15,\"absolute_offset\":404,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":2,\"end\":10}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"describe(\\\"toolLoopSampling server\\\", () => {\\n\"},\"line_number\":19,\"absolute_offset\":486,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":18,\"end\":26}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"    // Create client with sampling capability\\n\"},\"line_number\":26,\"absolute_offset\":683,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":26,\"end\":34}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"          sampling: {\\n\"},\"line_number\":34,\"absolute_offset\":858,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":10,\"end\":18}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"            tools: {}, // Indicate we support tool calling in sampling\\n\"},\"line_number\":35,\"absolute_offset\":880,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":62,\"end\":70}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"    // Create transport that spawns the toolLoopSampling server\\n\"},\"line_number\":41,\"absolute_offset\":991,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":48,\"end\":56}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"        resolve(__dirname, \\\"toolLoopSampling.ts\\\"),\\n\"},\"line_number\":48,\"absolute_offset\":1183,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":36,\"end\":44}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"    // Track sampling request count to simulate different LLM responses\\n\"},\"line_number\":58,\"absolute_offset\":1392,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":13,\"end\":21}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"    let samplingCallCount = 0;\\n\"},\"line_number\":59,\"absolute_offset\":1464,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":8,\"end\":16}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"    // Set up sampling handler that simulates an LLM\\n\"},\"line_number\":61,\"absolute_offset\":1496,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":14,\"end\":22}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"        samplingCallCount++;\\n\"},\"line_number\":65,\"absolute_offset\":1670,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":8,\"end\":16}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"          `[test] Sampling call ${samplingCallCount}, messages: ${messages.length}, last message type: ${lastContent.type}`\\n\"},\"line_number\":76,\"absolute_offset\":2099,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":18,\"end\":26},{\"match\":{\"text\":\"sampling\"},\"start\":34,\"end\":42}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"        if (samplingCallCount === 1) {\\n\"},\"line_number\":80,\"absolute_offset\":2286,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":12,\"end\":20}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"        if (samplingCallCount === 2) {\\n\"},\"line_number\":98,\"absolute_offset\":2802,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":12,\"end\":20}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"        if (samplingCallCount === 3) {\\n\"},\"line_number\":118,\"absolute_offset\":3380,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":12,\"end\":20}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"          `Unexpected sampling call count: ${samplingCallCount}`\\n\"},\"line_number\":135,\"absolute_offset\":3898,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":22,\"end\":30},{\"match\":{\"text\":\"sampling\"},\"start\":45,\"end\":53}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"    // Verify we made exactly 3 sampling calls (tool loop worked correctly)\\n\"},\"line_number\":167,\"absolute_offset\":4695,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":32,\"end\":40}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"    expect(samplingCallCount).toBe(3);\\n\"},\"line_number\":168,\"absolute_offset\":4771,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":11,\"end\":19}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"    let samplingCallCount = 0;\\n\"},\"line_number\":172,\"absolute_offset\":4880,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":8,\"end\":16}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"    // Set up sampling handler that requests an invalid path\\n\"},\"line_number\":174,\"absolute_offset\":4912,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":14,\"end\":22}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"        samplingCallCount++;\\n\"},\"line_number\":178,\"absolute_offset\":5094,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":8,\"end\":16}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"        if (samplingCallCount === 1) {\\n\"},\"line_number\":184,\"absolute_offset\":5307,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":12,\"end\":20}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"        if (samplingCallCount === 2) {\\n\"},\"line_number\":202,\"absolute_offset\":5832,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":12,\"end\":20}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"          `Unexpected sampling call count: ${samplingCallCount}`\\n\"},\"line_number\":232,\"absolute_offset\":6931,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":22,\"end\":30},{\"match\":{\"text\":\"sampling\"},\"start\":45,\"end\":53}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"    let samplingCallCount = 0;\\n\"},\"line_number\":260,\"absolute_offset\":7640,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":8,\"end\":16}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"    // Set up sampling handler that requests an unknown tool\\n\"},\"line_number\":262,\"absolute_offset\":7672,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":14,\"end\":22}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"        samplingCallCount++;\\n\"},\"line_number\":266,\"absolute_offset\":7854,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":8,\"end\":16}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"        if (samplingCallCount === 1) {\\n\"},\"line_number\":272,\"absolute_offset\":8050,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":12,\"end\":20}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"        if (samplingCallCount === 2) {\\n\"},\"line_number\":289,\"absolute_offset\":8512,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":12,\"end\":20}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"          `Unexpected sampling call count: ${samplingCallCount}`\\n\"},\"line_number\":317,\"absolute_offset\":9451,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":22,\"end\":30},{\"match\":{\"text\":\"sampling\"},\"start\":45,\"end\":53}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"    expect(samplingCallCount).toBe(2);\\n\"},\"line_number\":338,\"absolute_offset\":9880,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":11,\"end\":19}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"    let samplingCallCount = 0;\\n\"},\"line_number\":342,\"absolute_offset\":9986,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":8,\"end\":16}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"    // Set up sampling handler that sends malformed input\\n\"},\"line_number\":344,\"absolute_offset\":10018,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":14,\"end\":22}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"        samplingCallCount++;\\n\"},\"line_number\":348,\"absolute_offset\":10197,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":8,\"end\":16}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"        if (samplingCallCount === 1) {\\n\"},\"line_number\":354,\"absolute_offset\":10405,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":12,\"end\":20}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"        if (samplingCallCount === 2) {\\n\"},\"line_number\":372,\"absolute_offset\":10922,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":12,\"end\":20}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"          `Unexpected sampling call count: ${samplingCallCount}`\\n\"},\"line_number\":401,\"absolute_offset\":11911,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":22,\"end\":30},{\"match\":{\"text\":\"sampling\"},\"start\":45,\"end\":53}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"    expect(samplingCallCount).toBe(2);\\n\"},\"line_number\":422,\"absolute_offset\":12344,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":11,\"end\":19}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"    let samplingCallCount = 0;\\n\"},\"line_number\":426,\"absolute_offset\":12453,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":8,\"end\":16}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"    // Set up sampling handler that keeps requesting tools indefinitely\\n\"},\"line_number\":428,\"absolute_offset\":12485,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":14,\"end\":22}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"        samplingCallCount++;\\n\"},\"line_number\":432,\"absolute_offset\":12678,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":8,\"end\":16}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"            id: `call_${samplingCallCount}`,\\n\"},\"line_number\":440,\"absolute_offset\":12893,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":24,\"end\":32}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"    // Verify we hit the iteration limit (10 iterations as defined in toolLoopSampling.ts)\\n\"},\"line_number\":478,\"absolute_offset\":13902,\"submatches\":[{\"match\":{\"text\":\"Sampling\"},\"start\":78,\"end\":86}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"lines\":{\"text\":\"    expect(samplingCallCount).toBe(10);\\n\"},\"line_number\":479,\"absolute_offset\":13993,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":11,\"end\":19}]}}\n{\"type\":\"end\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolLoopSampling.test.ts\"},\"binary_offset\":null,\"stats\":{\"elapsed\":{\"secs\":0,\"nanos\":56291,\"human\":\"0.000056s\"},\"searches\":1,\"searches_with_match\":1,\"bytes_searched\":14043,\"bytes_printed\":14746,\"matched_lines\":45,\"matches\":50}}}\n{\"type\":\"begin\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolWithSampleServer.ts\"}}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolWithSampleServer.ts\"},\"lines\":{\"text\":\"// Run with: npx tsx src/examples/server/toolWithSampleServer.ts\\n\"},\"line_number\":2,\"absolute_offset\":1,\"submatches\":[{\"match\":{\"text\":\"Sample\"},\"start\":49,\"end\":55}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolWithSampleServer.ts\"},\"lines\":{\"text\":\"  name: \\\"tools-with-sample-server\\\",\\n\"},\"line_number\":9,\"absolute_offset\":238,\"submatches\":[{\"match\":{\"text\":\"sample\"},\"start\":20,\"end\":26}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolWithSampleServer.ts\"},\"lines\":{\"text\":\"// Tool that uses LLM sampling to summarize any text\\n\"},\"line_number\":13,\"absolute_offset\":299,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":22,\"end\":30}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolWithSampleServer.ts\"},\"lines\":{\"text\":\"    // Call the LLM through MCP sampling\\n\"},\"line_number\":23,\"absolute_offset\":556,\"submatches\":[{\"match\":{\"text\":\"sampling\"},\"start\":32,\"end\":40}]}}\n{\"type\":\"end\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/examples/server/toolWithSampleServer.ts\"},\"binary_offset\":null,\"stats\":{\"elapsed\":{\"secs\":0,\"nanos\":22166,\"human\":\"0.000022s\"},\"searches\":1,\"searches_with_match\":1,\"bytes_searched\":1637,\"bytes_printed\":1409,\"matched_lines\":4,\"matches\":4}}}\n{\"data\":{\"elapsed_total\":{\"human\":\"0.008650s\",\"nanos\":8650042,\"secs\":0},\"stats\":{\"bytes_printed\":51984,\"bytes_searched\":300525,\"elapsed\":{\"human\":\"0.000581s\",\"nanos\":580624,\"secs\":0},\"matched_lines\":159,\"matches\":171,\"searches\":15,\"searches_with_match\":15}},\"type\":\"summary\"}\n"
        }
      }
    ]
  },
  {
    "role": "assistant",
    "content": [
      {
        "type": "text",
        "text": "\n\nNow let me read the main types.ts file to get more details on the sampling-related types:"
      },
      {
        "type": "tool_use",
        "name": "read",
        "id": "toolu_01Syjo5Fa9qUNRcFAR5mESYm",
        "input": {
          "path": "src/types.ts",
          "startLineInclusive": 1183,
          "endLineInclusive": 1400
        }
      }
    ]
  },
  {
    "role": "user",
    "content": [
      {
        "type": "tool_result",
        "toolUseId": "toolu_01Syjo5Fa9qUNRcFAR5mESYm",
        "content": {
          "content": "1183: /* Sampling */\n1184: /**\n1185:  * Hints to use for model selection.\n1186:  */\n1187: export const ModelHintSchema = z\n1188:   .object({\n1189:     /**\n1190:      * A hint for a model name.\n1191:      */\n1192:     name: z.string().optional(),\n1193:   })\n1194:   .passthrough();\n1195: \n1196: /**\n1197:  * The server's preferences for model selection, requested of the client during sampling.\n1198:  */\n1199: export const ModelPreferencesSchema = z\n1200:   .object({\n1201:     /**\n1202:      * Optional hints to use for model selection.\n1203:      */\n1204:     hints: z.optional(z.array(ModelHintSchema)),\n1205:     /**\n1206:      * How much to prioritize cost when selecting a model.\n1207:      */\n1208:     costPriority: z.optional(z.number().min(0).max(1)),\n1209:     /**\n1210:      * How much to prioritize sampling speed (latency) when selecting a model.\n1211:      */\n1212:     speedPriority: z.optional(z.number().min(0).max(1)),\n1213:     /**\n1214:      * How much to prioritize intelligence and capabilities when selecting a model.\n1215:      */\n1216:     intelligencePriority: z.optional(z.number().min(0).max(1)),\n1217:   })\n1218:   .passthrough();\n1219: \n1220: /**\n1221:  * Controls tool usage behavior in sampling requests.\n1222:  */\n1223: export const ToolChoiceSchema = z\n1224:   .object({\n1225:     /**\n1226:      * Controls when tools are used:\n1227:      * - \"auto\": Model decides whether to use tools (default)\n1228:      * - \"required\": Model MUST use at least one tool before completing\n1229:      */\n1230:     mode: z.optional(z.enum([\"auto\", \"required\", \"none\"])),\n1231:     /**\n1232:      * If true, model should not use multiple tools in parallel.\n1233:      * Some models may ignore this hint.\n1234:      * Default: false\n1235:      */\n1236:     disable_parallel_tool_use: z.optional(z.boolean()),\n1237:   })\n1238:   .passthrough();\n1239: \n1240: export const UserMessageContentSchema = z.discriminatedUnion(\"type\", [\n1241:   TextContentSchema,\n1242:   ImageContentSchema,\n1243:   AudioContentSchema,\n1244:   ToolResultContentSchema,\n1245: ]);\n1246: \n1247: /**\n1248:  * A message from the user (server) in a sampling conversation.\n1249:  */\n1250: export const UserMessageSchema = z\n1251:   .object({\n1252:     role: z.literal(\"user\"),\n1253:     content: z.union([UserMessageContentSchema, z.array(UserMessageContentSchema)]),\n1254:     /**\n1255:      * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)\n1256:      * for notes on _meta usage.\n1257:      */\n1258:     _meta: z.optional(z.object({}).passthrough()),\n1259:   })\n1260:   .passthrough();\n1261: \n1262: export const AssistantMessageContentSchema = z.discriminatedUnion(\"type\", [\n1263:   TextContentSchema,\n1264:   ImageContentSchema,\n1265:   AudioContentSchema,\n1266:   ToolCallContentSchema,\n1267: ]);\n1268: \n1269: /**\n1270:  * A message from the assistant (LLM) in a sampling conversation.\n1271:  */\n1272: export const AssistantMessageSchema = z\n1273:   .object({\n1274:     role: z.literal(\"assistant\"),\n1275:     content: z.union([AssistantMessageContentSchema, z.array(AssistantMessageContentSchema)]),\n1276:     /**\n1277:      * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)\n1278:      * for notes on _meta usage.\n1279:      */\n1280:     _meta: z.optional(z.object({}).passthrough()),\n1281:   })\n1282:   .passthrough();\n1283: \n1284: /**\n1285:  * Describes a message issued to or received from an LLM API.\n1286:  * This is a discriminated union of UserMessage and AssistantMessage, where\n1287:  * each role has its own set of allowed content types.\n1288:  */\n1289: export const SamplingMessageSchema = z.discriminatedUnion(\"role\", [\n1290:   UserMessageSchema,\n1291:   AssistantMessageSchema,\n1292: ]);\n1293: \n1294: /**\n1295:  * A request from the server to sample an LLM via the client. The client has full discretion over which model to select. The client should also inform the user before beginning sampling, to allow them to inspect the request (human in the loop) and decide whether to approve it.\n1296:  */\n1297: export const CreateMessageRequestSchema = RequestSchema.extend({\n1298:   method: z.literal(\"sampling/createMessage\"),\n1299:   params: BaseRequestParamsSchema.extend({\n1300:     messages: z.array(SamplingMessageSchema),\n1301:     /**\n1302:      * An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt.\n1303:      */\n1304:     systemPrompt: z.optional(z.string()),\n1305:     /**\n1306:      * SOFT-DEPRECATED: Use tools parameter instead.\n1307:      * A request to include context from one or more MCP servers (including the caller), to be attached to the prompt. The client MAY ignore this request.\n1308:      * Requires clientCapabilities.sampling.context.\n1309:      */\n1310:     includeContext: z.optional(z.enum([\"none\", \"thisServer\", \"allServers\"])),\n1311:     temperature: z.optional(z.number()),\n1312:     /**\n1313:      * The maximum number of tokens to sample, as requested by the server. The client MAY choose to sample fewer tokens than requested.\n1314:      */\n1315:     maxTokens: z.number().int(),\n1316:     stopSequences: z.optional(z.array(z.string())),\n1317:     /**\n1318:      * Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.\n1319:      */\n1320:     metadata: z.optional(z.object({}).passthrough()),\n1321:     /**\n1322:      * The server's preferences for which model to select.\n1323:      */\n1324:     modelPreferences: z.optional(ModelPreferencesSchema),\n1325:     /**\n1326:      * Tool definitions for the LLM to use.\n1327:      * Requires clientCapabilities.sampling.tools.\n1328:      */\n1329:     tools: z.optional(z.array(ToolSchema)),\n1330:     /**\n1331:      * Controls tool usage behavior.\n1332:      * Requires clientCapabilities.sampling.tools and tools parameter.\n1333:      */\n1334:     toolChoice: z.optional(ToolChoiceSchema),\n1335:   }),\n1336: });\n1337: \n1338: /**\n1339:  * The client's response to a sampling/create_message request from the server. The client should inform the user before returning the sampled message, to allow them to inspect the response (human in the loop) and decide whether to allow the server to see it.\n1340:  */\n1341: export const CreateMessageResultSchema = ResultSchema.extend({\n1342:   /**\n1343:    * The name of the model that generated the message.\n1344:    */\n1345:   model: z.string(),\n1346:   /**\n1347:    * The reason why sampling stopped.\n1348:    * - \"endTurn\": Model completed naturally\n1349:    * - \"stopSequence\": Hit a stop sequence\n1350:    * - \"maxTokens\": Reached token limit\n1351:    * - \"toolUse\": Model wants to use a tool\n1352:    * - \"refusal\": Model refused the request\n1353:    * - \"other\": Other provider-specific reason\n1354:    */\n1355:   stopReason: z.optional(\n1356:     z.enum([\"endTurn\", \"stopSequence\", \"maxTokens\", \"toolUse\"]).or(z.string()),\n1357:   ),\n1358:   /**\n1359:    * The role is always \"assistant\" in responses from the LLM.\n1360:    */\n1361:   role: z.literal(\"assistant\"),\n1362:   /**\n1363:    * Response content. May be ToolCallContent if stopReason is \"toolUse\".\n1364:    */\n1365:   content: z.union([AssistantMessageContentSchema, z.array(AssistantMessageContentSchema)]),\n1366: });\n1367: \n1368: /* Elicitation */\n1369: /**\n1370:  * Primitive schema definition for boolean fields.\n1371:  */\n1372: export const BooleanSchemaSchema = z\n1373:   .object({\n1374:     type: z.literal(\"boolean\"),\n1375:     title: z.optional(z.string()),\n1376:     description: z.optional(z.string()),\n1377:     default: z.optional(z.boolean()),\n1378:   })\n1379:   .passthrough();\n1380: \n1381: /**\n1382:  * Primitive schema definition for string fields.\n1383:  */\n1384: export const StringSchemaSchema = z\n1385:   .object({\n1386:     type: z.literal(\"string\"),\n1387:     title: z.optional(z.string()),\n1388:     description: z.optional(z.string()),\n1389:     minLength: z.optional(z.number()),\n1390:     maxLength: z.optional(z.number()),\n1391:     format: z.optional(z.enum([\"email\", \"uri\", \"date\", \"date-time\"])),\n1392:   })\n1393:   .passthrough();\n1394: \n1395: /**\n1396:  * Primitive schema definition for number fields.\n1397:  */\n1398: export const NumberSchemaSchema = z\n1399:   .object({\n1400:     type: z.enum([\"number\", \"integer\"]),"
        }
      }
    ]
  },
  {
    "role": "assistant",
    "content": [
      {
        "type": "text",
        "text": "\n\nLet me also look at the client capabilities related to sampling:"
      },
      {
        "type": "tool_use",
        "name": "read",
        "id": "toolu_01LkryASvDpyTX2Cr9pWnmKJ",
        "input": {
          "path": "src/types.ts",
          "startLineInclusive": 280,
          "endLineInclusive": 330
        }
      }
    ]
  },
  {
    "role": "user",
    "content": [
      {
        "type": "tool_result",
        "toolUseId": "toolu_01LkryASvDpyTX2Cr9pWnmKJ",
        "content": {
          "content": "280:   .object({\n281:     /**\n282:      * Experimental, non-standard capabilities that the client supports.\n283:      */\n284:     experimental: z.optional(z.object({}).passthrough()),\n285:     /**\n286:      * Present if the client supports sampling from an LLM.\n287:      */\n288:     sampling: z.optional(\n289:       z\n290:         .object({\n291:           /**\n292:            * Present if the client supports non-'none' values for includeContext parameter.\n293:            * SOFT-DEPRECATED: New implementations should use tools parameter instead.\n294:            */\n295:           context: z.optional(z.object({}).passthrough()),\n296:           /**\n297:            * Present if the client supports tools and tool_choice parameters in sampling requests.\n298:            * Presence indicates full tool calling support.\n299:            */\n300:           tools: z.optional(z.object({}).passthrough()),\n301:         })\n302:         .passthrough(),\n303:     ),\n304:     /**\n305:      * Present if the client supports eliciting user input.\n306:      */\n307:     elicitation: z.optional(z.object({}).passthrough()),\n308:     /**\n309:      * Present if the client supports listing roots.\n310:      */\n311:     roots: z.optional(\n312:       z\n313:         .object({\n314:           /**\n315:            * Whether the client supports issuing notifications for changes to the roots list.\n316:            */\n317:           listChanged: z.optional(z.boolean()),\n318:         })\n319:         .passthrough(),\n320:     ),\n321:   })\n322:   .passthrough();\n323: \n324: /**\n325:  * This request is sent from the client to the server when it first connects, asking it to begin initialization.\n326:  */\n327: export const InitializeRequestSchema = RequestSchema.extend({\n328:   method: z.literal(\"initialize\"),\n329:   params: BaseRequestParamsSchema.extend({\n330:     /**"
        }
      }
    ]
  },
  {
    "role": "assistant",
    "content": [
      {
        "type": "text",
        "text": "\n\nNow let me check the server/index.ts file to see how sampling is implemented:"
      },
      {
        "type": "tool_use",
        "name": "read",
        "id": "toolu_01ShhFoHa7EStEVwbxg2fbaS",
        "input": {
          "path": "src/server/index.ts",
          "startLineInclusive": 330,
          "endLineInclusive": 350
        }
      }
    ]
  },
  {
    "role": "user",
    "content": [
      {
        "type": "tool_result",
        "toolUseId": "toolu_01ShhFoHa7EStEVwbxg2fbaS",
        "content": {
          "content": "330:   }\n331: \n332:   async createMessage(\n333:     params: CreateMessageRequest[\"params\"],\n334:     options?: RequestOptions,\n335:   ) {\n336:     return this.request(\n337:       { method: \"sampling/createMessage\", params },\n338:       CreateMessageResultSchema,\n339:       options,\n340:     );\n341:   }\n342: \n343:   async elicitInput(\n344:     params: ElicitRequest[\"params\"],\n345:     options?: RequestOptions,\n346:   ): Promise<ElicitResult> {\n347:     const result = await this.request(\n348:       { method: \"elicitation/create\", params },\n349:       ElicitResultSchema,\n350:       options,"
        }
      }
    ]
  },
  {
    "role": "assistant",
    "content": [
      {
        "type": "text",
        "text": "\n\nLet me look at the exported types to get a complete picture:"
      },
      {
        "type": "tool_use",
        "name": "read",
        "id": "toolu_01Xt1YzRsSPb31DoQ4M1u4kg",
        "input": {
          "path": "src/types.ts",
          "startLineInclusive": 1812,
          "endLineInclusive": 1830
        }
      }
    ]
  },
  {
    "role": "user",
    "content": [
      {
        "type": "tool_result",
        "toolUseId": "toolu_01Xt1YzRsSPb31DoQ4M1u4kg",
        "content": {
          "content": "1812: /* Sampling */\n1813: export type ToolChoice = Infer<typeof ToolChoiceSchema>;\n1814: export type UserMessage = Infer<typeof UserMessageSchema>;\n1815: export type AssistantMessage = Infer<typeof AssistantMessageSchema>;\n1816: export type SamplingMessage = Infer<typeof SamplingMessageSchema>;\n1817: export type CreateMessageRequest = Infer<typeof CreateMessageRequestSchema>;\n1818: export type CreateMessageResult = Infer<typeof CreateMessageResultSchema>;\n1819: export type AssistantMessageContent = Infer<typeof AssistantMessageContentSchema>;\n1820: export type UserMessageContent = Infer<typeof UserMessageContentSchema>;\n1821: \n1822: /* Elicitation */\n1823: export type BooleanSchema = Infer<typeof BooleanSchemaSchema>;\n1824: export type StringSchema = Infer<typeof StringSchemaSchema>;\n1825: export type NumberSchema = Infer<typeof NumberSchemaSchema>;\n1826: export type EnumSchema = Infer<typeof EnumSchemaSchema>;\n1827: export type PrimitiveSchemaDefinition = Infer<typeof PrimitiveSchemaDefinitionSchema>;\n1828: export type ElicitRequest = Infer<typeof ElicitRequestSchema>;\n1829: export type ElicitResult = Infer<typeof ElicitResultSchema>;\n1830: "
        }
      }
    ]
  },
  {
    "role": "assistant",
    "content": [
      {
        "type": "text",
        "text": "\n\nNow let me check for ModelPreferences and ModelHint types:"
      },
      {
        "type": "tool_use",
        "name": "ripgrep",
        "id": "toolu_01ScbDTNecwPa63Qv9qj67c6",
        "input": {
          "pattern": "export type (ModelHint|ModelPreferences)",
          "path": "src/types.ts"
        }
      }
    ]
  },
  {
    "role": "user",
    "content": [
      {
        "type": "tool_result",
        "toolUseId": "toolu_01ScbDTNecwPa63Qv9qj67c6",
        "content": {
          "output": "{\"data\":{\"elapsed_total\":{\"human\":\"0.004718s\",\"nanos\":4718292,\"secs\":0},\"stats\":{\"bytes_printed\":0,\"bytes_searched\":0,\"elapsed\":{\"human\":\"0.000000s\",\"nanos\":0,\"secs\":0},\"matched_lines\":0,\"matches\":0,\"searches\":0,\"searches_with_match\":0}},\"type\":\"summary\"}\n"
        }
      }
    ]
  },
  {
    "role": "assistant",
    "content": [
      {
        "type": "tool_use",
        "name": "ripgrep",
        "id": "toolu_01AE7AYrMzpLbJHyLdpkqmEb",
        "input": {
          "pattern": "^export type.*Model",
          "path": "src/types.ts"
        }
      }
    ]
  },
  {
    "role": "user",
    "content": [
      {
        "type": "tool_result",
        "toolUseId": "toolu_01AE7AYrMzpLbJHyLdpkqmEb",
        "content": {
          "output": "{\"data\":{\"elapsed_total\":{\"human\":\"0.001852s\",\"nanos\":1851542,\"secs\":0},\"stats\":{\"bytes_printed\":0,\"bytes_searched\":0,\"elapsed\":{\"human\":\"0.000000s\",\"nanos\":0,\"secs\":0},\"matched_lines\":0,\"matches\":0,\"searches\":0,\"searches_with_match\":0}},\"type\":\"summary\"}\n"
        }
      }
    ]
  },
  {
    "role": "assistant",
    "content": [
      {
        "type": "text",
        "text": "\n\nLet me search for where these types might be exported:"
      },
      {
        "type": "tool_use",
        "name": "ripgrep",
        "id": "toolu_01JB2TnNuRRovf1RuYAJ9onj",
        "input": {
          "pattern": "ModelHint|ModelPreferences",
          "path": "src/types.ts"
        }
      }
    ]
  },
  {
    "role": "user",
    "content": [
      {
        "type": "tool_result",
        "toolUseId": "toolu_01JB2TnNuRRovf1RuYAJ9onj",
        "content": {
          "output": "{\"type\":\"begin\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"}}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export const ModelHintSchema = z\\n\"},\"line_number\":1187,\"absolute_offset\":36772,\"submatches\":[{\"match\":{\"text\":\"ModelHint\"},\"start\":13,\"end\":22}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export const ModelPreferencesSchema = z\\n\"},\"line_number\":1199,\"absolute_offset\":37020,\"submatches\":[{\"match\":{\"text\":\"ModelPreferences\"},\"start\":13,\"end\":29}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"    hints: z.optional(z.array(ModelHintSchema)),\\n\"},\"line_number\":1204,\"absolute_offset\":37138,\"submatches\":[{\"match\":{\"text\":\"ModelHint\"},\"start\":30,\"end\":39}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"    modelPreferences: z.optional(ModelPreferencesSchema),\\n\"},\"line_number\":1324,\"absolute_offset\":41572,\"submatches\":[{\"match\":{\"text\":\"ModelPreferences\"},\"start\":33,\"end\":49}]}}\n{\"type\":\"end\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"binary_offset\":null,\"stats\":{\"elapsed\":{\"secs\":0,\"nanos\":386125,\"human\":\"0.000386s\"},\"searches\":1,\"searches_with_match\":1,\"bytes_searched\":59122,\"bytes_printed\":1279,\"matched_lines\":4,\"matches\":4}}}\n{\"data\":{\"elapsed_total\":{\"human\":\"0.001333s\",\"nanos\":1332875,\"secs\":0},\"stats\":{\"bytes_printed\":1279,\"bytes_searched\":59122,\"elapsed\":{\"human\":\"0.000386s\",\"nanos\":386125,\"secs\":0},\"matched_lines\":4,\"matches\":4,\"searches\":1,\"searches_with_match\":1}},\"type\":\"summary\"}\n"
        }
      }
    ]
  },
  {
    "role": "assistant",
    "content": [
      {
        "type": "text",
        "text": "\n\nLet me check if ModelHint and ModelPreferences are exported as types at the end of the file:"
      },
      {
        "type": "tool_use",
        "name": "read",
        "id": "toolu_01WFpgoMqg8BNtn8cP4THbco",
        "input": {
          "path": "src/types.ts",
          "startLineInclusive": 1800,
          "endLineInclusive": 1822
        }
      }
    ]
  },
  {
    "role": "user",
    "content": [
      {
        "type": "tool_result",
        "toolUseId": "toolu_01WFpgoMqg8BNtn8cP4THbco",
        "content": {
          "content": "1800: export type ListToolsRequest = Infer<typeof ListToolsRequestSchema>;\n1801: export type ListToolsResult = Infer<typeof ListToolsResultSchema>;\n1802: export type CallToolResult = Infer<typeof CallToolResultSchema>;\n1803: export type CompatibilityCallToolResult = Infer<typeof CompatibilityCallToolResultSchema>;\n1804: export type CallToolRequest = Infer<typeof CallToolRequestSchema>;\n1805: export type ToolListChangedNotification = Infer<typeof ToolListChangedNotificationSchema>;\n1806: \n1807: /* Logging */\n1808: export type LoggingLevel = Infer<typeof LoggingLevelSchema>;\n1809: export type SetLevelRequest = Infer<typeof SetLevelRequestSchema>;\n1810: export type LoggingMessageNotification = Infer<typeof LoggingMessageNotificationSchema>;\n1811: \n1812: /* Sampling */\n1813: export type ToolChoice = Infer<typeof ToolChoiceSchema>;\n1814: export type UserMessage = Infer<typeof UserMessageSchema>;\n1815: export type AssistantMessage = Infer<typeof AssistantMessageSchema>;\n1816: export type SamplingMessage = Infer<typeof SamplingMessageSchema>;\n1817: export type CreateMessageRequest = Infer<typeof CreateMessageRequestSchema>;\n1818: export type CreateMessageResult = Infer<typeof CreateMessageResultSchema>;\n1819: export type AssistantMessageContent = Infer<typeof AssistantMessageContentSchema>;\n1820: export type UserMessageContent = Infer<typeof UserMessageContentSchema>;\n1821: \n1822: /* Elicitation */"
        }
      }
    ]
  },
  {
    "role": "assistant",
    "content": [
      {
        "type": "text",
        "text": "\n\nLet me search for all exported types in types.ts to see if ModelHint and ModelPreferences are there:"
      },
      {
        "type": "tool_use",
        "name": "ripgrep",
        "id": "toolu_017GEMKEiq9fjvytkVuTNrsZ",
        "input": {
          "pattern": "^export type",
          "path": "src/types.ts"
        }
      }
    ]
  },
  {
    "role": "user",
    "content": [
      {
        "type": "tool_result",
        "toolUseId": "toolu_017GEMKEiq9fjvytkVuTNrsZ",
        "content": {
          "output": "{\"type\":\"begin\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"}}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type IsomorphicHeaders = Record<string, string | string[] | undefined>;\\n\"},\"line_number\":1691,\"absolute_offset\":51456,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type ProgressToken = Infer<typeof ProgressTokenSchema>;\\n\"},\"line_number\":1719,\"absolute_offset\":51946,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type Cursor = Infer<typeof CursorSchema>;\\n\"},\"line_number\":1720,\"absolute_offset\":52009,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type Request = Infer<typeof RequestSchema>;\\n\"},\"line_number\":1721,\"absolute_offset\":52058,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type RequestMeta = Infer<typeof RequestMetaSchema>;\\n\"},\"line_number\":1722,\"absolute_offset\":52109,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type Notification = Infer<typeof NotificationSchema>;\\n\"},\"line_number\":1723,\"absolute_offset\":52168,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type Result = Infer<typeof ResultSchema>;\\n\"},\"line_number\":1724,\"absolute_offset\":52229,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type RequestId = Infer<typeof RequestIdSchema>;\\n\"},\"line_number\":1725,\"absolute_offset\":52278,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type JSONRPCRequest = Infer<typeof JSONRPCRequestSchema>;\\n\"},\"line_number\":1726,\"absolute_offset\":52333,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type JSONRPCNotification = Infer<typeof JSONRPCNotificationSchema>;\\n\"},\"line_number\":1727,\"absolute_offset\":52398,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type JSONRPCResponse = Infer<typeof JSONRPCResponseSchema>;\\n\"},\"line_number\":1728,\"absolute_offset\":52473,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type JSONRPCError = Infer<typeof JSONRPCErrorSchema>;\\n\"},\"line_number\":1729,\"absolute_offset\":52540,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type JSONRPCMessage = Infer<typeof JSONRPCMessageSchema>;\\n\"},\"line_number\":1730,\"absolute_offset\":52601,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type EmptyResult = Infer<typeof EmptyResultSchema>;\\n\"},\"line_number\":1733,\"absolute_offset\":52686,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type CancelledNotification = Infer<typeof CancelledNotificationSchema>;\\n\"},\"line_number\":1736,\"absolute_offset\":52765,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type Icon = Infer<typeof IconSchema>;\\n\"},\"line_number\":1739,\"absolute_offset\":52865,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type Icons = Infer<typeof IconsSchema>;\\n\"},\"line_number\":1740,\"absolute_offset\":52910,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type BaseMetadata = Infer<typeof BaseMetadataSchema>;\\n\"},\"line_number\":1741,\"absolute_offset\":52957,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type Implementation = Infer<typeof ImplementationSchema>;\\n\"},\"line_number\":1744,\"absolute_offset\":53040,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type ClientCapabilities = Infer<typeof ClientCapabilitiesSchema>;\\n\"},\"line_number\":1745,\"absolute_offset\":53105,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type InitializeRequest = Infer<typeof InitializeRequestSchema>;\\n\"},\"line_number\":1746,\"absolute_offset\":53178,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type ServerCapabilities = Infer<typeof ServerCapabilitiesSchema>;\\n\"},\"line_number\":1747,\"absolute_offset\":53249,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type InitializeResult = Infer<typeof InitializeResultSchema>;\\n\"},\"line_number\":1748,\"absolute_offset\":53322,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type InitializedNotification = Infer<typeof InitializedNotificationSchema>;\\n\"},\"line_number\":1749,\"absolute_offset\":53391,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type PingRequest = Infer<typeof PingRequestSchema>;\\n\"},\"line_number\":1752,\"absolute_offset\":53486,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type Progress = Infer<typeof ProgressSchema>;\\n\"},\"line_number\":1755,\"absolute_offset\":53575,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type ProgressNotification = Infer<typeof ProgressNotificationSchema>;\\n\"},\"line_number\":1756,\"absolute_offset\":53628,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type PaginatedRequest = Infer<typeof PaginatedRequestSchema>;\\n\"},\"line_number\":1759,\"absolute_offset\":53723,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type PaginatedResult = Infer<typeof PaginatedResultSchema>;\\n\"},\"line_number\":1760,\"absolute_offset\":53792,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type ResourceContents = Infer<typeof ResourceContentsSchema>;\\n\"},\"line_number\":1763,\"absolute_offset\":53876,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type TextResourceContents = Infer<typeof TextResourceContentsSchema>;\\n\"},\"line_number\":1764,\"absolute_offset\":53945,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type BlobResourceContents = Infer<typeof BlobResourceContentsSchema>;\\n\"},\"line_number\":1765,\"absolute_offset\":54022,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type Resource = Infer<typeof ResourceSchema>;\\n\"},\"line_number\":1766,\"absolute_offset\":54099,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type ResourceTemplate = Infer<typeof ResourceTemplateSchema>;\\n\"},\"line_number\":1767,\"absolute_offset\":54152,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type ListResourcesRequest = Infer<typeof ListResourcesRequestSchema>;\\n\"},\"line_number\":1768,\"absolute_offset\":54221,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type ListResourcesResult = Infer<typeof ListResourcesResultSchema>;\\n\"},\"line_number\":1769,\"absolute_offset\":54298,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type ListResourceTemplatesRequest = Infer<typeof ListResourceTemplatesRequestSchema>;\\n\"},\"line_number\":1770,\"absolute_offset\":54373,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type ListResourceTemplatesResult = Infer<typeof ListResourceTemplatesResultSchema>;\\n\"},\"line_number\":1771,\"absolute_offset\":54466,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type ReadResourceRequest = Infer<typeof ReadResourceRequestSchema>;\\n\"},\"line_number\":1772,\"absolute_offset\":54557,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type ReadResourceResult = Infer<typeof ReadResourceResultSchema>;\\n\"},\"line_number\":1773,\"absolute_offset\":54632,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type ResourceListChangedNotification = Infer<typeof ResourceListChangedNotificationSchema>;\\n\"},\"line_number\":1774,\"absolute_offset\":54705,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type SubscribeRequest = Infer<typeof SubscribeRequestSchema>;\\n\"},\"line_number\":1775,\"absolute_offset\":54804,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type UnsubscribeRequest = Infer<typeof UnsubscribeRequestSchema>;\\n\"},\"line_number\":1776,\"absolute_offset\":54873,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type ResourceUpdatedNotification = Infer<typeof ResourceUpdatedNotificationSchema>;\\n\"},\"line_number\":1777,\"absolute_offset\":54946,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type PromptArgument = Infer<typeof PromptArgumentSchema>;\\n\"},\"line_number\":1780,\"absolute_offset\":55052,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type Prompt = Infer<typeof PromptSchema>;\\n\"},\"line_number\":1781,\"absolute_offset\":55117,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type ListPromptsRequest = Infer<typeof ListPromptsRequestSchema>;\\n\"},\"line_number\":1782,\"absolute_offset\":55166,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type ListPromptsResult = Infer<typeof ListPromptsResultSchema>;\\n\"},\"line_number\":1783,\"absolute_offset\":55239,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type GetPromptRequest = Infer<typeof GetPromptRequestSchema>;\\n\"},\"line_number\":1784,\"absolute_offset\":55310,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"match\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"lines\":{\"text\":\"export type TextContent = Infer<typeof TextContentSchema>;\\n\"},\"line_number\":1785,\"absolute_offset\":55379,\"submatches\":[{\"match\":{\"text\":\"export type\"},\"start\":0,\"end\":11}]}}\n{\"type\":\"end\",\"data\":{\"path\":{\"text\":\"/Users/ochafik/code/modelcontextprotocol-typescript-sdk/src/types.ts\"},\"binary_offset\":null,\"stats\":{\"elapsed\":{\"secs\":0,\"nanos\":86667,\"human\":\"0.000087s\"},\"searches\":1,\"searches_with_match\":1,\"bytes_searched\":0,\"bytes_printed\":15709,\"matched_lines\":50,\"matches\":50}}}\n{\"data\":{\"elapsed_total\":{\"human\":\"0.000808s\",\"nanos\":808042,\"secs\":0},\"stats\":{\"bytes_printed\":15709,\"bytes_searched\":0,\"elapsed\":{\"human\":\"0.000087s\",\"nanos\":86667,\"secs\":0},\"matched_lines\":50,\"matches\":50,\"searches\":1,\"searches_with_match\":1}},\"type\":\"summary\"}\n"
        }
      }
    ]
  },
  {
    "role": "assistant",
    "content": [
      {
        "type": "text",
        "text": "\n\nNow let me continue reading the rest of the exported types:"
      },
      {
        "type": "tool_use",
        "name": "read",
        "id": "toolu_0185uJh6ZBc9rQkiG7uNJTej",
        "input": {
          "path": "src/types.ts",
          "startLineInclusive": 1785,
          "endLineInclusive": 1835
        }
      }
    ]
  },
  {
    "role": "user",
    "content": [
      {
        "type": "tool_result",
        "toolUseId": "toolu_0185uJh6ZBc9rQkiG7uNJTej",
        "content": {
          "content": "1785: export type TextContent = Infer<typeof TextContentSchema>;\n1786: export type ImageContent = Infer<typeof ImageContentSchema>;\n1787: export type AudioContent = Infer<typeof AudioContentSchema>;\n1788: export type ToolCallContent = Infer<typeof ToolCallContentSchema>;\n1789: export type ToolResultContent = Infer<typeof ToolResultContentSchema>;\n1790: export type EmbeddedResource = Infer<typeof EmbeddedResourceSchema>;\n1791: export type ResourceLink = Infer<typeof ResourceLinkSchema>;\n1792: export type ContentBlock = Infer<typeof ContentBlockSchema>;\n1793: export type PromptMessage = Infer<typeof PromptMessageSchema>;\n1794: export type GetPromptResult = Infer<typeof GetPromptResultSchema>;\n1795: export type PromptListChangedNotification = Infer<typeof PromptListChangedNotificationSchema>;\n1796: \n1797: /* Tools */\n1798: export type ToolAnnotations = Infer<typeof ToolAnnotationsSchema>;\n1799: export type Tool = Infer<typeof ToolSchema>;\n1800: export type ListToolsRequest = Infer<typeof ListToolsRequestSchema>;\n1801: export type ListToolsResult = Infer<typeof ListToolsResultSchema>;\n1802: export type CallToolResult = Infer<typeof CallToolResultSchema>;\n1803: export type CompatibilityCallToolResult = Infer<typeof CompatibilityCallToolResultSchema>;\n1804: export type CallToolRequest = Infer<typeof CallToolRequestSchema>;\n1805: export type ToolListChangedNotification = Infer<typeof ToolListChangedNotificationSchema>;\n1806: \n1807: /* Logging */\n1808: export type LoggingLevel = Infer<typeof LoggingLevelSchema>;\n1809: export type SetLevelRequest = Infer<typeof SetLevelRequestSchema>;\n1810: export type LoggingMessageNotification = Infer<typeof LoggingMessageNotificationSchema>;\n1811: \n1812: /* Sampling */\n1813: export type ToolChoice = Infer<typeof ToolChoiceSchema>;\n1814: export type UserMessage = Infer<typeof UserMessageSchema>;\n1815: export type AssistantMessage = Infer<typeof AssistantMessageSchema>;\n1816: export type SamplingMessage = Infer<typeof SamplingMessageSchema>;\n1817: export type CreateMessageRequest = Infer<typeof CreateMessageRequestSchema>;\n1818: export type CreateMessageResult = Infer<typeof CreateMessageResultSchema>;\n1819: export type AssistantMessageContent = Infer<typeof AssistantMessageContentSchema>;\n1820: export type UserMessageContent = Infer<typeof UserMessageContentSchema>;\n1821: \n1822: /* Elicitation */\n1823: export type BooleanSchema = Infer<typeof BooleanSchemaSchema>;\n1824: export type StringSchema = Infer<typeof StringSchemaSchema>;\n1825: export type NumberSchema = Infer<typeof NumberSchemaSchema>;\n1826: export type EnumSchema = Infer<typeof EnumSchemaSchema>;\n1827: export type PrimitiveSchemaDefinition = Infer<typeof PrimitiveSchemaDefinitionSchema>;\n1828: export type ElicitRequest = Infer<typeof ElicitRequestSchema>;\n1829: export type ElicitResult = Infer<typeof ElicitResultSchema>;\n1830: \n1831: /* Autocomplete */\n1832: export type ResourceTemplateReference = Infer<typeof ResourceTemplateReferenceSchema>;\n1833: /**\n1834:  * @deprecated Use ResourceTemplateReference instead\n1835:  */"
        }
      }
    ]
  },
  {
    "role": "assistant",
    "content": [
      {
        "type": "text",
        "text": "\n\nPerfect! Now I have a comprehensive view. Let me also check for content-related types used in sampling:"
      },
      {
        "type": "tool_use",
        "name": "read",
        "id": "toolu_01EizKoWSWs9B4u1ZZhziGUK",
        "input": {
          "path": "src/types.ts",
          "startLineInclusive": 1100,
          "endLineInclusive": 1180
        }
      }
    ]
  },
  {
    "role": "user",
    "content": [
      {
        "type": "tool_result",
        "toolUseId": "toolu_01EizKoWSWs9B4u1ZZhziGUK",
        "content": {
          "content": "1100:    * However, any errors in _finding_ the tool, an error indicating that the\n1101:    * server does not support tool calls, or any other exceptional conditions,\n1102:    * should be reported as an MCP error response.\n1103:    */\n1104:   isError: z.optional(z.boolean()),\n1105: });\n1106: \n1107: /**\n1108:  * CallToolResultSchema extended with backwards compatibility to protocol version 2024-10-07.\n1109:  */\n1110: export const CompatibilityCallToolResultSchema = CallToolResultSchema.or(\n1111:   ResultSchema.extend({\n1112:     toolResult: z.unknown(),\n1113:   }),\n1114: );\n1115: \n1116: /**\n1117:  * Used by the client to invoke a tool provided by the server.\n1118:  */\n1119: export const CallToolRequestSchema = RequestSchema.extend({\n1120:   method: z.literal(\"tools/call\"),\n1121:   params: BaseRequestParamsSchema.extend({\n1122:     name: z.string(),\n1123:     arguments: z.optional(z.record(z.unknown())),\n1124:   }),\n1125: });\n1126: \n1127: /**\n1128:  * An optional notification from the server to the client, informing it that the list of tools it offers has changed. This may be issued by servers without any previous subscription from the client.\n1129:  */\n1130: export const ToolListChangedNotificationSchema = NotificationSchema.extend({\n1131:   method: z.literal(\"notifications/tools/list_changed\"),\n1132: });\n1133: \n1134: /* Logging */\n1135: /**\n1136:  * The severity of a log message.\n1137:  */\n1138: export const LoggingLevelSchema = z.enum([\n1139:   \"debug\",\n1140:   \"info\",\n1141:   \"notice\",\n1142:   \"warning\",\n1143:   \"error\",\n1144:   \"critical\",\n1145:   \"alert\",\n1146:   \"emergency\",\n1147: ]);\n1148: \n1149: /**\n1150:  * A request from the client to the server, to enable or adjust logging.\n1151:  */\n1152: export const SetLevelRequestSchema = RequestSchema.extend({\n1153:   method: z.literal(\"logging/setLevel\"),\n1154:   params: BaseRequestParamsSchema.extend({\n1155:     /**\n1156:      * The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/logging/message.\n1157:      */\n1158:     level: LoggingLevelSchema,\n1159:   }),\n1160: });\n1161: \n1162: /**\n1163:  * Notification of a log message passed from server to client. If no logging/setLevel request has been sent from the client, the server MAY decide which messages to send automatically.\n1164:  */\n1165: export const LoggingMessageNotificationSchema = NotificationSchema.extend({\n1166:   method: z.literal(\"notifications/message\"),\n1167:   params: BaseNotificationParamsSchema.extend({\n1168:     /**\n1169:      * The severity of this log message.\n1170:      */\n1171:     level: LoggingLevelSchema,\n1172:     /**\n1173:      * An optional name of the logger issuing this message.\n1174:      */\n1175:     logger: z.optional(z.string()),\n1176:     /**\n1177:      * The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.\n1178:      */\n1179:     data: z.unknown(),\n1180:   }),"
        }
      }
    ]
  },
  {
    "role": "assistant",
    "content": [
      {
        "type": "text",
        "text": "\n\nNow let me check what content types are defined for sampling messages:"
      },
      {
        "type": "tool_use",
        "name": "read",
        "id": "toolu_01NfGZD58SKsckLASodXBfMz",
        "input": {
          "path": "src/types.ts",
          "startLineInclusive": 800,
          "endLineInclusive": 1000
        }
      }
    ]
  },
  {
    "role": "user",
    "content": [
      {
        "type": "tool_result",
        "toolUseId": "toolu_01NfGZD58SKsckLASodXBfMz",
        "content": {
          "content": "800:      * The base64-encoded image data.\n801:      */\n802:     data: Base64Schema,\n803:     /**\n804:      * The MIME type of the image. Different providers may support different image types.\n805:      */\n806:     mimeType: z.string(),\n807: \n808:     /**\n809:      * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)\n810:      * for notes on _meta usage.\n811:      */\n812:     _meta: z.optional(z.object({}).passthrough()),\n813:   })\n814:   .passthrough();\n815: \n816: /**\n817:  * An Audio provided to or from an LLM.\n818:  */\n819: export const AudioContentSchema = z\n820:   .object({\n821:     type: z.literal(\"audio\"),\n822:     /**\n823:      * The base64-encoded audio data.\n824:      */\n825:     data: Base64Schema,\n826:     /**\n827:      * The MIME type of the audio. Different providers may support different audio types.\n828:      */\n829:     mimeType: z.string(),\n830: \n831:     /**\n832:      * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)\n833:      * for notes on _meta usage.\n834:      */\n835:     _meta: z.optional(z.object({}).passthrough()),\n836:   })\n837:   .passthrough();\n838: \n839: /**\n840:  * A tool call request from an assistant (LLM).\n841:  * Represents the assistant's request to use a tool.\n842:  */\n843: export const ToolCallContentSchema = z\n844:   .object({\n845:     type: z.literal(\"tool_use\"),\n846:     /**\n847:      * The name of the tool to invoke.\n848:      * Must match a tool name from the request's tools array.\n849:      */\n850:     name: z.string(),\n851:     /**\n852:      * Unique identifier for this tool call.\n853:      * Used to correlate with ToolResultContent in subsequent messages.\n854:      */\n855:     id: z.string(),\n856:     /**\n857:      * Arguments to pass to the tool.\n858:      * Must conform to the tool's inputSchema.\n859:      */\n860:     input: z.object({}).passthrough(),\n861:     /**\n862:      * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)\n863:      * for notes on _meta usage.\n864:      */\n865:     _meta: z.optional(z.object({}).passthrough()),\n866:   })\n867:   .passthrough();\n868: \n869: /**\n870:  * The result of a tool execution, provided by the user (server).\n871:  * Represents the outcome of invoking a tool requested via ToolCallContent.\n872:  */\n873: export const ToolResultContentSchema = z\n874:   .object({\n875:     type: z.literal(\"tool_result\"),\n876:     /**\n877:      * The ID of the tool call this result corresponds to.\n878:      * Must match a ToolCallContent.id from a previous assistant message.\n879:      */\n880:     toolUseId: z.string(),\n881:     /**\n882:      * The result of the tool execution.\n883:      * Can be any JSON-serializable object.\n884:      * Error information should be included in the content itself.\n885:      */\n886:     content: z.object({}).passthrough(),\n887:     /**\n888:      * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)\n889:      * for notes on _meta usage.\n890:      */\n891:     _meta: z.optional(z.object({}).passthrough()),\n892:   })\n893:   .passthrough();\n894: \n895: /**\n896:  * The contents of a resource, embedded into a prompt or tool call result.\n897:  */\n898: export const EmbeddedResourceSchema = z\n899:   .object({\n900:     type: z.literal(\"resource\"),\n901:     resource: z.union([TextResourceContentsSchema, BlobResourceContentsSchema]),\n902:     /**\n903:      * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)\n904:      * for notes on _meta usage.\n905:      */\n906:     _meta: z.optional(z.object({}).passthrough()),\n907:   })\n908:   .passthrough();\n909: \n910: /**\n911:  * A resource that the server is capable of reading, included in a prompt or tool call result.\n912:  *\n913:  * Note: resource links returned by tools are not guaranteed to appear in the results of `resources/list` requests.\n914:  */\n915: export const ResourceLinkSchema = ResourceSchema.extend({\n916:   type: z.literal(\"resource_link\"),\n917: });\n918: \n919: /**\n920:  * A content block that can be used in prompts and tool results.\n921:  */\n922: export const ContentBlockSchema = z.union([\n923:   TextContentSchema,\n924:   ImageContentSchema,\n925:   AudioContentSchema,\n926:   ResourceLinkSchema,\n927:   EmbeddedResourceSchema,\n928: ]);\n929: \n930: /**\n931:  * Describes a message returned as part of a prompt.\n932:  */\n933: export const PromptMessageSchema = z\n934:   .object({\n935:     role: z.enum([\"user\", \"assistant\"]),\n936:     content: ContentBlockSchema,\n937:   })\n938:   .passthrough();\n939: \n940: /**\n941:  * The server's response to a prompts/get request from the client.\n942:  */\n943: export const GetPromptResultSchema = ResultSchema.extend({\n944:   /**\n945:    * An optional description for the prompt.\n946:    */\n947:   description: z.optional(z.string()),\n948:   messages: z.array(PromptMessageSchema),\n949: });\n950: \n951: /**\n952:  * An optional notification from the server to the client, informing it that the list of prompts it offers has changed. This may be issued by servers without any previous subscription from the client.\n953:  */\n954: export const PromptListChangedNotificationSchema = NotificationSchema.extend({\n955:   method: z.literal(\"notifications/prompts/list_changed\"),\n956: });\n957: \n958: /* Tools */\n959: /**\n960:  * Additional properties describing a Tool to clients.\n961:  *\n962:  * NOTE: all properties in ToolAnnotations are **hints**.\n963:  * They are not guaranteed to provide a faithful description of\n964:  * tool behavior (including descriptive properties like `title`).\n965:  *\n966:  * Clients should never make tool use decisions based on ToolAnnotations\n967:  * received from untrusted servers.\n968:  */\n969: export const ToolAnnotationsSchema = z\n970:   .object({\n971:     /**\n972:      * A human-readable title for the tool.\n973:      */\n974:     title: z.optional(z.string()),\n975: \n976:     /**\n977:      * If true, the tool does not modify its environment.\n978:      *\n979:      * Default: false\n980:      */\n981:     readOnlyHint: z.optional(z.boolean()),\n982: \n983:     /**\n984:      * If true, the tool may perform destructive updates to its environment.\n985:      * If false, the tool performs only additive updates.\n986:      *\n987:      * (This property is meaningful only when `readOnlyHint == false`)\n988:      *\n989:      * Default: true\n990:      */\n991:     destructiveHint: z.optional(z.boolean()),\n992: \n993:     /**\n994:      * If true, calling the tool repeatedly with the same arguments\n995:      * will have no additional effect on the its environment.\n996:      *\n997:      * (This property is meaningful only when `readOnlyHint == false`)\n998:      *\n999:      * Default: false\n1000:      */"
        }
      }
    ]
  },
  {
    "role": "assistant",
    "content": [
      {
        "type": "text",
        "text": "\n\nNow I have a comprehensive understanding of the sampling-related classes and types. Let me compile this information:\n\n## Classes and Types Involved with Sampling\n\nBased on my search through the codebase, here are the key classes and types related to sampling in the Model Context Protocol (MCP) TypeScript SDK:\n\n### Core Sampling Types\n\n**Message Types:**\n- **`SamplingMessage`** - Discriminated union of `UserMessage` and `AssistantMessage`\n- **`UserMessage`** - A message from the user (server) with role \"user\"\n- **`AssistantMessage`** - A message from the assistant (LLM) with role \"assistant\"\n\n**Content Types for Messages:**\n- **`UserMessageContent`** - Union of: `TextContent`, `ImageContent`, `AudioContent`, `ToolResultContent`\n- **`AssistantMessageContent`** - Union of: `TextContent`, `ImageContent`, `AudioContent`, `ToolCallContent`\n\n**Content Blocks:**\n- **`TextContent`** - Text-based content with annotations\n- **`ImageContent`** - Base64-encoded image data with MIME type\n- **`AudioContent`** - Base64-encoded audio data with MIME type\n- **`ToolCallContent`** - Tool call request from LLM (type: \"tool_use\")\n- **`ToolResultContent`** - Tool execution result (type: \"tool_result\")\n\n### Request/Response Types\n\n- **`CreateMessageRequest`** - Request from server to sample an LLM via client (method: \"sampling/createMessage\")\n  - Contains: messages, systemPrompt, maxTokens, temperature, tools, toolChoice, modelPreferences, etc.\n  \n- **`CreateMessageResult`** - Client's response to sampling request\n  - Contains: model name, stopReason, role (\"assistant\"), content\n\n### Model Selection Types\n\n- **`ModelPreferencesSchema`** - Server's preferences for model selection\n  - `hints`: Optional array of `ModelHint`\n  - `costPriority`: 0-1 priority for cost\n  - `speedPriority`: 0-1 priority for latency\n  - `intelligencePriority`: 0-1 priority for capabilities\n\n- **`ModelHintSchema`** - Hints for model selection\n  - `name`: Optional model name hint\n\n### Tool-Related Types\n\n- **`ToolChoice`** - Controls tool usage behavior\n  - `mode`: \"auto\" | \"required\" | \"none\"\n  - `disable_parallel_tool_use`: Optional boolean\n\n- **`Tool`** - Tool definition with name, description, and inputSchema\n\n### Capabilities\n\n- **`ClientCapabilities.sampling`** - Indicates client supports sampling\n  - `sampling.tools`: Supports tools and tool_choice parameters\n  - `sampling.context`: Supports includeContext parameter (soft-deprecated)\n\n### Classes with Sampling Methods\n\n**Server Class** (`src/server/index.ts`):\n- **`createMessage(params, options)`** - Method to request LLM sampling from client\n  - Validates client has sampling capability\n  - Sends \"sampling/createMessage\" request\n\n**Client Class** (`src/client/index.ts`):\n- Handles incoming \"sampling/createMessage\" requests from server\n  - Validates sampling capability is declared\n  - Routes to request handler\n\n### Key Constants\n\n- **Stop Reasons**: \"endTurn\", \"stopSequence\", \"maxTokens\", \"toolUse\", \"refusal\", \"other\"\n- **Method**: \"sampling/createMessage\"\n\n### Schemas (Zod validators)\n\nAll types have corresponding Zod schemas for validation:\n- `SamplingMessageSchema`\n- `CreateMessageRequestSchema`\n- `CreateMessageResultSchema`\n- `ModelPreferencesSchema`\n- `ToolChoiceSchema`\n- And all content type schemas\n\nThis sampling system enables MCP servers to request LLM completions from connected clients, with full support for tool calling, multi-modal content (text, images, audio), and model selection preferences."
      }
    ]
  }
]

Breaking Changes

  • CreateMessageResult.content is now the union of a content block or an array of content blocks
  • Sampling w/ includeContext w/ values != none will fail if capabilities.sampling.context isn't set on the client.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed
  • Remove sampling backfill and its (dev) Dependency to the Anthropic SDK from this PR

ochafik and others added 22 commits October 1, 2025 14:28
Add comprehensive tool calling support to MCP sampling:

- New content types: ToolCallContent and ToolResultContent
- Split SamplingMessage into role-specific UserMessage/AssistantMessage
- Add ToolChoice schema for controlling tool usage behavior
- Update CreateMessageRequest with tools and tool_choice parameters
- Update CreateMessageResult with new stop reasons (toolUse, refusal, other)
- Enhance ClientCapabilities.sampling with context and tools sub-capabilities
- Mark includeContext as soft-deprecated in favor of explicit tools
- Add comprehensive unit tests (27 new test cases covering all new schemas)

All tests pass (47/47 in types.test.ts).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…OpenAI APIs

Remove the non-standard isError field from ToolResultContentSchema.
Errors should be represented in the content object itself, matching
the standard behavior of Claude and OpenAI tool result APIs.

Updated tests to validate error content directly without isError flag.
All tests pass (47/47 in types.test.ts, 683/683 in full suite).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Update backfillSampling.ts to support SEP-1577 tool calling:

**New Conversions:**
- MCP Tool → Claude API tool format (toolToClaudeFormat)
- MCP ToolChoice → Claude tool_choice (toolChoiceToClaudeFormat)
- Claude tool_use → MCP ToolCallContent (in contentToMcp)
- MCP ToolResultContent → Claude tool_result (in contentFromMcp)

**Message Handling:**
- Extract and convert tools/tool_choice from CreateMessageRequest
- Pass tools to Claude API messages.create
- Handle multi-content responses (prioritize tool_use over text)
- Map stop reasons: tool_use → toolUse, end_turn → endTurn, etc.

**Flow Support:**
The proxy now fully supports agentic tool calling loops:
1. Server sends request with tools
2. Claude responds with tool_use
3. Server executes tool and sends tool_result
4. Claude provides final answer

All conversions maintain type safety with proper MCP types
(UserMessage, AssistantMessage, ToolCallContent, ToolResultContent).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…le search

Adds a comprehensive example showing how to use MCP sampling with a tool loop.
The server exposes a fileSearch tool that uses an LLM with locally-defined
ripgrep and read tools to intelligently search and read files.

Key features:
- Implements a full agentic tool loop pattern
- Uses systemPrompt parameter for proper LLM instruction
- Validates tool inputs using Zod schemas
- Ensures path safety with canonicalization and CWD constraints
- Demonstrates recursive tool use (LLM decides which tools to call)
- Proper error handling throughout the tool loop
- Includes iteration limit to prevent infinite loops

This example demonstrates SEP-1577 tool calling support in MCP sampling.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Analyzed existing test files and examples to document:
- How to set up Client with StdioClientTransport for testing
- How to implement sampling request handlers
- Proper test structure and cleanup patterns
- Example code snippets for sampling handlers
- How to simulate a tool loop conversation in tests
- Common pitfalls and solutions

This analysis covers both unit testing (InMemoryTransport) and
integration testing (StdioClientTransport) patterns for servers
that use MCP sampling.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Adds integration tests for toolLoopSampling server that verify:
- Complete tool loop flow (ripgrep → read → final answer)
- Path validation and security (prevents directory traversal)
- Error handling for invalid tool names
- Input validation with malformed tool inputs
- Maximum iteration limit enforcement

Tests use StdioClientTransport to spawn actual server process and
implement sampling handlers that simulate LLM behavior with tool
calls and responses.

All 5 tests pass successfully, providing solid coverage of the
agentic tool loop pattern.

Also updates toolLoopSampling.ts with linter formatting fixes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…pSampling

Updated toolLoopSampling.ts to properly handle CreateMessageResult.content
as both single content blocks and arrays:

- Changed runToolLoop return type to include both answer and transcript
- Extract and execute ALL tool_use blocks in parallel using Promise.all()
- Concatenate all text content blocks for final answer
- Return full message transcript for debugging

This ensures the tool loop works correctly when the LLM returns multiple
content blocks (text + tool calls, or multiple tool calls in one turn).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Added sendLoggingMessage calls to provide real-time feedback on tool loop
operations:

- Log iteration number at the start of each loop
- Log number and names of tools being executed
- Log completion message with total iteration count

Also fixed toolWithSampleServer.ts to handle CreateMessageResult.content
as arrays (extract and concatenate all text blocks).

This provides visibility into the tool loop's progress for debugging and
monitoring purposes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…oolLoopSampling

Added line range support to the read tool:
- Added optional startLineInclusive and endLineInclusive parameters
- Returns numbered lines when range is specified
- Validates line ranges and provides helpful error messages

Improved logging with tool-specific messages:
- Loop iteration logs: "Loop iteration N: X tool invocation(s) requested"
- Ripgrep logs: "Searching pattern 'X' under Y"
- Read logs: "Reading file X" or "Reading file X (lines A-B)"

Updated tool descriptions:
- Added hint to read tool about requesting context lines around matches
- Emphasized that ripgrep output includes line numbers

This provides better visibility into tool operations and enables more
efficient file reading by fetching only relevant line ranges.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
ochafik and others added 6 commits October 1, 2025 19:21
Added comprehensive token usage tracking and reporting to the tool loop
sampling example:

**backfillSampling.ts**:
- Pass Anthropic API usage data through _meta field of CreateMessageResult
- Includes all token counts from Claude API response

**toolLoopSampling.ts**:
- Added AggregatedUsage interface to track cumulative token counts
- Aggregate usage across all API calls in the tool loop:
  - input_tokens (regular input)
  - cache_creation_input_tokens (tokens to create cache)
  - cache_read_input_tokens (tokens read from cache)
  - output_tokens (generated output)
  - api_calls (number of createMessage calls)
- Updated runToolLoop return type to include usage
- Display formatted usage summary in fileSearch tool output:
  - Total input tokens with breakdown by type
  - Total output tokens
  - Total tokens consumed
  - Number of API calls made

Example output:
```
--- Token Usage Summary ---
Total Input Tokens: 1234
  - Regular: 800
  - Cache Creation: 200
  - Cache Read: 234
Total Output Tokens: 567
Total Tokens: 1801
API Calls: 3
```

This provides complete visibility into Claude API token consumption for
monitoring costs and optimizing cache usage.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Updated backfillSampling and toolLoopSampling to support the new schema
where UserMessage and AssistantMessage content can be arrays:

**backfillSampling.ts**:
- Split contentFromMcp into contentBlockFromMcp (single block) and
  contentFromMcp (handles both single and arrays)
- Updated message mapping to pass content arrays directly to Claude API
- Now properly handles messages with multiple content blocks

**toolLoopSampling.ts**:
- Removed flattening logic that created multiple messages
- SamplingMessage now natively supports content arrays
- Simplified message history management

**toolLoopSampling.test.ts**:
- Added helper to handle content as potentially an array
- Updated all test assertions to work with array content
- All 5 tests passing

This aligns with the MCP protocol change allowing content arrays in
UserMessage and AssistantMessage, enabling multi-block responses (e.g.,
text + tool calls in one message).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant