Phantom.Prompt (phantom_mcp v0.3.2)
View SourceThe Model Context Protocol (MCP) provides a standardized way for servers to expose prompt templates to clients. Prompts allow servers to provide structured messages and instructions for interacting with language models. Clients can discover available prompts, retrieve their contents, and provide arguments to customize them.
sequenceDiagram
participant Client
participant Server
Note over Client,Server: Discovery
Client->>Server: prompts/list
Server-->>Client: List of prompts
Note over Client,Server: Usage
Client->>Server: prompts/get
Server-->>Client: Prompt content
opt listChanged
Note over Client,Server: Changes
Server--)Client: prompts/list_changed
Client->>Server: prompts/list
Server-->>Client: Updated prompts
end
https://modelcontextprotocol.io/specification/2025-03-26/server/prompts
Summary
Functions
Build an audio message for the prompt
Build a prompt spec
Embedded resource reponse.
Build an image message for the prompt
Formats the response from an MCP Router to the MCP specification
Construct a prompt response with the provided messages for the given prompt
Build a text message for the prompt
Represent a Prompt spec as json when listing the available prompts to clients.
Types
@type embedded_resource_content() :: %{ type: :resource, resource: Phantom.Resource.response() }
@type message() :: %{ role: :assistant | :user, content: text_content() | image_content() | audio_content() | embedded_resource_content() }
@type text_content() :: %{type: :text, data: String.t()}
Functions
@spec audio(binary(), String.t()) :: audio_content()
Build an audio message for the prompt
The provided binary will be base64-encoded.
Build a prompt spec
The Phantom.Router.prompt/3
macro will build these specs.
Fields:
:name
- The name of the prompt.: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.:arguments
- A list of arguments that the prompt takes.
Argument fields:
:name
- the name of the argument, eg: "username":description
- description of the argument, eg, "Your Github username":required
- whether the argument is required in order to be called, ie:true
orfalse
@spec embedded_resource(string_uri :: String.t(), map()) :: embedded_resource_content()
Embedded resource reponse.
@spec image(binary(), String.t()) :: image_content()
Build an image message for the prompt
The provided binary will be base64-encoded.
Formats the response from an MCP Router to the MCP specification
Provide a keyword list of messages with a keyword list. The key should contain the role, and the value contain the message.
For example:
require Phantom.Prompt, as: Prompt
{:ok, uri, resource} = MyApp.MCP.Router.read_resource(session, :my_resource, 123)
Prompt.response([
assistant: Prompt.audio(File.read!("foo.wav"), "audio/wav"),
user: Prompt.text("Wow that was interesting"),
assistant: Prompt.image(File.read!("bar.png"), "image/png"),
user: Prompt.text("amazing"),
assistant: Prompt.embedded_resource(uri, resource)
])
Construct a prompt response with the provided messages for the given prompt
See response/1
macro version that do the same thing but will fetch the
prompt spec from the current session.
@spec text(String.t()) :: text_content()
Build a text message for the prompt
Represent a Prompt spec as json when listing the available prompts to clients.