qwen3_code_optimize
Optimize code for performance, memory usage, or readability using Qwen3-Coder's AI model to improve code efficiency and maintainability based on specified criteria.
Instructions
Optimize code using Qwen3-Coder
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | The code to optimize | |
| criteria | No | Optimization criteria (performance, memory, readability, etc.) | |
| language | No | Programming language of the code |
Implementation Reference
- qwen3-mcp-server.js:219-228 (handler)Specific switch case handler for the qwen3_code_optimize tool. Constructs a prompt for code optimization based on input code, language, and criteria, then calls the callQwen3Coder helper function.case "qwen3_code_optimize": prompt = `Optimize the following ${args.language || 'code'} for ${args.criteria || 'performance'}: \`\`\`${args.language || ''} ${args.code} \`\`\` Please provide optimized code with explanations of the improvements made.`; result = await callQwen3Coder(prompt); break;
- qwen3-mcp-server.js:138-159 (registration)Tool registration in the ListToolsRequestSchema handler, defining the name, description, and inputSchema for qwen3_code_optimize.{ name: "qwen3_code_optimize", description: "Optimize code using Qwen3-Coder", inputSchema: { type: "object", properties: { code: { type: "string", description: "The code to optimize" }, criteria: { type: "string", description: "Optimization criteria (performance, memory, readability, etc.)" }, language: { type: "string", description: "Programming language of the code" } }, required: ["code"] } }
- qwen3-mcp-server.js:141-158 (schema)Input schema definition for the qwen3_code_optimize tool, specifying properties for code, criteria, and language.inputSchema: { type: "object", properties: { code: { type: "string", description: "The code to optimize" }, criteria: { type: "string", description: "Optimization criteria (performance, memory, readability, etc.)" }, language: { type: "string", description: "Programming language of the code" } }, required: ["code"] }
- qwen3-mcp-server.js:25-56 (helper)Helper function that spawns Ollama process to run qwen3-coder:30b model with the given prompt, captures output, handles errors and timeout. Used by all tools including qwen3_code_optimize.async function callQwen3Coder(prompt, options = {}) { return new Promise((resolve, reject) => { const ollamaProcess = spawn('ollama', ['run', 'qwen3-coder:30b', prompt], { stdio: ['pipe', 'pipe', 'pipe'] }); let output = ''; let error = ''; ollamaProcess.stdout.on('data', (data) => { output += data.toString(); }); ollamaProcess.stderr.on('data', (data) => { error += data.toString(); }); ollamaProcess.on('close', (code) => { if (code === 0) { resolve(output.trim()); } else { reject(new Error(`Ollama process exited with code ${code}: ${error}`)); } }); // Set timeout for long-running requests setTimeout(() => { ollamaProcess.kill(); reject(new Error('Request timeout')); }, options.timeout || 120000); // 2 minutes default timeout }); }