# `Phantom.ResourceTemplate`
[🔗](https://github.com/dbernheisel/phantom_mcp/blob/main/lib/phantom/resource_template.ex#L1)

The Model Context Protocol (MCP) provides a standardized way for
servers to expose resources to clients. Resources allow servers to
share data that provides context to language models, such as files,
database schemas, or application-specific information. Each resource
is uniquely identified by a URI.

https://modelcontextprotocol.io/specification/2025-03-26/server/resources

# `json`

```elixir
@type json() :: %{
  :uri =&gt; String.t(),
  :name =&gt; String.t(),
  optional(:description) =&gt; String.t(),
  optional(:mimeType) =&gt; String.t(),
  optional(:size) =&gt; pos_integer()
}
```

# `t`

```elixir
@type t() :: %Phantom.ResourceTemplate{
  completion_function: atom(),
  description: String.t(),
  function: atom(),
  handler: module(),
  icons: [Phantom.Icon.t()] | nil,
  meta: map(),
  mime_type: String.t(),
  name: String.t(),
  path: String.t(),
  router: module(),
  scheme: String.t(),
  size: pos_integer(),
  uri: URI.t(),
  uri_template: String.t()
}
```

# `build`

```elixir
@spec build(map() | Keyword.t()) :: t()
```

Build a resource_template spec

The `Phantom.Router.resource/3` macro will build these specs.

- `:name` - The name of the resource template.
- `:uri` - The URI template of the resource in the style of `Plug.Router`, including the scheme.
  For example, you can define a path like `"myapp:///some/path/:project_id/:id` which
  will be parsed to include path params `%{"project_id" => _, "id" => _}`. The scheme can be
  `"https"`, `"git"`, `"file"`, or custom, eg `"myapp"`.
- `:description` - The description of the resource and when to use it.
- `:handler` - The module to call.
- `:function` - The function to call on the handler module.
- `:completion_function` - The function to call on the handler module that will provide possible completion results.
- `:mime_type` - the MIME type of the results.
- `:router` - The Router module that will capture the URIs and route resources by URI to functions.
  This is constructed by the `Phantom.Router.resource/3` macro automatically as
  `MyApp.MyMCPRouter.ResourceRouter.{Scheme}`. The module does not need to exist at the time of
  building it-- it will be generated when added by `Phantom.Cache.add_resource_template/2`
  or by the `Phantom.Router.resource/3` macro.

# `to_json`

```elixir
@spec to_json(t()) :: json()
```

Represent a ResourceTemplate spec as json when listing the available resources to clients.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
