Skip to main content
Glama
keithah

Qwen3-Coder MCP Server

qwen3_code_optimize

Optimize code for performance, memory usage, or readability by analyzing and improving existing code based on specified criteria and programming language.

Instructions

Optimize code using Qwen3-Coder

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesThe code to optimize
criteriaNoOptimization criteria (performance, memory, readability, etc.)
languageNoProgramming language of the code

Implementation Reference

  • Handler logic for the qwen3_code_optimize tool. Constructs a specific prompt for code optimization and calls the Qwen3Coder via callQwen3Coder 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;
  • Input schema definition for the qwen3_code_optimize tool, specifying parameters like 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"]
    }
  • Registration of the qwen3_code_optimize tool in the ListTools response, including name, description, and schema.
    {
      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"]
      }
    }
  • Helper function callQwen3Coder that spawns Ollama process to run qwen3-coder:30b model with the given prompt and returns the output.
    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
      });
    }

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/keithah/qwen3-coder-mcp'

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