Skip to main content
Glama
NellyW8

EDA Tools MCP Server

by NellyW8

synthesize_verilog

Convert Verilog HDL code into optimized gate-level netlists for FPGA implementation using Yosys synthesis, supporting multiple target technologies.

Instructions

Synthesize Verilog code using Yosys for various FPGA targets

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
verilog_codeYesThe Verilog source code to synthesize
top_moduleYesName of the top-level module
targetNoTarget technology (generic, ice40, xilinx, intel)generic

Implementation Reference

  • Core handler function in EDAServer class that implements Verilog synthesis using Yosys. Creates temp project dir, writes Verilog, generates target-specific Yosys script (generic/ice40/xilinx), executes yosys, extracts synthesized netlist, and returns JSON with results and project_id.
      async synthesizeVerilog(verilogCode: string, topModule: string, target = "generic"): Promise<string> {
        try {
          const projectId = Math.random().toString(36).substring(2, 15);
          const projectDir = join(this.tempDir, `project_${projectId}`);
          await fs.mkdir(projectDir, { recursive: true });
    
          // Store project info
          this.projects.set(projectId, { dir: projectDir, type: "synthesis" });
    
          // Write Verilog file
          const verilogFile = join(projectDir, "design.v");
          await fs.writeFile(verilogFile, verilogCode);
    
          // Create synthesis script
          let synthScript: string;
          switch (target.toLowerCase()) {
            case "ice40":
              synthScript = `
    read_verilog design.v
    hierarchy -check -top ${topModule}
    synth_ice40 -top ${topModule}
    write_verilog synth_output.v
    stat
    `;
              break;
            case "xilinx":
              synthScript = `
    read_verilog design.v
    hierarchy -check -top ${topModule}
    synth_xilinx -top ${topModule}
    write_verilog synth_output.v
    stat
    `;
              break;
            default:
              synthScript = `
    read_verilog design.v
    hierarchy -check -top ${topModule}
    synth -top ${topModule}
    techmap
    opt
    write_verilog synth_output.v
    stat
    `;
          }
    
          const scriptFile = join(projectDir, "synth.ys");
          await fs.writeFile(scriptFile, synthScript);
    
          // Run Yosys
          const { stdout, stderr } = await execAsync(`yosys -s ${scriptFile}`, {
            cwd: projectDir,
            timeout: 120000,
          });
    
          let synthVerilog = "";
          try {
            synthVerilog = await fs.readFile(join(projectDir, "synth_output.v"), 'utf8');
          } catch {
            synthVerilog = "Synthesis output not generated";
          }
    
          return JSON.stringify({
            project_id: projectId,
            success: true,
            stdout,
            stderr,
            synthesized_verilog: synthVerilog,
            target,
          }, null, 2);
        } catch (error: any) {
          return JSON.stringify({
            success: false,
            error: error.message || String(error),
          }, null, 2);
        }
      }
  • src/index.ts:726-748 (registration)
    Tool registration in ListTools response, including name, description, and input schema (verilog_code required string, top_module required string, target optional string default 'generic').
    {
      name: "synthesize_verilog",
      description: "Synthesize Verilog code using Yosys for various FPGA targets",
      inputSchema: {
        type: "object",
        properties: {
          verilog_code: { 
            type: "string", 
            description: "The Verilog source code to synthesize" 
          },
          top_module: { 
            type: "string", 
            description: "Name of the top-level module" 
          },
          target: { 
            type: "string", 
            description: "Target technology (generic, ice40, xilinx, intel)", 
            default: "generic" 
          },
        },
        required: ["verilog_code", "top_module"],
      },
    },
  • MCP CallToolRequestSchema handler case that validates input parameters using helpers and delegates to edaServer.synthesizeVerilog method.
    case "synthesize_verilog": {
      const verilogCode = validateRequiredString(args, "verilog_code", name);
      const topModule = validateRequiredString(args, "top_module", name);
      const target = getStringProperty(args, "target", "generic");
      
      return {
        content: [{
          type: "text",
          text: await edaServer.synthesizeVerilog(verilogCode, topModule, target),
        }],
      };
    }
  • Helper function for executing shell commands with timeout and large buffer support, used by synthesizeVerilog to run Yosys.
    async function execAsyncWithTimeout(command: string, options: any = {}, timeoutMs = 600000): Promise<{stdout: string, stderr: string}> {
      return new Promise((resolve, reject) => {
        const timeout = setTimeout(() => {
          childProcess.kill('SIGKILL');
          reject(new Error(`Command timed out after ${timeoutMs}ms: ${command}`));
        }, timeoutMs);
    
        // Ensure encoding is set to get string output and increase buffer size
        const execOptions = {
          encoding: 'utf8' as const,
          maxBuffer: 10 * 1024 * 1024, // 10MB default buffer
          ...options
        };
    
        const childProcess = exec(command, execOptions, (error, stdout, stderr) => {
          clearTimeout(timeout);
          if (error) {
            reject(error);
          } else {
            // Convert to string if needed (though with utf8 encoding it should already be string)
            const stdoutStr = typeof stdout === 'string' ? stdout : stdout.toString();
            const stderrStr = typeof stderr === 'string' ? stderr : stderr.toString();
            resolve({ stdout: stdoutStr, stderr: stderrStr });
          }
        });
      });
    }
Behavior2/5

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

With no annotations, the description carries full burden but provides minimal behavioral context. It mentions the tool (Yosys) and target types, but doesn't disclose execution details like runtime, error handling, output format, or resource requirements, leaving significant gaps for a synthesis operation.

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

Conciseness4/5

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

The description is a single, efficient sentence that front-loads key information (synthesize Verilog code). It avoids redundancy but could be more structured by separating tool details from target scope.

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 no annotations and no output schema, the description is incomplete for a synthesis tool. It lacks details on behavioral traits, output format, error conditions, and integration with sibling tools, failing to compensate for the missing structured information.

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?

Schema description coverage is 100%, so the schema fully documents parameters. The description adds no additional parameter semantics beyond implying synthesis for FPGA targets, which aligns with the target parameter but doesn't enhance understanding of verilog_code or top_module beyond the schema.

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 ('synthesize') and resource ('Verilog code'), specifying the tool (Yosys) and target scope (FPGA targets). It distinguishes from siblings like simulate_verilog or run_openlane by focusing on synthesis rather than simulation or full flows, though it doesn't explicitly name alternatives.

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?

No guidance is provided on when to use this tool versus alternatives. While the description implies synthesis for FPGA targets, it doesn't specify prerequisites, when not to use it, or compare it to siblings like simulate_verilog for verification or run_openlane for complete implementation.

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/NellyW8/mcp-EDA'

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