# `OzMcp.Structs.CreateMessageRequestParams`
[🔗](https://github.com/oz-elixir/oz_mcp/blob/v0.9.0/lib/oz_mcp/structs/create_message_request_params.ex#L1)

Helper module used to build the params of a `sampling/createMessage`
request.

_(MCP protocol: 2025-11-25)_

`messages` is a list of `OzMcp.Structs.SamplingMessage` structs or maps.
`tools` is a list of `OzMcp.Structs.Tool` structs or maps. `maxTokens` is
required.

Tool use follows the rules of the specification, checked by `build/1`:

  * a message that has a `tool_result` block has only `tool_result`
    blocks, has the role `user` and comes right after a message with the
    `tool_use` blocks it answers;
  * a message that has `tool_use` blocks has the role `assistant` and is
    followed by a message with a `tool_result` block for each of them (the
    same `toolUseId`).

## Short example:

```elixir
%CreateMessageRequestParams{}
  |> CreateMessageRequestParams.messages([SamplingMessage.user("Hello")])
  |> CreateMessageRequestParams.max_tokens(100)
  |> CreateMessageRequestParams.build()
```

Result:

```elixir
%{
  messages: [%{role: "user", content: %{type: "text", text: "Hello"}}],
  maxTokens: 100
}
```

Specification: [CreateMessageRequestParams](https://modelcontextprotocol.io/specification/2025-11-25/schema#createmessagerequestparams)

## Fields

| Field | Setter | Type | Required |
|---|---|---|---|
| `messages` | `messages/2` | list of `t:OzMcp.Structs.SamplingMessage.t/0` or map | yes |
| `modelPreferences` | `model_preferences/2` | OzMcp.Structs.ModelPreferences.t() \| map() \| nil | no |
| `systemPrompt` | `system_prompt/2` | string | no |
| `includeContext` | `include_context/2` | String.t() \| atom() \| nil | no |
| `temperature` | `temperature/2` | number | no |
| `maxTokens` | `max_tokens/2` | pos_integer() \| nil | no |
| `stopSequences` | `stop_sequences/2` | list | no |
| `metadata` | `metadata/2` | map | no |
| `tools` | `tools/2` | [OzMcp.Structs.Tool.t() \| map()] \| nil | no |
| `toolChoice` | `tool_choice/2` | OzMcp.Structs.ToolChoice.t() \| map() \| atom() \| nil | no |
| `_meta` | `_meta/2` | map | no |
| `task` | `task/2` | `t:OzMcp.Structs.TaskMetadata.t/0` | no |

# `t`

```elixir
@type t() :: %OzMcp.Structs.CreateMessageRequestParams{
  _meta: map() | nil,
  includeContext: String.t() | atom() | nil,
  maxTokens: pos_integer() | nil,
  messages: [OzMcp.Structs.SamplingMessage.t() | map()],
  metadata: map() | nil,
  modelPreferences: OzMcp.Structs.ModelPreferences.t() | map() | nil,
  stopSequences: list() | nil,
  systemPrompt: String.t() | nil,
  task: OzMcp.Structs.TaskMetadata.t() | nil,
  temperature: number() | nil,
  toolChoice: OzMcp.Structs.ToolChoice.t() | map() | atom() | nil,
  tools: [OzMcp.Structs.Tool.t() | map()] | nil
}
```

# `build`

```elixir
@spec build(t()) :: map()
```

# `include_context`

```elixir
@spec include_context(t(), String.t() | atom() | nil) :: t()
```

# `max_tokens`

```elixir
@spec max_tokens(t(), pos_integer() | nil) :: t()
```

# `messages`

```elixir
@spec messages(t(), [OzMcp.Structs.SamplingMessage.t() | map()]) :: t()
```

# `metadata`

```elixir
@spec metadata(t(), map() | nil) :: t()
```

# `model_preferences`

```elixir
@spec model_preferences(t(), OzMcp.Structs.ModelPreferences.t() | map() | nil) :: t()
```

# `stop_sequences`

```elixir
@spec stop_sequences(t(), list() | nil) :: t()
```

# `system_prompt`

```elixir
@spec system_prompt(t(), String.t() | nil) :: t()
```

# `task`

```elixir
@spec task(t(), OzMcp.Structs.TaskMetadata.t() | nil) :: t()
```

# `temperature`

```elixir
@spec temperature(t(), number() | nil) :: t()
```

# `tool_choice`

```elixir
@spec tool_choice(t(), OzMcp.Structs.ToolChoice.t() | map() | atom() | nil) :: t()
```

# `tools`

```elixir
@spec tools(t(), [OzMcp.Structs.Tool.t() | map()] | nil) :: t()
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
