NexusMCP.Server.Prompt (NexusMCP v0.3.0)

Copy Markdown View Source

Provides the defprompt macro for declaring MCP prompts alongside their handlers.

Prompts are user-controlled message templates surfaced to MCP clients via prompts/list and prompts/get (MCP spec 2025-11-25).

Example

defprompt "code_review", "Ask the model to review code",
  arguments: [code: {:string!, "The code to review"}] do
  {:ok, [
    %{role: "user",
      content: %{type: "text", text: "Please review:\n" <> params["code"]}}
  ]}
end

Inside the do block, params and session are bound.

Arguments

The :arguments keyword uses the same DSL as tool params (see NexusMCP.Server.Schema):

arguments: [
  code: :string!,                     # required string, no description
  language: {:string, "Lang hint"},   # optional string with description
  max_lines: {:integer, "Cap lines"}
]

Required arguments are validated by the session before the handler is invoked; missing required args produce a -32602 JSON-RPC error.

Summary

Functions

Converts the DSL arguments: keyword list to MCP prompt argument objects.

Returns the names of arguments marked required.

Functions

build_arguments(args)

Converts the DSL arguments: keyword list to MCP prompt argument objects.

Example

iex> NexusMCP.Server.Prompt.build_arguments([code: {:string!, "The code"}])
[%{name: "code", description: "The code", required: true}]

defprompt(name, description, opts_or_args \\ [], do_block \\ [])

(macro)

required_argument_names(arguments)

Returns the names of arguments marked required.