MCPKit.Resource behaviour (mcp_kit v0.2.4)

Copy Markdown View Source

Behaviour for MCP resources.

Resource modules expose concrete resource entries, URI templates, and reading logic for concrete URIs. They may optionally implement complete/3 for URI template variable suggestions.

Summary

Callbacks

Returns URI template variable completion suggestions.

Returns the description for the resource module.

Reads a concrete resource URI.

Returns concrete resources shown in resources/list.

Returns URI templates shown in resources/templates/list.

Callbacks

complete(t, map, map)

@callback complete(String.t(), map(), map()) :: {:ok, [String.t()]} | :unsupported

Returns URI template variable completion suggestions.

Return :unsupported when the resource does not expose completions for the given variable.

description()

@callback description() :: String.t() | nil

Returns the description for the resource module.

read(uri, context)

@callback read(uri :: String.t(), context :: map()) ::
  {:reply, [map()], map()}
  | {:error,
     :not_found | {:forbidden, String.t()} | {:internal_error, String.t()}}

Reads a concrete resource URI.

Return {:error, :not_found} when the resource does not handle the URI.

resources()

@callback resources() :: [map()]

Returns concrete resources shown in resources/list.

templates()

@callback templates() :: [map()]

Returns URI templates shown in resources/templates/list.