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
      });
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure but only states the basic function. It doesn't explain what 'optimize' entails (e.g., whether it modifies code in-place, returns suggestions, requires internet access, has rate limits, or handles errors), leaving critical operational details unspecified.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise—a single sentence with zero wasted words—and front-loads the core action ('optimize code'). It efficiently communicates the essential purpose without unnecessary elaboration, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of code optimization (a non-trivial task), lack of annotations, and no output schema, the description is incomplete. It fails to address behavioral aspects, usage context among siblings, or expected outputs, leaving significant gaps for an agent to operate effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds no parameter semantics beyond what the schema already provides (100% coverage). The schema fully describes 'code', 'criteria', and 'language', so the baseline score of 3 is appropriate as the description doesn't compensate with additional context like examples or constraints.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('optimize') and resource ('code') using a specific tool ('Qwen3-Coder'), making the purpose understandable. However, it doesn't differentiate this optimization tool from its siblings (explain, fix, generate, review), which all involve code processing but serve different functions.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus its siblings. There's no mention of alternatives, prerequisites, or specific scenarios where optimization is preferred over explanation, fixing, generation, or review, leaving the agent to guess based on tool names alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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