rewrite_coding_prompt
Optimizes coding prompts for AI IDEs by adding structure, context, and language-specific considerations to improve AI-generated code results.
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)The core implementation of the 'rewrite_coding_prompt' tool, which uses Anthropic's Claude model to rewrite the user's coding prompt for optimal use in AI IDEs like Cursor AI.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:21-39 (registration)Tool definition and registration object for 'rewrite_coding_prompt', including name, description, and input 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:24-38 (schema)Input schema definition for the 'rewrite_coding_prompt' tool, specifying parameters prompt and language.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)Registration of the tool in the ListToolsRequest handler, exposing it via the MCP protocol.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [REWRITE_CODING_PROMPT_TOOL], }));
- index.ts:117-127 (registration)Tool dispatch handler case in CallToolRequestSchema that validates arguments and invokes the rewriteCodingPrompt handler.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, }; }