rewrite_coding_prompt
Improve AI IDE responses by restructuring coding prompts with language-specific context and clear requirements before submission.
Instructions
Rewrites user's coding prompts before passing to AI IDE (e.g. Cursor AI) to get the best results from AI IDE.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | The raw user's prompt that needs rewriting | |
| language | Yes | The programming language of the code |
Implementation Reference
- index.ts:68-101 (handler)Core implementation of the rewrite_coding_prompt tool: uses Anthropic Claude model to engineer an optimal prompt for Cursor AI based on user input.async function rewriteCodingPrompt(prompt: string, language: string = "typescript") { // Check if API key is available if (!process.env.ANTHROPIC_API_KEY) { throw new Error("ANTHROPIC_API_KEY environment variable is not set. Using fallback formatting."); } // Initialize Anthropic model const model = new ChatAnthropic({ apiKey: process.env.ANTHROPIC_API_KEY, temperature: 0.2, // Low temperature for more consistent, structured output modelName: "claude-3-7-sonnet-20250219", // Using a fast, cost-effective model }); // Create the system prompt for Claude const systemPromptText = `You are an expert prompt engineer specializing in creating optimal prompts for code-related AI tasks. Your job is to take a user's raw Cursor AI's prompt and transform it into a well-structured, detailed prompt that will get the best results from Cursor AI. Your output should ONLY be the edited prompt that will get the best results from Cursor AI or any IDE with no additional commentary, explanations, or metadata.`; // Create message objects const systemMessage = new SystemMessage(systemPromptText); const userMessage = new HumanMessage(`Here is my raw prompt: \n\n${prompt}\n\nPlease format this into an optimal prompt for Cursor AI. The programming language is ${language}.`); // Call the model with the messages const response = await model.invoke([systemMessage, userMessage]); // Ensure we have a valid response if (!response || typeof response.content !== 'string') { throw new Error('Invalid response from Claude API'); } // Return the formatted prompt return response.content; }
- index.ts:24-38 (schema)JSON schema defining the input parameters for the rewrite_coding_prompt tool.inputSchema: { type: "object", properties: { prompt: { type: "string", description: "The raw user's prompt that needs rewriting" }, language: { type: "string", description: "The programming language of the code" } }, required: ["prompt", "language"], title: "rewrite_coding_promptArguments" }
- index.ts:21-39 (registration)Tool object definition and registration including name, description, and schema.const REWRITE_CODING_PROMPT_TOOL: Tool = { name: "rewrite_coding_prompt", description: "Rewrites user's coding prompts before passing to AI IDE (e.g. Cursor AI) to get the best results from AI IDE.", inputSchema: { type: "object", properties: { prompt: { type: "string", description: "The raw user's prompt that needs rewriting" }, language: { type: "string", description: "The programming language of the code" } }, required: ["prompt", "language"], title: "rewrite_coding_promptArguments" } };
- index.ts:104-106 (registration)Registers the list tools handler that exposes the rewrite_coding_prompt tool.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [REWRITE_CODING_PROMPT_TOOL], }));
- index.ts:117-127 (registration)Dispatch case in CallToolRequestSchema handler that invokes the rewriteCodingPrompt function.case "rewrite_coding_prompt": { if (!isPromptFormatArgs(args)) { throw new Error("Invalid arguments for rewrite_coding_prompt"); } const { prompt, language } = args; const rewrittenPrompt = await rewriteCodingPrompt(prompt, language); return { content: [{ type: "text", text: rewrittenPrompt }], isError: false, }; }
- index.ts:54-66 (helper)Type guard helper function for validating arguments to rewrite_coding_prompt.function isPromptFormatArgs(args: unknown): args is { prompt: string; language: string; } { return ( typeof args === "object" && args !== null && "prompt" in args && typeof (args as { prompt: string }).prompt === "string" && "language" in args && typeof (args as { language: string }).language === "string" ); }