pns-server MCP Server
Allows using locally hosted Ollama models as the provider for the AI agent that converts natural language descriptions into Petri net models.
Allows using OpenAI's LLM models as the provider for the AI agent that converts natural language descriptions into Petri net models; also provides an OpenAI-compatible API endpoint for chat completions.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@pns-server MCP ServerModel a queue with two servers and a buffer"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
pns-server
Backend service that converts natural language descriptions of production and queueing systems into Petri net models exported in PNML format (compatible with TINA, PetriObjModel, CPN Tools).
Web UI: pns-ui-web
Stack
Layer | Technology |
Runtime | Python 3.13 |
Web framework | FastAPI + Uvicorn |
AI agent | LangGraph + LangChain |
LLM providers | OpenAI, Anthropic, Ollama |
Database | PostgreSQL (async via SQLAlchemy + asyncpg) |
Session cache | Redis |
Protocol | OpenAI-compatible REST + MCP (Model Context Protocol) |
Migrations | Alembic |
Related MCP server: FlexSim MCP Server
Quick start (Docker)
Local — single command, auto-generated secrets
Runs PostgreSQL + backend. No Redis. Every user provides their own LLM API key via the Settings page.
docker compose -f docker-compose.local.yml up -d
# View auto-generated secrets on first start
docker compose -f docker-compose.local.yml logs app | grep -A 10 "AUTO-GENERATED"
# Health check
curl http://localhost:8000/healthProduction — with Redis, PostgreSQL, Nginx
cp .env.example .env
# Fill in all required values in .env
docker compose -f docker-compose.prod.yml up -d
docker compose -f docker-compose.prod.yml psNginx reverse proxy config:
server {
listen 80;
server_name your-domain.com;
location /api/ { proxy_pass http://127.0.0.1:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; }
location /health { proxy_pass http://127.0.0.1:8000; }
location /mcp {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_read_timeout 3600s;
proxy_buffering off;
proxy_cache off;
chunked_transfer_encoding on;
}
}Scale workers (default: 2):
UVICORN_WORKERS=4 docker compose -f docker-compose.prod.yml up -d backendLocal development
# Install dependencies (uv package manager)
uv sync --extra dev
# Start dependencies
docker compose up -d
# Apply migrations
uv run alembic upgrade head
# Start server with hot reload
uv run uvicorn main:app --reload --host 0.0.0.0 --port 8000
# Run tests
uv run pytest -vAPI
OpenAI-compatible
Method | Path | Description |
POST |
| Chat completion (stream/non-stream) |
GET |
| List available models |
GET |
| Download generated PNML file |
Auth: Authorization: Bearer sk-...
Auth & API Keys
Method | Path | Description |
POST |
| Register |
POST |
| Log in, returns JWT pair |
POST |
| Refresh tokens |
GET |
| Current user |
POST |
| Create API key |
GET |
| List API keys |
DELETE |
| Revoke API key |
LLM Credentials (BYOK)
Method | Path | Description |
POST |
| Store encrypted LLM API key |
GET |
| List profiles |
PATCH |
| Update profile |
DELETE |
| Delete profile |
POST |
| Verify connectivity |
Sessions & Simulation
Method | Path | Description |
GET |
| List user sessions |
GET |
| Get session |
POST |
| Run simulation (SSE stream) |
GET |
| List net snapshots |
Health
Method | Path | Description |
GET |
| Liveness probe |
GET |
| Readiness probe (checks DB + Redis) |
MCP Server (Model Context Protocol)
The MCP server is mounted at /mcp on the main port and also available standalone.
Mode | Command | Endpoint |
Unified (default) |
|
|
Standalone HTTP |
|
|
Standalone stdio |
| — |
The MCP server exposes 50+ tools for Petri net construction, simulation, and export directly to MCP-compatible clients.
Architecture
src/
├── api/ # Common API infrastructure (health, versioning, middleware)
├── openai_api/ # OpenAI-compatible protocol (chat completions, models, files)
├── core/ # Config, DI, logging, lifecycle
├── domain/ # Pure domain logic
│ ├── models/ # PetriNet, Place, Transition, Arc
│ ├── patterns/ # 29 reusable Petri net building blocks
│ └── layout/ # Sugiyama hierarchical layout algorithm
├── infrastructure/ # PostgreSQL (SQLAlchemy) + Redis
├── mcp/ # MCP server — tools, resources, prompts
└── services/
├── agent/ # LangGraph workflow (graph, nodes, tools)
├── chat/ # Chat orchestration, session management
├── petri/ # Builder, Optimizer, PNML exporter
├── simulation/ # Discrete-event Petri net simulator
├── llm/ # Per-credentials LLM factory (OpenAI / Anthropic / Ollama)
├── crypto/ # Fernet encryption for stored API keys
├── usage/ # Free-tier Redis counters
└── auth/ # JWT, API keys, OAuthPetri net patterns (29 total)
Core: Generator, Machine, Controller, Assembly, Router, Terminator, Buffer, BoundedQueue
Flow control: PriorityChoice, ThresholdActivation, Merge, Duplicate
Advanced: QualityCheck, FeedbackLoop, Conveyor, ConveyorWorkstation, TransportAgent
Batching: Batch, Unbatch, TimedBatch
Reliability: Breakdown, ScheduledAvailability, PreemptiveMachine, SetupMachine
Queueing: RenegingQueue, BalkingQueue, MultiResource, ServerVacation, NonstationaryGenerator
Key environment variables
Variable | Default | Description |
|
| Environment ( |
|
| LLM provider ( |
|
| Model name |
| — | OpenAI API key |
| — | Anthropic API key |
| — | PostgreSQL connection |
| — | Redis connection |
|
| Enable Redis |
| — | JWT signing key (min 32 chars) |
|
| Require user-provided LLM credentials |
|
| Encryption mode ( |
| — | 32-byte base64 key for Fernet |
| — | Optional external simulation backend |
See .env.example for the full reference.
CI/CD
Push to main → GitHub Actions builds Docker image → pushes to ghcr.io → deploys via SSH.
Required GitHub secrets: SERVER_HOST, SERVER_USER, SERVER_SSH_KEY, DEPLOY_PATH.
License
MIT
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
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/petri-net-sim/pns-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server