About ngspice-mcp
ngspice-mcp exposes ngspice circuit simulation through an MCP server for AI language models and other MCP clients. It supports loading netlists, running simulations, and retrieving plotted vector data.
Key features
- 01Load circuits and netlists
- 02Run ngspice simulations
- 03List plots and vectors
- 04Retrieve vector data in multiple formats
- 05Read stdout and stderr resources
Use cases
- 01Load a circuit netlist for simulation
- 02Run DC, AC, or transient analyses
- 03Retrieve selected simulation vectors and intervals
MCP support
Provides MCP tools for circuit loading, simulation, and data retrieval, along with stdout, stderr, and usage resources.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEngspice-mcp
A Model Context Protocol (MCP) server that provides access to ngspice circuit simulation functionality through a standardized protocol interface. This server enables AI language models to interact with ngspice in a controlled and structured way.
Features
- Integration with ngspice's shared library interface
- Standardized MCP protocol implementation
- Synchronous operation with structured data access
- Comprehensive output capture and redirection
- Vector data handling with multiple representation formats
- Support for both server and library usage modes
- Built-in test suite
Requirements
- D compiler (DMD/LDC)
- ngspice shared library
- MCP server library (d-mcp-server)
- D build system (dub)
Installation
- Ensure system requirements are installed
- Clone the repository
- Build using dub:
dub build --config=server
Usage
The server can be started with:
./ngspice-mcp [options]
Command Line Options
--working-dir,-d: Set the working directory for circuit files (default: current directory)
Available Tools
Circuit Loading
loadCircuit: Load circuit netlists directlyloadNetlistFromFile: Load netlists from files
Example netlist:
RC Circuit
R1 in out 1k
C1 out 0 1u
.end
Simulation
runSimulation: Execute simulation commands
Common commands:
op: DC operating pointdc source start stop stepac dec points fstart fendtran step tstop
Data Access
getPlotNames: List available simulation plotsgetVectorNames: List vectors in a specific plotgetVectorData: Retrieve vector data with options for:- Magnitude-phase representation
- Rectangular (real-imaginary) representation
- Both representations
- Optional interval selection
Resources
stdout://: Standard output stream from ngspicestderr://: Error output stream from ngspiceusage://: Comprehensive usage guide
Development
Project Structure
ngspice-mcp/
├── source/
│ ├── app.d # Main application
│ ├── bindings/ # ngspice C API bindings
│ ├── database/ # SQLite database handling
│ ├── parser/ # Netlist parsing
│ └── server/ # MCP server implementation
├── resources/ # Resource files
└── bin/ # Build outputs
Build Configurations
- Server Mode
dub build --config=server
- Library Mode
dub build --config=library
- Unit Tests
dub test --config=unittest
Testing
Run the test suite:
dub test
Tests cover:
- ngspice bindings
- Server functionality
- Tool validation
- Resource handling
- Error cases
Technical Details
Architecture
The server implements several key components:
-
NgspiceServer: Core server implementation
- Tool registration and handling
- Resource management
- Output stream capture
- Vector data processing
-
Output System
- Stdout/stderr capture
- Stream buffering
- Resource notification
-
Vector Processing
- Complex number handling
- Scientific notation formatting
- Interval selection
- Multiple representation formats
Database System
- Model parameter storage
- Efficient indexing and querying
- Transaction support
- Concurrent access handling
License
MIT License - see dub.json for details.
Copyright © 2024, Garret Noble
Contributing
Contributions are welcome! Please ensure:
- Code follows project style and standards
- Tests are included for new functionality
- Documentation is updated as needed
- Commit messages are clear and descriptive
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.