score_prompt
Score and rewrite coding prompts to improve clarity and effectiveness across 4 dimensions before sending to an AI. No API key or server required.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| raw_prompt | Yes |
Implementation Reference
- src/tools/score.ts:7-16 (handler)The main handler function for the score_prompt tool. It applies all rule sets (efficiency, clarity, specificity, completeness) to the prompt, computes a total score and per-dimension breakdown using the scorer, and returns results including issues.
export function scorePrompt(rawPrompt: string) { const rules = [ ...applyEfficiencyRules(rawPrompt).results, ...applyClarityRules(rawPrompt).results, ...applySpecificityRules(rawPrompt).results, ...applyCompletenessRules(rawPrompt).results, ]; const { total, breakdown } = computeScore(rules); return { total, breakdown, issues: rules }; } - src/index.ts:17-22 (registration)Registration of the 'score_prompt' tool on the MCP server (stdio transport). Defines the schema: expects a single 'raw_prompt' string. Calls scorePrompt() and returns JSON output.
server.tool("score_prompt", { raw_prompt: z.string() }, async ({ raw_prompt }) => ({ content: [{ type: "text", text: JSON.stringify(scorePrompt(raw_prompt), null, 2) }] }) ); - src/http.ts:22-27 (registration)Registration of the 'score_prompt' tool on the MCP server (HTTP/streamable transport). Same schema and handler logic as the stdio registration.
server.tool("score_prompt", { raw_prompt: z.string() }, async ({ raw_prompt }) => ({ content: [{ type: "text", text: JSON.stringify(scorePrompt(raw_prompt), null, 2) }] }) ); - src/lib/scorer.ts:13-30 (helper)The computeScore function that calculates the total prompt score (out of 100) and per-dimension breakdown (each up to 25 points) based on penalties derived from rule violations.
export function computeScore(rules: RuleResult[]): { total: number; breakdown: ScoreBreakdown } { const penalties: Record<string, number> = { clarity: 0, specificity: 0, completeness: 0, efficiency: 0 }; for (const r of rules) { const maxPenalty = 25 / RULES_PER_DIMENSION[r.dimension]; penalties[r.dimension] += maxPenalty * SEVERITY_WEIGHT[r.severity]; } const breakdown: ScoreBreakdown = { clarity: Math.round(Math.max(0, 25 - penalties.clarity)), specificity: Math.round(Math.max(0, 25 - penalties.specificity)), completeness: Math.round(Math.max(0, 25 - penalties.completeness)), efficiency: Math.round(Math.max(0, 25 - penalties.efficiency)), }; const total = (Object.values(breakdown) as number[]).reduce((a, b) => a + b, 0); return { total, breakdown }; } - src/lib/types.ts:1-17 (schema)Type definitions used by the scoring system: RuleResult (includes dimension, severity, message, fix_applied) and ScoreBreakdown (clarity, specificity, completeness, efficiency).
export type Severity = "info" | "warn" | "critical"; export type Dimension = "clarity" | "specificity" | "completeness" | "efficiency"; export interface RuleResult { id: string; dimension: Dimension; severity: Severity; message: string; fix_applied: boolean; } export interface ScoreBreakdown { clarity: number; specificity: number; completeness: number; efficiency: number; }