This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
pforge is a zero-boilerplate framework for building Model Context Protocol (MCP) servers through declarative YAML configuration. It's built on pmcp (Pragmatic AI Labs MCP SDK) with strict PMAT quality enforcement.
Design Philosophy: Cargo Lambda simplicity × Flask ergonomics × Rust guarantees
# Continuous testing during development
cargo watch -x 'test --lib --quiet' -x 'clippy --quiet'
# Run all tests
cargo test --all
cargo test --all --release
# Fast development cycle
make dev # Runs continuous test + clippy watch# Full quality gate check (run before committing)
make quality-gate
# Individual quality checks
cargo fmt --check # Code formatting
cargo clippy -- -D warnings # Linting
cargo test --all # All tests
cargo tarpaulin --out Json # Code coverage (min 80%)
pmat analyze complexity --max 20 # Cyclomatic complexity
pmat analyze satd --max 0 # Technical debt comments
pmat analyze tdg --min 0.75 # Technical Debt Grade# Unit tests (< 1ms each)
cargo test --test unit
# Integration tests (< 100ms each)
cargo test --test integration
# Property-based tests
cargo test --test property --release -- --test-threads=1
# Mutation tests (target: 90%+ mutation kill rate)
cargo mutants --check# Run all benchmarks
cargo bench
# Specific benchmark suites
cargo bench --bench dispatch_benchmark
cargo bench --bench throughput_benchmark
# Performance regression check
make bench-check# Development build
pforge build --debug
# Release build
pforge build --release
# Run server
pforge serve
# Development mode with hot reload
pforge dev --watch# Verbose logging
RUST_LOG=pforge=trace pforge serve
# Flamegraph profiling
cargo flamegraph --bin pforge -- serve
# Memory profiling (valgrind)
valgrind --leak-check=full --show-leak-kinds=all target/release/pforge serve
# Heap profiling
cargo run --release --features dhat-heappforge CLI (Scaffold, Build, Dev, Test, Quality)
↓
pforge-codegen (YAML → Rust AST → Optimized Runtime)
↓
pforge-runtime (Handler Registry, Type-safe validation, Middleware, State)
↓
pmcp v1.6+ (TypedTool, Multi-transport, SIMD JSON parsing - 16x faster than TS SDK)
↓
MCP Protocol v2024-10-07 (JSON-RPC 2.0)
crates/
├── pforge-cli/ # CLI binary and commands (new, build, serve, dev, quality)
├── pforge-runtime/ # Core runtime (handler registry, transport, state, middleware)
├── pforge-codegen/ # Code generation (YAML → Rust AST → optimized runtime)
├── pforge-config/ # Configuration parsing and validation
├── pforge-macro/ # Procedural macros
└── pforge-quality/ # Quality enforcement and PMAT integration
bridges/ # Language bridges (Python, Go, Node.js)
examples/ # Example MCP servers
benches/ # Performance benchmarks
docs/ # Documentation
Handler Trait (pforge-runtime/src/handler.rs):
- Zero-cost abstraction compatible with pmcp TypedTool
- Type-safe Input/Output with JsonSchema generation
- Async by default via async_trait
HandlerRegistry (pforge-runtime/src/registry.rs):
- O(1) average-case lookup using FxHash (2x faster than SipHash for small keys)
- Compile-time optimized dispatch
- Future optimization: Perfect hashing (FKS algorithm) for O(1) worst-case
Configuration AST (pforge-config/src/types.rs):
- ForgeConfig: Root configuration structure
- ToolDef: Enum supporting Native, CLI, HTTP, and Pipeline handlers
- ParamSchema: Type-safe parameter definitions with validation
- Native: Rust handlers compiled into binary (fastest, < 1μs dispatch)
- CLI: CLI wrapper with streaming support
- HTTP: HTTP endpoint wrapper with auth support
- Pipeline: Tool composition pipeline with conditional execution
- NO
unwrap()calls in production code (only in tests) - NO
panic!()in production code - NO SATD (Self-Admitted Technical Debt) comments
- NO functions with cyclomatic complexity > 20
- Test coverage: ≥ 80% line coverage
- Technical Debt Grade (TDG): ≥ 0.75
- Mutation kill rate: ≥ 90%
- All error paths must have tests
Strict 5-minute cycle enforcement:
- RED (2 min max): Write failing test
- GREEN (2 min max): Minimum code to pass
- REFACTOR (1 min): Clean up, run quality gates
- COMMIT: If quality gates pass
- RESET: If cycle exceeds 5 minutes
Quality gate failures halt development (Jidoka/"stop the line" principle).
Automated quality enforcement via pre-commit hooks and Makefile targets:
# Run all quality gates
make quality-gate
# Individual PMAT checks
pmat analyze complexity --max-cyclomatic 20
pmat analyze satd
pmat tdg .
pmat analyze dead-codePre-Commit Hook (.git/hooks/pre-commit):
- Automatically runs on every commit
- Enforces: formatting, linting, tests, complexity, SATD, coverage, TDG
- Blocks commits that fail quality standards
- Bypass (NOT recommended):
git commit --no-verify
Quality Gate Test Suite (integration_test.rs):
- 8 tests verify PMAT integration
- Tests complexity enforcement, SATD detection, TDG calculation
- Validates pre-commit hook existence and executability
- Ensures quality-gates.yaml configuration is valid
Metrics Tracked:
- Cyclomatic Complexity: max 20 (current: 9)
- SATD Comments: Phase markers allowed
- TDG Score: min 75/100 (current: 96/100)
- Dead Code: monitored (current: 0%)
- Test Coverage: min 80% (current: 80.54%)
| Metric | Target |
|---|---|
| Cold start | < 100ms |
| Tool dispatch (hot) | < 1μs |
| Config parse | < 10ms |
| Schema generation | < 1ms |
| Memory baseline | < 512KB |
| Memory per tool | < 256B |
| Throughput (sequential) | > 100K req/s |
| Throughput (concurrent 8-core) | > 500K req/s |
All errors use thiserror with specific variants:
ToolNotFound: Requested tool doesn't existInvalidConfig: Configuration validation failedValidation: Parameter validation failedHandler: Handler execution errorTimeout: Operation exceeded timeoutBridgeError: Language bridge error
Never use unwrap() or expect() in production - always propagate errors or handle explicitly.
tests/
├── unit/ # Fast tests (< 1ms each) - config, registry, codegen
├── integration/ # Integration tests (< 100ms) - CLI, server, PMAT
├── property/ # Property-based tests using proptest
└── e2e/ # End-to-end tests - stdio, SSE, WebSocket transports
Use proptest for:
- Config roundtrip serialization
- Handler dispatch always returns valid JSON
- Parameter validation edge cases
All benchmarks in benches/ directory:
dispatch_benchmark.rs: Handler dispatch latencythroughput_benchmark.rs: Sustained throughput testingmemory_benchmark.rs: Memory usage profiling
Pre-commit hooks automatically run:
0. pmat validate-docs - Validate all markdown links (local & HTTP)
cargo fmt --check- Code formattingcargo clippy -- -D warnings- Lintingcargo test --all- All testspmat analyze complexity- Complexity check (≤20)pmat analyze satd- No technical debt commentscargo tarpaulin- Coverage check (≥80%)pmat analyze tdg- Technical Debt Grade (≥0.75)
Commits are blocked if any gate fails. This includes broken documentation links (both local files and external URLs with HTTP 404s).
GitHub Actions workflows (.github/workflows/):
ci.yml: Continuous integrationquality.yml: Quality gates + mutation tests + coverage uploadrelease.yml: Release automation
Performance regression fails if dispatch latency > 2μs.
Bridge architecture for polyglot handlers (Python, Go, Node.js):
- Thin FFI layer with stable C ABI
- Zero-copy parameter passing (pointers, not serialization)
- Error semantics preserved across language boundaries
- Type safety leveraged in target language
Bridge implementations in bridges/ directory.
YAML configuration defines MCP servers declaratively:
forge:
name: server-name
version: 0.1.0
transport: stdio|sse|websocket
optimization: debug|release
tools:
- type: native|cli|http|pipeline
name: tool_name
description: "Tool description"
handler: { ... }
params: { ... }
timeout_ms: 30000 # optional
resources: [ ... ] # optional
prompts: [ ... ] # optional
state: { ... } # optionalExtreme TDD + Lean Manufacturing Principles:
- Rapid feedback cycles (5-minute max)
- Quality built-in (Jidoka)
- Stop-the-line on quality failures
- Continuous improvement (Kaizen)
- Eliminate waste
- Amplify learning
Theoretical Foundation: Combines Beck's TDD with Toyota Production System (Poppendieck & Poppendieck, 2003: Lean Software Development).
make test- All tests passmake quality-gate- Full quality gatemake mutants- Mutation testsmake bench-check- Benchmark regression check- Update
Cargo.tomlversion - Update
CHANGELOG.md git tag -a v0.1.0 -m "Release v0.1.0"git push --tags- Publish crates in order: runtime → codegen → cli
Primary specification: docs/specifications/pforge-specification.md (comprehensive 2400+ line spec)
Examples in examples/:
hello-world/: Minimal viable serverpmat-server/: PMAT code analysis integrationpolyglot-server/: Multi-language bridge example
All code changes require a prior contract (provable-contract YAML or pmat work contract.json).
NEVER write code before defining the contract. Run pmat comply check before completing any task.
CB-1400 enforces agent contract existence; verification_level must be satisfied before merge.