Skip to main content
Glama
onion-ai

onion-mcp-server

Official
by onion-ai

code_generate

Converts natural language descriptions into functional code. Supports multiple languages and styles for tailored output.

Instructions

根据自然语言描述生成代码。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
descriptionYes功能描述
languageNoPython
styleNosimple

Implementation Reference

  • Registers 'code_generate' tool name to the handle_code handler via the _HANDLERS routing table.
    for _t in CODE_TOOLS:   
        _HANDLERS[_t.name] = handle_code
  • Defines the 'code_generate' tool schema: name, description, inputSchema with 'description', 'language', and 'style' parameters.
    types.Tool(
        name="code_generate",
        description="根据自然语言描述生成代码。",
        inputSchema={
            "type": "object",
            "properties": {
                "description": {"type": "string", "description": "功能描述"},
                "language":    {"type": "string", "default": "Python"},
                "style":       {
                    "type": "string",
                    "enum": ["simple", "production"],
                    "default": "simple",
                },
            },
            "required": ["description"],
        },
    ),
  • The handler logic for 'code_generate' that builds the prompt from arguments (description, language, style) and calls llm_call to generate code.
    elif name == "code_generate":
        style_map = {
            "simple":     "简洁易读",
            "production": "生产级别(含完整错误处理、日志、类型注解)",
        }
        style_str = style_map.get(a.get("style", "simple"), "简洁易读")
        lang      = a.get("language", "Python")
        prompt = (
            f"请用 {lang} 编写以下功能的代码,风格要求:{style_str}。\n"
            f"只输出代码和必要的注释,不需要额外解释。\n\n"
            f"需求:{a['description']}"
        )
  • The llm_call helper used by handle_code to send the prompt to the LLM and return the generated text.
    async def llm_call(
        prompt: str,
        system: Optional[str] = None,
        temperature: float = 0.7,
    ) -> str:
        """单轮调用"""
        messages = []
        if system:
            messages.append({"role": "system", "content": system})
        messages.append({"role": "user", "content": prompt})
        return await llm_chat(messages, temperature=temperature)
Behavior2/5

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

No annotations provided, so description must disclose behavior. It only states code generation, with no details about limitations, error handling, or side effects. Minimal transparency.

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

Conciseness3/5

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

Single sentence is efficient but omits crucial details for a tool with 3 parameters. Balance between conciseness and completeness is lacking.

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?

With no output schema and only one required parameter described, the description fails to explain default language, style options, or return format. Incomplete for confident invocation.

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

Parameters2/5

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

Schema coverage is 33%; description adds no extra meaning beyond the parameter names. Language and style parameters are not elaborated, leaving the agent to infer from default values.

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

Purpose5/5

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

Description clearly states 'generate code based on natural language description', specifying verb and resource. It effectively distinguishes from other code tools like code_fix or code_review.

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

Usage Guidelines3/5

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

The description implies the tool is for generating code, but lacks explicit guidance on when to use versus alternatives or prerequisites. Usage context is implied by the task.

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/onion-ai/mcp-server'

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