ExMCP.DSL.Prompt (ex_mcp v0.10.0)
View SourceSimplified 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
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.
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"
Converts argument definitions to the MCP protocol format.
The MCP spec uses a simpler format for prompt arguments compared to tools.
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
Sets icons for the current prompt (new in 2025-11-25).
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"}