Noizu.MCP.Server.Prompt behaviour (Noizu MCP v0.1.3)

Copy Markdown View Source

Define an MCP prompt as a module.

defmodule MyApp.MCP.CodeReview do
  use Noizu.MCP.Server.Prompt,
    name: "code_review",
    description: "Review code for quality issues"

  arguments do
    arg :code, required: true, description: "The code to review"
    arg :style, description: "Review style", complete: ["strict", "friendly"]
  end

  @impl true
  def get(%{"code" => code} = args, _ctx) do
    style = args["style"] || "strict"

    {:ok,
     [
       Noizu.MCP.Types.PromptMessage.user("Review this code (style: #{style}):"),
       Noizu.MCP.Types.PromptMessage.user(code)
     ]}
  end
end

Prompt arguments are protocol-level string key/values (no JSON Schema), so get/2 receives them string-keyed. Declared required: arguments are checked by the runtime before get/2 runs. The complete: option provides static, prefix-filtered completion for an argument; override complete/3 for dynamic completion.

Return values from get/2

  • {:ok, [PromptMessage.t()]}
  • {:ok, [PromptMessage.t()], description: "..."}
  • {:error, Noizu.MCP.Error.t()}

Summary

Callbacks

The wire definition advertised by prompts/list.

Functions

Declare prompt arguments with arg/1,2.

Callbacks

complete(argument, value, ctx)

(optional)
@callback complete(argument :: atom(), value :: String.t(), ctx :: Noizu.MCP.Ctx.t()) ::
  {:ok, [String.t()]} | {:ok, [String.t()], keyword()} | {:error, term()}

definition()

@callback definition() :: Noizu.MCP.Types.Prompt.t()

The wire definition advertised by prompts/list.

get(args, ctx)

@callback get(args :: map(), ctx :: Noizu.MCP.Ctx.t()) ::
  {:ok, [Noizu.MCP.Types.PromptMessage.t()]}
  | {:ok, [Noizu.MCP.Types.PromptMessage.t()], keyword()}
  | {:error, term()}

Functions

arguments(list)

(macro)

Declare prompt arguments with arg/1,2.