AttestoMCP.Server (attesto_mcp_server v0.8.0)

Copy Markdown View Source

Attesto-native MCP server core.

The core is transport-neutral. AttestoMCP.Server.Plug and AttestoMCP.Server.Stdio both call dispatch/4; handlers run under a separately supervised task and receive only an explicit authorization context.

Summary

Types

Registered primitive definition accepted by the registry.

A normal, failed, or modern interactive handler return.

Options for startup, limits, timeouts, cursor policy, and disabled task flags.

Functions

Consumes one bounded rate-limit token for a principal/category key.

Returns a specification to start this module under a supervisor.

Dispatch one decoded request and return a correlated response/result.

Returns normalized options used by the protocol adapters.

Registers one supported primitive type.

Registers a completion handler for an explicit prompt/template reference.

Registers a prompt and publishes a modern prompts-list invalidation.

Registers a static resource and publishes a modern resources-list invalidation.

Registers a URI-template resource and publishes a modern resources-list invalidation.

Registers a tool and publishes a modern tools-list invalidation.

Returns the negotiated minimum legacy log level for an owned session.

Sets the negotiated minimum legacy log level for an owned session.

Returns a deterministic registry snapshot.

Starts the supervised protocol core and its registry/subscription children.

Returns bounded public counters for sessions, streams, subscriptions, and requests.

Types

context()

@type context() :: map()

definition()

@type definition() :: map() | keyword()

Registered primitive definition accepted by the registry.

handler_return()

@type handler_return() :: {:ok, term()} | {:error, term()} | {:input_required, map()}

A normal, failed, or modern interactive handler return.

server_opts()

@type server_opts() :: AttestoMCP.Server.API.server_opts()

Options for startup, limits, timeouts, cursor policy, and disabled task flags.

Functions

ack_legacy_stream(server, stream_ref)

ack_subscription(server, id, owner \\ nil)

allow_rate(server, key, category)

@spec allow_rate(pid() | atom(), term(), atom()) :: :ok | {:error, :rate_limited}

Consumes one bounded rate-limit token for a principal/category key.

await_initialized(server, id, principal, tenant, timeout \\ 50)

cancel_request(server, principal, request_id, owner \\ nil)

cancel_subscription(server, id, owner \\ nil)

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

close_legacy_stream(server, stream_ref)

close_subscription(server, id, owner \\ nil)

delete_session(server, id)

deliver_client_response(server, session_id, principal, tenant, response)

dispatch(server, request, context \\ %{}, opts \\ [])

@spec dispatch(pid() | atom(), map(), context(), keyword()) :: term()

Dispatch one decoded request and return a correlated response/result.

get_session(server, id, principal, tenant \\ nil)

mark_initialized(server, id)

negotiate_session(server, session_id, principal, tenant, version, capabilities)

new_session(server, principal, tenant \\ nil, opts \\ [])

open_legacy_stream(server, session_id, principal, tenant, sink, authorize \\ nil)

options(server)

@spec options(pid() | atom()) :: keyword()

Returns normalized options used by the protocol adapters.

publish(server, notification, opts \\ [])

register(server, type, identity, definition)

@spec register(pid() | atom(), atom(), String.t(), definition()) ::
  :ok | {:error, term()}

Registers one supported primitive type.

register_completion(server, name, definition)

@spec register_completion(pid() | atom(), String.t(), definition()) ::
  :ok | {:error, term()}

Registers a completion handler for an explicit prompt/template reference.

register_prompt(server, name, definition)

@spec register_prompt(pid() | atom(), String.t(), definition()) ::
  :ok | {:error, term()}

Registers a prompt and publishes a modern prompts-list invalidation.

register_resource(server, uri, definition)

@spec register_resource(pid() | atom(), String.t(), definition()) ::
  :ok | {:error, term()}

Registers a static resource and publishes a modern resources-list invalidation.

register_resource_template(server, template, definition)

@spec register_resource_template(pid() | atom(), String.t(), definition()) ::
  :ok | {:error, term()}

Registers a URI-template resource and publishes a modern resources-list invalidation.

register_tool(server, name, definition)

@spec register_tool(pid() | atom(), String.t(), definition()) ::
  :ok | {:error, term()}

Registers a tool and publishes a modern tools-list invalidation.

request_client(server, session_id, principal, tenant, method, params, timeout \\ 30000)

session_capabilities(server, session_id, principal, tenant)

session_logging_level(server, session_id, principal, tenant)

@spec session_logging_level(pid() | atom(), binary(), term(), term()) ::
  String.t() | nil

Returns the negotiated minimum legacy log level for an owned session.

set_session_logging_level(server, session_id, principal, tenant, level)

@spec set_session_logging_level(pid() | atom(), binary(), term(), term(), String.t()) ::
  :ok | {:error, :not_found}

Sets the negotiated minimum legacy log level for an owned session.

set_session_version(server, id, version)

snapshot(server)

@spec snapshot(pid() | atom()) :: map()

Returns a deterministic registry snapshot.

start_link(opts \\ [])

@spec start_link(server_opts()) :: GenServer.on_start()

Starts the supervised protocol core and its registry/subscription children.

stats(server)

@spec stats(pid() | atom()) :: map()

Returns bounded public counters for sessions, streams, subscriptions, and requests.

subscribe_resource(server, session_id, principal, tenant, uri)

touch_session(server, id)

unsubscribe_resource(server, session_id, principal, tenant, uri)