pns-server MCP Server
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 |
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
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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