Noizu.MCP.Server.Resource behaviour (Noizu MCP v0.1.6)

Copy Markdown View Source

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())}
end

use options

  • :uri (required) β€” the resource URI
  • :name, :title, :description, :mime_type, :size, :annotations, :icons, :meta β€” advertised in resources/list
  • :subscribable β€” when true, clients may resources/subscribe to this URI and the server's resources.subscribe capability is enabled. Publish changes with MyServer.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/1 for missing resources)

Summary

Callbacks

The wire definition advertised by resources/list.

Read the resource. See the module docs for return values.

Callbacks

definition()

@callback definition() :: Noizu.MCP.Types.Resource.t()

The wire definition advertised by resources/list.

read(uri, ctx)

@callback read(uri :: String.t(), ctx :: Noizu.MCP.Ctx.t()) ::
  {:ok, term()} | {:error, term()}

Read the resource. See the module docs for return values.