Define an MCP resource template (RFC 6570 {var} URIs) as a module.
defmodule MyApp.MCP.TableSchema do
use Noizu.MCP.Server.ResourceTemplate,
uri_template: "db://{table}/schema",
name: "Table Schema",
mime_type: "application/json"
@impl true
def read(_uri, %{table: table}, _ctx) do
{:ok, MyApp.Repo.schema_json(table)}
end
@impl true
def complete(:table, prefix, _ctx) do
{:ok, Enum.filter(MyApp.Repo.tables(), &String.starts_with?(&1, prefix))}
end
@impl true
def list(_ctx) do
{:ok, Enum.map(MyApp.Repo.tables(), &%Noizu.MCP.Types.Resource{uri: "db://#{&1}/schema"})}
end
enduse options
:uri_template (required), plus the same metadata options as
Noizu.MCP.Server.Resource (:name, :title, :description, :mime_type,
:annotations, :icons, :meta, :subscribable).
Callbacks
read/3(required) — receives the concrete URI and the template variables, atom-keyed. Same return contract asNoizu.MCP.Server.Resource.read/2.complete/3(optional) — powerscompletion/completefor template variables. Return{:ok, values}or{:ok, values, has_more: true, total: n}.list/1(optional) — makes the template's instances enumerable inresources/list.
Summary
Callbacks
The wire definition advertised by resources/templates/list.
Callbacks
@callback definition() :: Noizu.MCP.Types.ResourceTemplate.t()
The wire definition advertised by resources/templates/list.
@callback list(ctx :: Noizu.MCP.Ctx.t()) :: {:ok, [Noizu.MCP.Types.Resource.t()]} | {:error, term()}
@callback read(uri :: String.t(), vars :: map(), ctx :: Noizu.MCP.Ctx.t()) :: {:ok, term()} | {:error, term()}