AttestoMCP.Server (attesto_mcp_server v0.14.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 child spec whose id follows the optional registered server name.

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

Negotiates one enabled legacy revision and capability map exactly once.

Returns normalized options used by the protocol adapters.

Registers one supported primitive type.

Registers a bounded primitive batch atomically and coalesces catalog invalidations.

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.

Atomically replaces the complete primitive catalog from one bounded batch.

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

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

Binds an unnegotiated session to one enabled legacy protocol revision.

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)

ack_subscription(server, id, owner)

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)

cancel_subscription(server, id, owner)

child_spec(init_arg)

@spec child_spec(server_opts()) :: Supervisor.child_spec()

Returns a child spec whose id follows the optional registered server name.

close_legacy_stream(server, stream_ref)

close_subscription(server, id)

close_subscription(server, id, owner)

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)

@spec negotiate_session(pid() | atom(), binary(), term(), term(), String.t(), map()) ::
  :ok
  | {:error,
     :invalid_negotiation
     | :already_negotiated
     | :not_found
     | :session_store_unavailable}

Negotiates one enabled legacy revision and capability map exactly once.

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 \\ [])

@spec publish(pid() | atom(), map(), keyword()) :: :ok | {:error, atom()}

register(server, type, identity, definition)

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

Registers one supported primitive type.

register_all(server, registrations)

@spec register_all(pid() | atom(), [AttestoMCP.Server.Registry.registration()]) ::
  :ok | {:error, term()}

Registers a bounded primitive batch atomically and coalesces catalog invalidations.

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.

replace_catalog(server, registrations)

@spec replace_catalog(pid() | atom(), [AttestoMCP.Server.Registry.registration()]) ::
  :ok | {:error, term()}

Atomically replaces the complete primitive catalog from one bounded batch.

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

session_capabilities(server, session_id, principal, tenant)

@spec session_capabilities(pid() | atom(), binary(), term(), term()) ::
  map() | {:error, :session_store_unavailable}

session_logging_level(server, session_id, principal, tenant)

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

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 | :session_store_unavailable}

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

set_session_version(server, id, version)

@spec set_session_version(pid() | atom(), binary(), String.t()) ::
  :ok | {:error, :invalid_version | :session_store_unavailable}

Binds an unnegotiated session to one enabled legacy protocol revision.

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)