Define an MCP resource as a module.
defmodule MyApp.MCP.Config do
use Noizu.MCP.Server.Resource,
uri: "config://app",
name: "App Config",
mime_type: "application/json",
subscribable: true
@impl true
def read(_uri, _ctx), do: {:ok, Jason.encode!(MyApp.config())}
enduse options
:uri(required) — the resource URI:name,:title,:description,:mime_type,:size,:annotations,:icons,:meta— advertised inresources/list:subscribable— when true, clients mayresources/subscribeto this URI and the server'sresources.subscribecapability is enabled. Publish changes withMyServer.notify_resource_updated(uri).
Return values from read/2
{:ok, String.t()}— text contents (with the declared mime type){:ok, {:blob, binary()}}— binary contents (base64-encoded on the wire){:ok, ResourceContents.t() | [ResourceContents.t()]}— full control{:error, Noizu.MCP.Error.t()}— protocol error (Noizu.MCP.Error.resource_not_found/1for missing resources)
Summary
Callbacks
The wire definition advertised by resources/list.
Read the resource. See the module docs for return values.
Callbacks
@callback definition() :: Noizu.MCP.Types.Resource.t()
The wire definition advertised by resources/list.
@callback read(uri :: String.t(), ctx :: Noizu.MCP.Ctx.t()) :: {:ok, term()} | {:error, term()}
Read the resource. See the module docs for return values.