Packages

Official-style Elixir SDK for the Model Context Protocol (MCP) — client and server with stdio and Streamable HTTP transports.

Current section

Files

Jump to
mcp_elixir_sdk lib mcp protocol messages completion.ex
Raw

lib/mcp/protocol/messages/completion.ex

defmodule MCP.Protocol.Messages.Completion do
@moduledoc """
Message types for `completion/complete`.
"""
defmodule Params do
@moduledoc """
Parameters for `completion/complete`.
"""
@derive Jason.Encoder
defstruct [:ref, :argument, :context, :meta]
@type t :: %__MODULE__{
ref: map(),
argument: map(),
context: map() | nil,
meta: map() | nil
}
@spec from_map(map()) :: t()
def from_map(map) when is_map(map) do
%__MODULE__{
ref: Map.fetch!(map, "ref"),
argument: Map.fetch!(map, "argument"),
context: Map.get(map, "context"),
meta: Map.get(map, "_meta")
}
end
defimpl Jason.Encoder, for: __MODULE__ do
def encode(struct, opts) do
map = %{ref: struct.ref, argument: struct.argument}
map = if struct.context, do: Map.put(map, :context, struct.context), else: map
map = if struct.meta, do: Map.put(map, :_meta, struct.meta), else: map
Jason.Encode.map(map, opts)
end
end
end
defmodule Result do
@moduledoc """
Result of `completion/complete`.
"""
@derive Jason.Encoder
defstruct [:completion, :meta]
@type t :: %__MODULE__{
completion: map(),
meta: map() | nil
}
@spec from_map(map()) :: t()
def from_map(map) when is_map(map) do
%__MODULE__{
completion: Map.fetch!(map, "completion"),
meta: Map.get(map, "_meta")
}
end
defimpl Jason.Encoder, for: __MODULE__ do
def encode(struct, opts) do
map = %{completion: struct.completion}
map = if struct.meta, do: Map.put(map, :_meta, struct.meta), else: map
Jason.Encode.map(map, opts)
end
end
end
end