Midnight MCP - AI-assisted development for Compact smart contracts
AI coding assistants like Claude, GitHub Copilot, and Cursor have transformed how developers write code. But they have a fundamental limitation: they only know what was in their training data.
Compact, Midnight's smart contract language, isn't in that training data. When you ask an AI assistant to write a Compact contract, it hallucinates. It invents syntax that doesn't exist, references functions that were never defined, and produces code that fails at compile time.
Midnight MCP solves this problem.
What is MCP?β
The Model Context Protocol (MCP) is an open standard that allows AI assistants to access external tools and data sources. Instead of relying solely on training data, an AI assistant with MCP can query live documentation, search codebases, and call APIs.
Midnight MCP is an MCP server purpose-built for Midnight development. It gives AI assistants:
- Indexed knowledge of 102 Midnight repositories
- Real compiler validation before showing you code
- Semantic search across documentation and examples
- Version-aware syntax references for Compact
When you ask Claude to write a Compact contract, it queries Midnight MCP for the correct syntax, generates the code, validates it against the real compiler, and only shows you working code.
The problem with AI-generated Compact codeβ
Consider this prompt:
"Write a simple counter contract in Compact"
Without Midnight MCP, an AI assistant might generate:
contract Counter {
state count: Int = 0;
function increment(): Void {
count = count + 1;
}
}
This looks plausible. It's also completely wrong:
- Compact uses
ledgerfor state, notstate. - There is no
Inttype in Compact. It usesUint<32>,Field, and other specific types. Voiddoesn't exist. Compact uses[]for the unit type.- State mutations require witness functions, not direct assignment.
The AI hallucinated a language that resembles Solidity but isn't Compact. A developer unfamiliar with Compact might spend hours debugging code that was never valid.
Install Midnight MCPβ
Midnight MCP requires no API keys and installs in under 60 seconds. Add the appropriate configuration to your AI assistant based on the tool you use.
Claude Desktopβ
On macOS, edit ~/Library/Application Support/Claude/claude_desktop_config.json. Add the following configuration to enable Midnight MCP:
{
"mcpServers": {
"midnight": {
"command": "npx",
"args": ["-y", "midnight-mcp@latest"]
}
}
}
Cursorβ
Create or edit .cursor/mcp.json in your project root. You can also configure it globally at ~/.cursor/mcp.json on macOS/Linux or %USERPROFILE%\.cursor\mcp.json on Windows. Add the following configuration:
{
"mcpServers": {
"midnight": {
"command": "npx",
"args": ["-y", "midnight-mcp@latest"]
}
}
}
VS Code with GitHub Copilotβ
Create or edit .vscode/mcp.json in your project. Add the following configuration to connect Copilot to Midnight MCP:
{
"servers": {
"midnight": {
"command": "npx",
"args": ["-y", "midnight-mcp@latest"]
}
}
}
After adding the configuration, restart your AI assistant. You now have access to 29 Midnight-specific tools.
How Midnight MCP worksβ
Midnight MCP operates as a local server that connects your AI assistant to Midnight's ecosystem.

When you ask for a Compact contract:
- The AI assistant calls
midnight-get-latest-syntaxto retrieve current Compact syntax. - It generates code using the correct patterns.
- It calls
midnight-compile-contractto validate against the real compiler. - If compilation fails, it reads the error, fixes the code, and retries.
- You receive verified, working code.
This compile-validate-fix loop happens automatically. You never see the broken intermediate versions.
Real compiler integrationβ
Most code-generation tools rely on pattern matching and hope. Midnight MCP validates code against the actual Compact compiler hosted.
The compiler catches errors that static analysis cannot, including:
- Type mismatches: Using
FieldwhereUint<64>is expected - Sealed field violations: Attempting to access sealed state incorrectly
- Disclose rule errors: Missing or malformed privacy annotations
- Unbound identifiers: References to undefined variables or types
When the compiler returns an error, the response includes the exact line number and column:
success: false
message: "Line 12:8 - unbound identifier 'totalSupply'"
errorDetails:
line: 12
column: 8
errorType: error
The AI assistant uses this information to fix the code and try again.
Graceful fallbackβ
If the hosted compiler is unavailable, Midnight MCP falls back to static analysis. The response indicates which validation method was used:
validationType: "compiler" # Real compiler validation
validationType: "static-analysis-fallback" # Compiler unavailable
You always receive validation. The tool never fails silently.
Semantic search across 102 repositoriesβ
Today, Midnight MCP indexes every non-archived repository in the Midnight ecosystem:
- All 88 repositories from
midnightntwrk. - 14 community and partner repositories, including OpenZeppelin contracts and hackathon winners.
The search is semantic, not keyword-based. For example, a prompt like "find code that handles shielded transactions" returns relevant results even if those exact words don't appear in the code.
Prompt: "How do I implement a token with transfer limits?"
midnight-search-compact returns:
- Token contract examples from midnight-examples
- Rate limiting patterns from community repos
- Relevant documentation sections
29 tools for Midnight developmentβ
Midnight MCP provides 29 tools organized by function.
Search toolsβ
Use these tools to find code, documentation, and examples across the Midnight ecosystem.
| Tool | Purpose |
|---|---|
midnight-search-compact | Search Compact language code across indexed repos |
midnight-search-docs | Search official Midnight documentation |
midnight-search-typescript | Search TypeScript SDK implementations |
midnight-fetch-docs | Fetch live documentation from docs.midnight.network |
Analysis toolsβ
Use these tools to validate, analyze, and review Compact contracts.
| Tool | Purpose |
|---|---|
midnight-compile-contract | Validate code against the real Compact compiler |
midnight-analyze-contract | Run 15 static security checks |
midnight-review-contract | AI-powered security review |
midnight-extract-contract-structure | Parse contract structure and exports |
Generation toolsβ
Use these tools to create new contracts and documentation.
| Tool | Purpose |
|---|---|
midnight-generate-contract | Generate contracts from natural language descriptions |
midnight-document-contract | Generate documentation in Markdown or JSDoc format |
Repository toolsβ
Use these tools to access files and syntax references from Midnight repositories.
| Tool | Purpose |
|---|---|
midnight-get-file | Retrieve files from any indexed Midnight repository |
midnight-get-file-at-version | Get file content at a specific version |
midnight-compare-syntax | Compare syntax between Compact versions |
midnight-get-latest-syntax | Current Compact syntax reference |
midnight-get-repo-context | Everything needed to start coding (compound tool) |
midnight-list-examples | List available example contracts |
Version management toolsβ
Use these tools to manage upgrades and track changes between Compact versions.
| Tool | Purpose |
|---|---|
midnight-upgrade-check | Full upgrade analysis (compound tool) |
midnight-check-breaking-changes | Identify breaking changes between versions |
midnight-get-migration-guide | Step-by-step migration instructions |
Resources and promptsβ
Beyond tools, Midnight MCP provides nine built-in resources and five interactive prompts.
Resources are always-available references that provide quick access to syntax and examples:
midnight://syntax/latest Current Compact syntax
midnight://examples/counter Counter contract example
midnight://examples/token Token contract example
midnight://docs/compact Compact language reference
Prompts are templates for common tasks that guide you through specific workflows:
create-compact-contract Start a new contract
debug-compact-error Fix compilation errors
security-review Full security audit
compare-compact-versions Migration assistance
Architectureβ
Midnight MCP is built for reliability:
- Token efficiency: Outputs YAML by default (20-30% fewer tokens than JSON)
- Compound tools: Single calls that combine multiple operations
- Graceful degradation: Falls back to cached data when services are unavailable
- Progress notifications: Real-time updates during long operations
The codebase is fully tested with 206 tests across 10 test suites.
What's nextβ
Midnight MCP is open source and actively developed. The roadmap includes:
- Full ZK circuit output parsing from compiler results.
- Contract deployment directly from AI chat.
- TypeScript SDK integration for automatic prover code generation.
- Local devnet interaction for querying balances and submitting transactions.
Learn moreβ
Explore the source code and contribute:
β npm package
Midnight MCP is a community project. Contributions, issues, and feature requests are welcome.