McpServer.Conn (HTTP MCP Server v0.6.0)

View Source

Protocol defining the MCP connection interface.

This protocol abstracts the connection details for different transport mechanisms (e.g., HTTP, STDIO, custom transports). It provides a unified way to access session information and other connection-specific data.

Summary

Functions

Retrieves private data associated with the connection. This function allows you to access previously stored key-value pairs. If the key does not exist, it returns the provided default value (or nil if no default is given).

Retrieves the session ID associated with the connection.

Stores private data into the connection for later usage. This function allows you to associate arbitrary key-value pairs with the connection.

Types

t()

@type t() :: %McpServer.Conn{private: map(), session_id: String.t()}

Functions

get_private(conn, key, default \\ nil)

@spec get_private(t(), any(), any()) :: any()

Retrieves private data associated with the connection. This function allows you to access previously stored key-value pairs. If the key does not exist, it returns the provided default value (or nil if no default is given).

Examples

iex> conn = %McpServer.Conn{private: %{user_role: :admin}}
iex> McpServer.Conn.get_private(conn, :user_role)
:admin
iex> McpServer.Conn.get_private(conn, :nonexistent_key, :default_value)
:default_value

get_session_id(conn)

@spec get_session_id(t()) :: String.t()

Retrieves the session ID associated with the connection.

The session ID is a unique identifier for the current MCP session.

Examples

iex> conn = %McpServer.Conn{session_id: "abc123"}
iex> McpServer.Conn.get_session_id(conn)
"abc123"

put_private(conn, key, value)

@spec put_private(t(), any(), any()) :: t()

Stores private data into the connection for later usage. This function allows you to associate arbitrary key-value pairs with the connection.

Examples

iex> conn = %McpServer.Conn{}
iex> conn = McpServer.Conn.put_private(conn, :user_role, :admin)
iex> conn.private
%{user_role: :admin}