Skip to main content
Glama

@zesun33/mcp-cocotb

Purpose and first steps

Run Python hardware testbenches and inspect their results through an MCP server.

Who it is for: Hardware engineers using an MCP-capable client or coding agent.

First task: Configure the server in your MCP client, then call cocotb_toolchain_info before running a design.

What to expect: Simulator/tool availability, then discovered tests and parsed pass/fail results.

Current scope: Published MCP server. The npx command starts a stdio server that waits for a client; EDA execution also needs its documented host/container tools.

Start here: Runtime requirements and configuration.

Related projects: mcp-verilog, hw-verification-suite.

Choose another project.

Model Context Protocol (MCP) server for Python-based Cocotb co-simulation hardware testbenches.

License: Apache-2.0 CI Protocol: MCP Runtime: Rootless Podman

mcp-cocotb equips AI coding agents and IDEs (Cursor, Windsurf, GitHub Copilot / OpenAI Codex, Claude Code, Google Antigravity, OpenCode, Cline) with structured tools to discover, generate, and run asynchronous Python testbenches against Verilog/SystemVerilog designs. By wrapping the complexity of simulator VPI compilation, Makefile orchestration, and JUnit XML parsing into deterministic JSON contracts, agents can execute closed-loop verification without drowning in simulator logs.

Related MCP server: EDA Tools MCP Server

Install and run

Run this MCP server directly from npm:

npx -y @zesun33/mcp-cocotb

For the complete hardware-agent setup, use npx -y @zesun33/create-hw-agent my-asic.


⚡ Quick Tour: See It in Action

The examples below illustrate tool requests and result fields. Timings, counts, and scores depend on the input and runtime; they are not guaranteed outcomes or fresh verification results.

Why AI Agents Need mcp-cocotb

Without mcp-cocotb (Raw Shell / Make)

With mcp-cocotb (Structured MCP)

Handcrafts brittle Makefiles with obscure cocotb-config paths

1-Call Generation & Execution (cocotb_run)

Parses hundreds of lines of mixed C/VPI/Python stdout

Structured JSON with test counts, pass/fail, duration

Assertion failures lost in noisy simulator terminal scrollback

Direct Python exception traceback & line numbers

Simulator hangs on coroutine deadlock or infinite clock loop

Automated timeout kill-switch (timeout_ms)

Requires complex local Python 3.12 + C++ compiler toolchains

Zero host configuration (runs via isolated rootless Podman)

Example tool requests and results

1. Probing the Environment (Zero-Config Verification)

// Tool Call: cocotb_toolchain_info
{
  "runtime": "podman",
  "image": "ghcr.io/zesun33/verilog",
  "cocotbVersion": "2.1.0",
  "pythonVersion": "Python 3.12.3",
  "simulator": "iverilog (Icarus Verilog)"
}

2. Static Test Discovery (Inspect Test Matrix Without Running)

// Tool Call: cocotb_list_tests {"test_file": "test_dff.py"}
{
  "file": "test_dff.py",
  "totalTests": 3,
  "tests": [
    { "name": "test_dff_reset", "doc": "Verify DFF reset behavior." },
    { "name": "test_dff_toggle", "doc": "Verify DFF data propagation across clock edges." },
    { "name": "test_dff_failing_assert", "doc": "Negative test fixture for assertion failure handling." }
  ]
}

3. Automated Co-Simulation Runner (Passing Suite)

// Tool Call: cocotb_run {"verilog_sources": ["dff.v"], "toplevel": "dff", "python_module": "test_dff"}
{
  "success": false,
  "totalTests": 3,
  "passedTests": 2,
  "failedTests": 1,
  "durationSeconds": 0.04,
  "tests": [
    { "name": "test_dff_reset", "classname": "test_dff", "time": 0.012, "status": "pass" },
    { "name": "test_dff_toggle", "classname": "test_dff", "time": 0.018, "status": "pass" },
    {
      "name": "test_dff_failing_assert",
      "classname": "test_dff",
      "time": 0.010,
      "status": "fail",
      "failureMessage": "assert False, 'INTENTIONAL_ASSERTION_FAILURE'",
      "traceback": "Traceback (most recent call last):\n  File \"test_dff.py\", line 45, in test_dff_failing_assert\n    assert False, 'INTENTIONAL_ASSERTION_FAILURE'\nAssertionError: INTENTIONAL_ASSERTION_FAILURE"
    }
  ]
}

4. Instant Agent Self-Repair Loop

Because mcp-cocotb captures the exact Python failure traceback (AssertionError: INTENTIONAL_ASSERTION_FAILURE at line 45), the LLM agent immediately knows what line and condition failed and can self-correct the RTL or testbench in a single turn without human intervention.


Tools Exposed

Tool

Parameters

Engine

Description

cocotb_run

verilog_sources: string[], toplevel: string, python_module: string, cwd?: string, timeout_ms?: number, simulator?: "icarus" | "verilator", dump_waves?: boolean

cocotb + iverilog/verilator

Compiles DUT, executes the Python testbench, and returns parsed JUnit results with tracebacks plus simulator echo and collected waveFiles (WAVES=1 dumps). simulator: "verilator" needs Verilator >= 5.036 (image ships 5.050) and builds with --timing for Clock/Timer tests.

cocotb_list_tests

test_file: string, cwd?: string

AST Scanner

Fast static parser extracting all @cocotb.test() coroutines and docstrings from a test file without running simulation.

cocotb_generate_runner

verilog_sources: string[], toplevel: string, python_module: string, simulator?: string

Generator

Generates a reproducible Cocotb Makefile (adds COMPILE_ARGS += --timing for Verilator Clock/Timer tests).

cocotb_toolchain_info

none

Probe

Returns active container/host runtime and versions of Cocotb, Python 3, and simulator engines.


Execution Runtime

mcp-cocotb runs inside the zesun33/verilog rootless Podman image so tools are identical on any Linux host.

Public install (recommended — anyone can pull):

podman pull ghcr.io/zesun33/verilog:latest
export MCP_COCOTB_IMAGE=ghcr.io/zesun33/verilog

ghcr.io/zesun33/verilog is the default (anyone can pull). Local builds still work as localhost/zesun33/verilog via MCP_COCOTB_IMAGE.

  • Container mount: -v <workspace>:/workspace:Z -w /workspace

  • Podman storage option: --storage-opt overlay.ignore_chown_errors=true

To force host binaries instead of container execution:

export MCP_COCOTB_RUNTIME=host

Universal Client & AI IDE Setup

Because mcp-cocotb implements the standard Model Context Protocol (MCP), it connects seamlessly to any MCP-compliant AI IDE or agent interface:

Environment

Supported Tools

Setup Location

AI IDEs

Cursor, Windsurf, Google Antigravity, Zed

.cursor/mcp.json or .windsurf/mcp.json

Extensions

GitHub Copilot / OpenAI Codex, Cline, Roo Code

VS Code MCP extension settings

CLI Agents

Claude Code, OpenCode, Goose, Antigravity CLI (agy)

Global MCP configuration or CLI flags

Desktop

Claude Desktop

claude_desktop_config.json

1. Cursor / Windsurf / Antigravity IDE

Add to your project's .cursor/mcp.json or .windsurf/mcp.json:

{
  "mcpServers": {
    "cocotb": {
      "command": "node",
      "args": ["/path/to/personal-projects/mcp-cocotb/dist/index.js"]
    }
  }
}

2. VS Code (GitHub Copilot / OpenAI Codex / Cline)

Add to your VS Code MCP settings or user configuration:

{
  "mcpServers": {
    "cocotb": {
      "command": "node",
      "args": ["/path/to/personal-projects/mcp-cocotb/dist/index.js"]
    }
  }
}

3. Claude Desktop & Claude Code

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "cocotb": {
      "command": "node",
      "args": ["/path/to/personal-projects/mcp-cocotb/dist/index.js"]
    }
  }
}

Verification & Testing

Run the full 6-gate verification suite:

# Full verification (with Podman container execution)
./scripts/verify.sh

# Fast / CI verification (headless environments)
./scripts/verify.sh --quick

Run specific test tiers:

npm run test:unit       # Fast unit tests (parsers & AST discovery)
npm test                # Full test suite (including live container simulation)

npm releases

See RELEASING.md for GitHub Actions dry runs and trusted publishing.

Available Tools

4 tools
cocotb_generate_runnerB

Generates a deterministic, standard Cocotb simulation Makefile for a given Verilog DUT and Python test module.

Inputs: toplevel (required), python_module (required), verilog_sources (required), simulator.

cocotb_list_testsA

Discovers all @cocotb.test() coroutines and their docstrings in a Python testbench file without executing simulation.

Inputs: test_file (required), cwd.

cocotb_runA

Compiles a Verilog DUT, executes an asynchronous Python cocotb testbench, and parses results into structured JSON test reports with assertion tracebacks.

Inputs: toplevel (required), python_module (required), verilog_sources (required), cwd, +3 more.

cocotb_toolchain_infoA

Returns active container or host execution runtime info and versions of Cocotb, Python, and simulator.

Inputs: no named parameters.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4/5.0

    Scored across 4 tools

    Disambiguation5/5

    Each tool targets a distinct stage of the Cocotb workflow: test discovery, Makefile generation, simulation execution, and environment introspection. There is no meaningful overlap between the tools.

    Naming Consistency4/5

    All tools share the cocotb_ prefix and mostly follow a verb_noun pattern. Minor deviations are cocotb_run (verb only) and cocotb_toolchain_info (noun phrase), but the names remain predictable and readable.

    Tool Count5/5

    Four tools is well-scoped for a focused Cocotb simulation server. Each tool covers a necessary part of the workflow without redundancy or bloat.

    Completeness5/5

    The set provides end-to-end coverage: discover tests, generate a runner, execute simulations with parsed results, and inspect the runtime environment. No obvious core operation is missing for the stated domain.

    Maintenance

    ActivitySlowing
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      C
      quality
      F
      maintenance
      Enables RTL simulation and hardware verification with Verilator through automatic testbench generation, natural language queries about simulations, waveform analysis, and protocol-aware testing for Verilog/SystemVerilog designs.
      4
      4
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Enables AI assistants to perform Electronic Design Automation (EDA) tasks including Verilog synthesis, simulation, ASIC design flows, and waveform analysis through a unified interface.
      6
      ISC
    • A
      license
      Not graded
      quality
      C
      maintenance
      Provides LLMs and AI agents safe, structured, read-only access to verification artifacts for deterministic triage and root-cause analysis. Supports UVM, cocotb, and SystemVerilog verification ecosystems.
      35 PyPI
      7
      Apache 2.0
    • A
      license
      A
      quality
      B
      maintenance
      Enables AI coding agents and IDEs to lint, compile, syntax-check, and simulate Verilog/SystemVerilog designs through structured, token-efficient MCP tools with isolated containerized toolchains.
      4
      15 npm
      Apache 2.0