An immutable registry and synchronous protocol-neutral dispatcher.
The router owns no process, connection, session, or application state.
dispatch/5 accepts the immutable execution options the server holds:
:schema_validator and the optional :authorization policy. Snodo.Server
supplies both from Snodo.Server.Runtime; calling the router directly with
neither runs neither.
Summary
Functions
Returns whether any registered prompt or resource template supports completion.
Runs one operation against the registered components.
Returns the definition of every registered prompt, sorted by name.
Returns the definition of every resource template, sorted by URI template.
Returns the definition of every direct resource, sorted by URI.
Returns the definition of every registered tool, sorted by name.
Returns an empty router.
Registers a prompt module under the name in its definition.
Registers a resource module.
Registers a tool module under the name its Snodo.Tool.name/0 returns.
Types
Functions
Returns whether any registered prompt or resource template supports completion.
@spec dispatch(t(), operation(), map(), Snodo.Context.t(), keyword()) :: {:ok, Snodo.Result.t()} | {:error, Snodo.Error.t()}
Runs one operation against the registered components.
Operations and the params each reads:
:tools_list,:prompts_list,:resources_list, and:resource_templates_list- the whole sorted catalog, less any component the authorization policy refuses in the:discoveryphase.paramsis ignored. Pagination and cache hints are applied later bySnodo.Server.{:tools_call, name}- calls the tool withparams["arguments"](default%{}).{:resource_read, uri}- reads the direct resource or the one template that matchesuri. Template variables are merged intoparamsbeforeSnodo.Resource.read/2runs.{:prompt_get, name}- renders the prompt withparams["arguments"], a map of strings to strings.:completion_complete- completes a prompt or resource template argument from thecompletion/completeparams.
Any other operation returns a -32601 error.
Returns {:ok, %Snodo.Result{}} or {:error, %Snodo.Error{}}:
- An unknown name or URI, an
"arguments"value of the wrong shape, or a missing required prompt argument is a -32602 error. - A missing required tool argument, tool arguments the schema validator
rejects, and a tool that returns
{:error, reason}without anSnodo.Errorproduce{:ok, result}with aSnodo.Result.error/2result. - An
Snodo.Errorreturned by a component, or by the authorization policy in the:invocationphase, is returned unchanged. - A component that raises, exits, or returns an invalid value is a -32603 error.
Options:
:schema_validator- theSnodo.Schema.Validatormodule that checks tool arguments and structured output. Defaults toSnodo.Schema.Validator.Passthrough.:authorization- aSnodo.Authorizationpolicy module,{module, options}, ornil, asSnodo.Server.Runtime.new/1accepts. Defaults tonil, which allows everything. Any other value raisesArgumentError.
@spec list_prompts(t()) :: [Snodo.Prompt.Definition.t()]
Returns the definition of every registered prompt, sorted by name.
No authorization policy is applied.
@spec list_resource_templates(t()) :: [Snodo.Resource.Definition.t()]
Returns the definition of every resource template, sorted by URI template.
No authorization policy is applied.
@spec list_resources(t()) :: [Snodo.Resource.Definition.t()]
Returns the definition of every direct resource, sorted by URI.
No authorization policy is applied.
@spec list_tools(t()) :: [Snodo.Tool.Definition.t()]
Returns the definition of every registered tool, sorted by name.
No authorization policy is applied.
@spec new() :: t()
Returns an empty router.
Registers a prompt module under the name in its definition.
Registering the same module again returns the router unchanged. Raises
ArgumentError when the module is not a valid Snodo.Prompt or another
module already registered the name.
Registers a resource module.
A definition with a :uri registers a direct resource under that URI. A
definition with a :uri_template registers a resource template, which
answers any URI its Snodo.Resource.matches?/1 accepts. Registering the
same module again returns the router unchanged.
Raises ArgumentError when the module is not a valid Snodo.Resource, or
when its name, URI, or URI template is already registered by another
module. A direct URI that an existing template matches, and a template that
matches an existing direct URI, are also refused.
Registers a tool module under the name its Snodo.Tool.name/0 returns.
The module must implement Snodo.Tool with a valid definition. Registering
the same module again returns the router unchanged.
Raises ArgumentError when the module cannot be loaded, does not export the
Snodo.Tool callbacks, returns an invalid definition, or uses a name that
another module already registered.