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
# β¦πΆπ§π½π°β§ read :: auto-generated pointer for public function read
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.