Skip to main content
Glama

validate_completion_metadata

Read-onlyIdempotent

Validate required billing metadata fields and values before prompt completion to catch attribution errors and avoid paying for incorrect calls.

Instructions

Preflight billing metadata before run_prompt_completion. Validates required fields and values without making changes, so you can catch attribution errors before paying for the call.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
client_idNoClient ID for billing attribution
appNoApp identifier (REQUIRED). Use your deployed app name, for example 'hourlink' or 'support-console'.
envNoEnvironment identifier (REQUIRED). Use your environment name, for example 'dev', 'staging', 'prod', or 'qa'.
project_idNoProject ID for granular billing
featureNoFeature name for tracking

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
okYesWhether the tool call succeeded and returned structured data
dataNoStructured success payload when ok is true
errorNoStructured error payload when ok is false

Implementation Reference

  • Registration of the 'validate_completion_metadata' MCP tool. Provides the tool description, schema reference, and handler that delegates to service.prompts.validateBillingMetadata.
    // Validate completion metadata tool
    server.tool(
    	"validate_completion_metadata",
    	"Preflight billing metadata before run_prompt_completion. Validates required fields and values without making changes, so you can catch attribution errors before paying for the call.",
    	PROMPTS_TOOL_SCHEMAS.validateCompletionMetadata,
    	async (params) => {
    		const result = service.prompts.validateBillingMetadata(params);
    
    		return {
    			content: [
    				{
    					type: "text",
    					text: JSON.stringify(
    						{
    							valid: result.valid,
    							errors: result.errors,
    							warnings: result.warnings,
    							metadata: params,
    						},
    						null,
    						2,
    					),
    				},
    			],
    		};
    	},
    );
  • Zod validation schema for the tool's input parameters: all fields are optional since this is a pre-flight validation check.
    validateCompletionMetadata: {
    	client_id: z
    		.string()
    		.optional()
    		.describe("Client ID for billing attribution"),
    	app: PromptAppIdentifierSchema.optional(),
    	env: PromptEnvironmentIdentifierSchema.optional(),
    	project_id: z
    		.string()
    		.optional()
    		.describe("Project ID for granular billing"),
    	feature: z.string().optional().describe("Feature name for tracking"),
    },
  • Core validation logic: checks that client_id, app, and env are present (errors) and warns if project_id is missing.
    validateBillingMetadata(
    	metadata: Partial<BillingMetadata>,
    ): ValidateMetadataResult {
    	const errors: string[] = [];
    	const warnings: string[] = [];
    
    	if (!metadata.client_id) {
    		errors.push("Missing required field: client_id");
    	}
    	if (!metadata.app) {
    		errors.push("Missing required field: app");
    	}
    	if (!metadata.env) {
    		errors.push("Missing required field: env");
    	}
    
    	if (!metadata.project_id) {
    		warnings.push(
    			"Missing recommended field: project_id (helps with billing attribution)",
    		);
    	}
    
    	return {
    		valid: errors.length === 0,
    		errors,
    		warnings,
    	};
    }
  • Canonical BillingMetadata schema used in run_prompt_completion. The validateCompletionMetadata schema uses optional variants of the same fields.
    export const BillingMetadataSchema = z.object({
    	client_id: z
    		.string()
    		.describe("Client ID for billing attribution (REQUIRED)"),
    	app: PromptAppIdentifierSchema,
    	env: PromptEnvironmentIdentifierSchema,
    	project_id: z.string().optional().describe("Project ID for granular billing"),
    	feature: z.string().optional().describe("Feature name for tracking"),
    });
  • TypeScript interface for BillingMetadata used across the service layer.
    export interface BillingMetadata {
    	client_id: string;
    	app: string;
    	env: string;
    	project_id?: string;
    	feature?: string;
    	prompt_slug?: string;
    	prompt_version?: string;
    	[key: string]: unknown;
    }
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnlyHint=true and idempotentHint=true. The description reinforces this by stating 'validates without making changes' and 'catch attribution errors before paying for the call', adding clear behavioral context about no side effects and cost-saving intent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences with zero waste. The first sentence states the purpose and the parent tool; the second explains the benefit and behavior. Information is front-loaded and every sentence earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the presence of an output schema (not shown) and rich annotations, the description is complete: it covers what the tool does, why to use it (no-cost check), and when (before run_prompt_completion). No missing behavioral or contextual details.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% with each parameter described (e.g., client_id for billing, app as required). The description adds value by framing these parameters as 'billing metadata' and emphasizing preflight validation, giving an overarching semantic context that ties the parameters together.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description explicitly states the tool validates billing metadata before running a prompt completion, using a specific verb ('validate') and resource ('billing metadata'). It clearly distinguishes itself from sibling tools like run_prompt_completion, which actually executes and incurs charges.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description tells the agent to use this tool before run_prompt_completion to catch attribution errors early and avoid paying for failed calls. It implicitly advises when to use (preflight) and confidently differentiates from the costing sibling by emphasizing the no-cost, no-change nature.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/s-b-e-n-s-o-n/portkey-admin-mcp'

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