Knowledge Graph system for agentic AI context engineering
npm install kg-coderElite coding patterns from the world's best developers, delivered to your AI assistant.
kg-coder is a local-first knowledge graph system designed for agentic AI context engineering. It provides Claude Desktop and other MCP-compatible AI assistants with access to 115 elite coding patterns extracted from 13 legendary developers.
Each pattern includes:
- Problem - The specific issue the pattern solves
- Solution - The implementation approach
- Benefits - What the pattern enables
- Tradeoffs - What you sacrifice when using it
- Causality chains - Full reasoning path from problem to solution
- 115 Elite Patterns from 13 legendary developers (bellard, antirez, ryansolid, mitchellh, and more)
- MCP Server for seamless Claude Desktop integration
- Context-Aware Discovery - Patterns matched by file type, keywords, and problem description
- Full Causality Chains - Understand the "why" behind each pattern
- Local-First - Your data stays on your machine
- SQLite Backend - Fast, reliable, WAL-mode enabled
Add to your Claude Desktop configuration (~/Library/Application Support/Claude/claude_desktop_config.json):
``json`
{
"mcpServers": {
"kg-coder": {
"command": "node",
"args": ["/path/to/kg-coder/dist/mcp-server/index.js"],
"env": {
"KG_DATABASE_PATH": "/path/to/kg-coder/elite-patterns/patterns.db"
}
}
}
}
`bashClone the repository
git clone https://github.com/bradheitmann/kg-coder.git
cd kg-coder
Quick Start
Once installed in Claude Desktop, you can query patterns directly:
`
"What patterns solve rate limiting problems?"
"Show me patterns from antirez"
"How does bellard approach memory management?"
`Or use the MCP resources directly:
`
kg://patterns/context?ext=.tsx&keywords=state,reactive
kg://patterns/developer?dev=ryansolid&limit=5
kg://patterns/top?minWow=0.95
`Pattern Library
$3
| Developer | Known For | Patterns |
|-----------|-----------|----------|
| Fabrice Bellard | FFmpeg, QEMU, QuickJS | Systems programming, compression |
| Salvatore Sanfilippo (antirez) | Redis | Data structures, idempotency |
| Andrew Kelley | Zig | Comptime, error handling |
$3
| Developer | Known For | Patterns |
|-----------|-----------|----------|
| Ryan Carniato | SolidJS | Fine-grained reactivity |
| Rich Harris | Svelte | Compiler-driven UI |
| Evan You | Vue | Reactive systems |
| Mitchell Hashimoto | HashiCorp | Infrastructure patterns |
$3
| Developer | Known For | Patterns |
|-----------|-----------|----------|
| Matt Pocock (matklad) | rust-analyzer | IDE architecture |
| Tanner Linsley | TanStack | State management |
| Jarred Sumner | Bun | Runtime optimization |
| Simon Willison | Datasette | Data tooling |
| TJ Holowaychuk | Express, Koa | Node.js patterns |
MCP Tools
$3
| Tool | Description |
|------|-------------|
|
memory.upsert_entities | Create or update graph nodes |
| memory.upsert_edges | Create relationships between nodes |
| memory.invalidate_edges | Soft-delete edges (temporal versioning) |
| memory.query_subgraph | Query graph with traversal |
| context.assemble_pgn | Pack context for LLM consumption |
| memory.compact_session | Optimize session memory |$3
| Tool | Description |
|------|-------------|
|
patterns.find_for_problem | Find patterns by problem description |
| patterns.get_by_developer | Get patterns from specific developer |
| patterns.get_causality_chain | Get full causality chain for pattern |
| patterns.find_by_context | Find patterns by file/language context |
| patterns.search | Full-text pattern search |MCP Resources
$3
| Resource | Description |
|----------|-------------|
|
kg://graph/stats | Graph statistics (nodes, edges, tokens) |
| kg://graph/entities | Entity listing with filtering |
| kg://graph/neighborhood | K-hop expansion from seeds |
| kg://graph/temporal | Time-slice graph state |
| kg://graph/clusters | Spectral clustering view |
| kg://graph/ranking | Marginal utility ranking |
| kg://graph/paths | Shortest path finder |
| kg://server/info | Server version and capabilities |$3
| Resource | Description |
|----------|-------------|
|
kg://patterns/context | Context-aware pattern discovery |
| kg://patterns/developer | Patterns by developer |
| kg://patterns/top | Highest-rated patterns |
| kg://patterns/problems | Problem-organized index |
| kg://patterns/chain | Full causality chains |
| kg://patterns/developers | Available developer listing |Configuration
$3
| Variable | Description | Default |
|----------|-------------|---------|
|
KG_DATABASE_PATH | Path to SQLite database | ~/.kg-coder/memory.db |
| KG_VERBOSE | Enable verbose logging | false |$3
`bash
kg-coder-mcp --db /path/to/database.db --verbose
`| Argument | Description |
|----------|-------------|
|
--db, --database | Database file path |
| --verbose, -v | Enable verbose logging |
| --help, -h | Show help |Database Schema
kg-coder uses SQLite with:
- WAL mode for concurrent access
- Foreign key constraints for referential integrity
- 13 indexes for query performance
- Temporal versioning for edge history
$3
| Metric | Value |
|--------|-------|
| Nodes | 381 |
| Edges | 335 |
| Entity Types | 20 |
| Predicates | 31 |
Serialization Formats
kg-coder supports multiple formats for context packing:
- PGN (Prompt Graph Notation) - Markdown for LLMs
- TOON (Tokens Optimized Notation) - CSV tables for efficiency
- GGN (Graph Grammar Notation) - Schema-first format
- JSON - Native format
Development
`bash
Development mode (watch)
pnpm devRun tests
pnpm testRun tests with coverage
pnpm test:coverageType check
pnpm typecheckLint
pnpm lint
`Project Structure
`
kg-coder/
├── src/
│ ├── core/ # Core types and models
│ ├── storage/ # SQLite database layer
│ ├── serialization/ # PGN, TOON, GGN formats
│ ├── mcp-server/ # MCP server implementation
│ ├── tools/ # MCP tool handlers
│ └── import/ # Data import pipeline
├── elite-patterns/ # Pattern database
├── tests/ # Test suite
└── docs/ # Documentation
``See CONTRIBUTING.md for development setup and guidelines.
See SECURITY.md for security model and vulnerability reporting.
MIT - see LICENSE
This project extracts and organizes coding patterns from publicly available talks, blog posts, and open-source code by the developers listed above. All attribution is preserved in the pattern metadata.
---
Built with care by OKOA Labs