MCP Server for AI assisted Nim Programming
NimGenie is a Model Context Protocol (MCP) server that provides AI assistants with deep understanding of Nim codebases through intelligent code analysis, symbol indexing, and development assistance.
NimGenie bridges the gap between AI assistants and Nim development by providing MCP tools for the LLM to use to:
- Intelligent Symbol Search: Find functions, types, and variables across your entire codebase and dependencies
- Real-time Code Analysis: Perform syntax checking and semantic validation using the Nim compiler
- Dependency Management: Automatic discovery and indexing of Nimble packages
- Multi-Project Support: Work with multiple Nim projects simultaneously
- Persistent Storage: TiDB-backed symbol database that survives server restarts
- Search symbols by name, type, or module across your entire codebase
- Automatic indexing of project dependencies and Nimble packages
- Cross-reference functionality to understand code relationships
- Dependency-based incremental indexing that only re-indexes changed files and their dependents
- Syntax and semantic checking with detailed error reporting
- Project statistics and codebase metrics
- Nimble package management (install, search, upgrade)
- Project creation and build automation
- Dependency-based incremental indexing for efficient re-indexing
- Serve project files and assets as MCP resources
- Screenshot workflow support for game development
- Directory-based resource organization
- Nim 2.2.4+: Install from nim-lang.org
- TiDB: For persistent storage (see setup below)
- Ollama: For running a local LLM to perform embeddings
NimGenie uses TiDB for persistent storage. The easiest way to get started running Tidb locally is with TiUP:
# Install TiUP (TiDB cluster management tool)
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
# Start a persistent TiDB playground for Nimgenie (includes TiDB, TiKV, PD)
tiup playground --tag nimgenieThis starts TiDB on localhost:4000 with default settings (user: root, password: empty).
# Clone the repository
git clone https://github.com/gokr/nimgenie
cd nimgenie
# Build the MCP server
nimble build
# Run NimGenie
./nimgenie
# Install globally
nimble installNimGenie can be configured via environment variables or command-line options.
| Variable | Description | Default |
|---|---|---|
TIDB_HOST |
Database host | localhost |
TIDB_PORT |
Database port | 4000 |
TIDB_USER |
Database user | root |
TIDB_PASSWORD |
Database password | (empty) |
TIDB_DATABASE |
Database name | nimgenie |
TIDB_POOL_SIZE |
Connection pool size | 10 |
Command-line options:
Usage: nimgenie [OPTIONS]
Options:
-h, --help Show help message
-v, --version Show version information
-p, --port <number> MCP server port (default: 8080)
--host <address> Host address (default: localhost)
--project <path> Project directory (default: current directory)
--verbose Enable verbose logging
--database-host TiDB host (default: localhost)
--database-port TiDB port (default: 4000)
--no-discovery Disable Nimble package discovery
For some feeling how to use Nimgenie, see the tutorial.
NimGenie is built with Nimcp, a library that makes it easy to build MCP servers. We mostly call out to Nim tools like nimble and the Nim compiler etc to perform indexing and other tasks. The database used is Tidb because it is MySQL compatible, fully Open Source, can run locally or is also available in the cloud and supports vector based searching and more. Embeddings are calculated via Ollama with an embeddings LLM running, typically locally.
NimGenie uses the Nim compiler's built-in dependency analysis (nim genDepend) to track file dependencies efficiently. This enables:
- Incremental indexing: Only re-index files that have changed and their dependents
- Accurate dependency tracking: Leverages the compiler's understanding of imports and modules
- Efficient updates: Avoids full re-indexing on every change
- Cascade changes: Automatically identifies all files affected by a dependency change
The dependency information is stored in the TiDB database with tables for:
file_dependency: Tracks source → target file dependenciesfile_modification: Stores file modification times, sizes, and hashes
This approach is more reliable than manual file hash/modification tracking as it uses the compiler's own dependency analysis, handling complex import scenarios correctly.
We welcome contributions! Please see our development documentation in CLAUDE.md for detailed information about the codebase architecture and development guidelines.
MIT License - see LICENSE file for details.
- Nimcp: github.com/gokr/nimcp
- MCP Protocol: modelcontextprotocol.io
- Nim Language: nim-lang.org
- TiDB Database: pingcap.com