ExMCP.DSL.Prompt (ex_mcp v0.10.0)

View Source

Simplified DSL for defining MCP prompts.

Provides the defprompt macro for defining prompt templates with arguments.

Summary

Functions

Validates a prompt definition at compile time.

Defines an argument within an arguments block.

Converts argument definitions to the MCP protocol format.

Defines a prompt template with its arguments and metadata.

Sets icons for the current prompt (new in 2025-11-25).

Validates prompt arguments against their definitions.

Functions

__validate_prompt_definition__(prompt_name, meta)

Validates a prompt definition at compile time.

This function is called during the defprompt macro expansion to ensure the prompt definition is complete and valid.

arg(name, opts \\ [])

(macro)

Defines an argument within an arguments block.

Options

  • :required - Whether the argument is required (default: false)
  • :description - Human-readable description

Examples

arg :code, required: true, description: "Code to review"
arg :language, description: "Programming language"
arg :focus, required: false, description: "Areas to focus on"

arguments(list)

(macro)

arguments_to_mcp_format(argument_definitions)

Converts argument definitions to the MCP protocol format.

The MCP spec uses a simpler format for prompt arguments compared to tools.

defprompt(prompt_name, list)

(macro)

Defines a prompt template with its arguments and metadata.

Examples

defprompt "code_review" do
  meta do
    name "Code Review Assistant"
    description "Reviews code with specific focus areas"
    version "2.0.0"
  end

  arguments do
    arg :code, required: true, description: "Code to review"
    arg :language, required: false, description: "Programming language"
    arg :focus, required: false, description: "Review focus areas"
  end
end

defprompt "greeting" do
  meta do
    name "Greeting Template"
    description "A simple greeting prompt"
  end
end

icons(icon_list)

(macro)

Sets icons for the current prompt (new in 2025-11-25).

validate_arguments(args, argument_definitions)

Validates prompt arguments against their definitions.

Examples

arguments = [
  %{name: "code", required: true, description: "Code to review"},
  %{name: "language", required: false, description: "Programming language"}
]

# Valid arguments
ExMCP.DSL.Prompt.validate_arguments(%{"code" => "def hello, do: :world"}, arguments)
# => :ok

# Missing required argument
ExMCP.DSL.Prompt.validate_arguments(%{"language" => "elixir"}, arguments)
# => {:error, "Missing required argument: code"}