Phantom.ResourceTemplate (phantom_mcp v0.3.2)
View SourceThe 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
Summary
Functions
Build a resource_template spec
Represent a ResourceTemplate spec as json when listing the available resources to clients.
Types
@type json() :: %{ :uri => String.t(), :name => String.t(), optional(:description) => String.t(), optional(:mimeType) => String.t(), optional(:size) => pos_integer() }
@type t() :: %Phantom.ResourceTemplate{ completion_function: atom(), description: String.t(), function: atom(), handler: module(), 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() }
Functions
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 ofPlug.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 thePhantom.Router.resource/3
macro automatically asMyApp.MyMCPRouter.ResourceRouter.{Scheme}
. The module does not need to exist at the time of building it-- it will be generated when added byPhantom.Cache.add_resource_template/2
or by thePhantom.Router.resource/3
macro.
Represent a ResourceTemplate spec as json when listing the available resources to clients.