Skip to main content
Glama
Arize-ai

@arizeai/phoenix-mcp

Official
by Arize-ai

upsert-prompt

Create or update prompts with templates and model configurations for AI workflows using the Phoenix platform.

Instructions

Create or update a prompt with its template and configuration. Creates a new prompt and its initial version with specified model settings.

Example usage: Create a new prompt named 'email_generator' with a template for generating emails

Expected return: A confirmation message of successful prompt creation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
descriptionNo
templateYes
model_providerNoOPENAI
model_nameNogpt-4
temperatureNo

Implementation Reference

  • Handler and registration for the 'upsert-prompt' tool. This function handles the tool execution by constructing a prompt version object based on the model provider and calling the Phoenix client's createPrompt function to upsert the prompt.
    server.tool(
      "upsert-prompt",
      UPSERT_PROMPT_DESCRIPTION,
      createPromptSchema.shape,
      async ({
        name,
        description,
        template,
        model_provider,
        model_name,
        temperature,
      }) => {
        let promptVersionData;
    
        switch (model_provider) {
          case "OPENAI":
            promptVersionData = promptVersion({
              modelProvider: "OPENAI",
              modelName: model_name,
              description: description || "",
              template: [
                {
                  role: "user",
                  content: [{ type: "text", text: template }],
                },
              ],
              invocationParameters: {
                temperature: temperature,
              },
            });
            break;
          case "AZURE_OPENAI":
            promptVersionData = promptVersion({
              modelProvider: "AZURE_OPENAI",
              modelName: model_name,
              description: description || "",
              template: [
                {
                  role: "user",
                  content: [{ type: "text", text: template }],
                },
              ],
              invocationParameters: {
                temperature: temperature,
              },
            });
            break;
          case "ANTHROPIC":
            promptVersionData = promptVersion({
              modelProvider: "ANTHROPIC",
              modelName: model_name,
              description: description || "",
              template: [
                {
                  role: "user",
                  content: [{ type: "text", text: template }],
                },
              ],
              invocationParameters: {
                temperature: temperature,
                max_tokens: 1000, // Required for Anthropic
              },
            });
            break;
          case "GOOGLE":
            promptVersionData = promptVersion({
              modelProvider: "GOOGLE",
              modelName: model_name,
              description: description || "",
              template: [
                {
                  role: "user",
                  content: [{ type: "text", text: template }],
                },
              ],
              invocationParameters: {
                temperature: temperature,
              },
            });
            break;
        }
    
        const response = await createPrompt({
          client: client,
          name: name,
          description: description || "",
          version: promptVersionData,
        });
        return {
          content: [
            {
              type: "text",
              text: `Successfully created prompt "${name}":\n${JSON.stringify(response, null, 2)}`,
            },
          ],
        };
      }
    );
  • Zod schema defining the input shape for the upsert-prompt tool, including name, description, template, model_provider, model_name, and temperature.
    export const createPromptSchema = z.object({
      name: z
        .string()
        .transform(
          (val) =>
            val
              .toLowerCase()
              .replace(/\s+/g, "_") // Replace spaces with underscores
              .replace(/[^\w_]/g, "") // Remove anything that's not alphanumeric or underscore
        )
        .refine((val) => val.length > 0, {
          message: "Name cannot be empty after transformation",
        }),
      description: z.string().optional(),
      template: z.string(),
      model_provider: z
        .enum(["OPENAI", "AZURE_OPENAI", "ANTHROPIC", "GOOGLE"])
        .optional()
        .default("OPENAI"),
      model_name: z.string().optional().default("gpt-4"),
      temperature: z.number().optional().default(0.7),
    });
  • Invocation of initializePromptTools which registers all prompt tools, including upsert-prompt.
    initializePromptTools({ client, server });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Arize-ai/phoenix'

If you have feedback or need assistance with the MCP directory API, please join our Discord server