midnight-mcp
The Midnight MCP server gives AI assistants tools to search, analyze, compile, generate, and manage Midnight blockchain contracts, SDKs, and documentation.
🔍 Search & Discovery
Search Compact smart contract code, TypeScript SDK, and official documentation semantically
Fetch live documentation directly from
docs.midnight.networkExplore 115+ indexed Midnight repositories
🔧 Contract Analysis & Compilation
Static analysis of contract structure, security patterns, and common syntax errors (
analyze-contract,extract-contract-structure)Plain-language explanations of Compact circuits, including ZK proof and privacy implications (
explain-circuit)Real compilation via a hosted service: fast syntax validation (~1–2s) or full ZK circuit generation (~10–30s), with fallback to static analysis (
compile-contract)
🤖 AI-Powered Generation (requires client sampling)
Generate Compact smart contracts from natural language requirements (
generate-contract)Security review for vulnerabilities, logic errors, and best practices (
review-contract)Generate Markdown or JSDoc documentation for contracts (
document-contract)
📁 Repository Access
Retrieve specific files from Midnight repositories, optionally at a specific version or line range (
get-file,get-file-at-version)Browse example contracts and DApps with complexity ratings (
list-examples)Get recent commits and changes across repositories (
get-latest-updates)
📦 Version & Migration
Get version info, release notes, and breaking changes (
get-version-info,check-breaking-changes)Obtain step-by-step migration guides between versions (
get-migration-guide)Diff files between versions and get an authoritative Compact syntax reference to prevent hallucinations (
compare-syntax,get-latest-syntax)
⚡ Compound Tools (token-efficient)
Combined version check + breaking changes + migration guide in one call, ~60% token savings (
upgrade-check)Version info + syntax reference + examples in one call for starting a coding session, ~50% token savings (
get-repo-context)
🩺 Health & Status
Monitor server health, API connectivity, rate limits, and cache statistics (
health-check,get-status)Check if the installed midnight-mcp is up to date against the npm registry (
check-version)
🧭 Tool Discovery
Browse 7 logical tool categories and their tools (
list-tool-categories,list-category-tools)Describe your intent in natural language and get tool recommendations (
suggest-tool)
Provides embedded resources with OpenZeppelin contract templates and documentation for use in Midnight smart contract development.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@midnight-mcp search for compact contracts"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Midnight MCP Server
⚠️ Deprecated — use Kapa + Midnight Expert
midnight-mcp is being wound down. Midnight has standardised on two official tools:
Kapa MCP (docs Q&A / search):
claude mcp add --transport http midnight https://midnight.mcp.kapa.aiMidnight Expert (hands-on dev, Claude Code plugins):
curl -fsSL https://midnightntwrk.expert/install.sh | bashMigration guide → https://docs.midnight.network/blog/migrating-to-kapa-and-midnight-expert
MCP server that gives AI assistants access to Midnight blockchain—search contracts, analyze code, and explore documentation.
This project extends the Midnight Network with additional developer tooling.
Related MCP server: Solana DeFi Intelligence MCP Server
Requirements
Node.js 20+ (LTS recommended)
Check your version: node --version
If you use nvm, Claude Desktop may not see your nvm-managed Node. Use this config instead:
{
"mcpServers": {
"midnight": {
"command": "/bin/sh",
"args": [
"-c",
"source ~/.nvm/nvm.sh && nvm use 20 >/dev/null 2>&1 && npx -y midnight-mcp@latest"
]
}
}
}Quick Start
Claude Desktop
Add to your claude_desktop_config.json:
{
"mcpServers": {
"midnight": {
"command": "npx",
"args": ["-y", "midnight-mcp@latest"]
}
}
}Config file locations:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.jsonLinux:
~/.config/Claude/claude_desktop_config.json
Cursor
One-click install:
Or manually add to .cursor/mcp.json:
{
"mcpServers": {
"midnight": {
"command": "npx",
"args": ["-y", "midnight-mcp@latest"]
}
}
}VS Code Copilot
Add to .vscode/mcp.json or use Command Palette: MCP: Add Server → "command (stdio)" → npx -y midnight-mcp@latest
Windsurf
Add to ~/.codeium/windsurf/mcp_config.json:
{
"mcpServers": {
"midnight": {
"command": "npx",
"args": ["-y", "midnight-mcp@latest"]
}
}
}No API keys required. Restart your editor after adding the config.
Why
@latest? Unlike cached npx packages that never auto-update,@latestensures you get new features and fixes on each restart. If upgrading from an older config without@latest, also clear your npx cache:rm -rf ~/.npm/_npx
What's Included
29 Tools
Category | Tools | Description |
Search |
| Semantic search + live docs fetching |
Analysis |
| Static analysis + real compilation |
Repository |
| Access files and examples |
Versioning |
| Version tracking and migration |
AI Generation |
| AI-powered code generation (requires sampling) |
Compound |
| Multi-step operations (saves 50-70% tokens) |
Health |
| Server status and version checking |
Discovery |
| Explore available tools and get recommendations |
All tools are prefixed with midnight- (e.g., midnight-search-compact).
Real Contract Compilation
The midnight-compile-contract tool validates Compact code using a hosted compiler service:
✅ Compilation successful (Compiler v0.29.0) in 2841msFast mode (
skipZk=true): Syntax validation in ~1-2 secondsFull mode (
fullCompile=true): Complete ZK circuit generation in ~10-30 secondsAutomatic fallback: Falls back to static analysis if the compiler service is unavailable
This catches semantic errors that static analysis misses (sealed fields, disclose rules, type mismatches).
MCP Capabilities
Capability | Feature |
Tools | 29 tools with |
Resources | 9 embedded resources with subscription support |
Prompts | 5 workflow prompts |
Logging | Client-controllable log level |
Completions | Autocomplete for prompt arguments |
Progress | Real-time progress for compound tools |
Sampling | AI-powered generation (when client supports it) |
9 Embedded Resources
Quick references available offline:
Compact syntax guide (v0.16-0.21)
SDK API reference
OpenZeppelin contracts
Tokenomics overview
Wallet integration
Common errors & solutions
Static Analysis
extract-contract-structure catches common mistakes before compilation:
Check | Severity | Description |
| P0 | Catches |
| P0 | Catches |
| P0 | Catches old pragma → use |
| P1 | Enums need |
| P0 | Use |
+ 10 more checks | P1-P2 | Overflow, division, assertions, etc. |
5 Prompts
create-contract— Generate new contractsreview-contract— Security and code reviewexplain-concept— Learn Midnight conceptscompare-approaches— Compare implementation patternsdebug-contract— Troubleshoot issues
Indexed Repositories
The API indexes 115+ Midnight repositories from the entire Midnight ecosystem:
Category | Count | Key Repositories |
Compact Language | 6 |
|
SDKs & APIs | 5 |
|
Core Infrastructure | 9 |
|
ZK & Cryptography | 6 |
|
Documentation | 5 |
|
Examples & Templates | 18 |
|
Identity | 5 |
|
Developer Tools | 5 |
|
Solutions & Apps | 7 |
|
Glacier Drop | 15 |
|
Partners & Community | 20 | OpenZeppelin, BrickTowers, MeshJS, PaimaStudios, hackathon winners, Olanetsoft |
Other | 18+ | Contracts, bridges, token distribution, monitoring, QA tools, community projects |
All non-archived repositories from the midnightntwrk organization plus community partners. See api/README.md for the complete list.
Advanced Configuration
HTTP Mode
Run as an HTTP server for web integrations or remote deployment:
# Start HTTP server on port 3000
npx midnight-mcp --http --port 3000Endpoints:
/health- Health check/mcp- Streamable HTTP (MCP protocol)/sse- Server-Sent Events
CLI Options
npx midnight-mcp --help
Options:
--stdio Use stdio transport (default, for Claude Desktop)
--http Use HTTP transport with SSE support
--port <number> HTTP port (default: 3000)
--json Output in JSON (default: YAML for better LLM efficiency)
--github-token GitHub token (overrides GITHUB_TOKEN env var)
-h, --help Show help
-v, --version Show versionWhy YAML by default? YAML is ~20-30% more token-efficient than JSON, which means AI assistants can process more context from tool responses.
Local Mode
Run everything locally for privacy or offline use:
{
"mcpServers": {
"midnight": {
"command": "npx",
"args": ["-y", "midnight-mcp@latest"],
"env": {
"MIDNIGHT_LOCAL": "true",
"OPENAI_API_KEY": "sk-...",
"CHROMA_URL": "http://localhost:8000"
}
}
}
}Requires ChromaDB (docker run -d -p 8000:8000 chromadb/chroma) and OpenAI API key.
GitHub Token
Add "GITHUB_TOKEN": "ghp_..." for higher GitHub API rate limits (60 → 5000 requests/hour).
Developer Setup
git clone https://github.com/Olanetsoft/midnight-mcp.git && cd midnight-mcp
npm install && npm run build && npm test
# Lint & format
npm run lint # ESLint (typescript-eslint)
npm run lint:fix # Auto-fix lint issues
npm run format # PrettierThe hosted API runs on Cloudflare Workers + Vectorize. See api/README.md for backend details.
Links
License
MIT
Stargazers ⭐️
Available Tools
30 toolsmidnight-analyze-contractARead-onlyIdempotent
⚠️ STATIC ANALYSIS ONLY - Analyze contract structure and patterns. 🚫 THIS DOES NOT COMPILE THE CONTRACT. Cannot catch: sealed field rules, disclose() requirements, semantic errors. 👉 Use 'midnight-extract-contract-structure' for pre-compilation checks.
Use this for: understanding structure, security pattern analysis, recommendations. NEVER claim a contract 'works' or 'compiles' based on this tool alone.
USAGE GUIDANCE: • Call once per contract - results are deterministic • For security review, also use midnight-review-contract (requires sampling) • Run before making changes, not repeatedly during iteration
Inputs: code (required), checkSecurity. Returns: Detailed contract analysis with security findings
midnight-auto-update-configARead-onlyIdempotent
⚠️ DEPRECATED: Auto-update is NOT possible because AI agents run in sandboxed environments without access to local filesystems. Instead, tell users to manually update their config to use midnight-mcp@latest, then run: rm -rf ~/.npm/_npx && restart their editor. This tool only returns config file paths for reference.
Inputs: no named parameters. Returns: instruction, platform, configPaths, searchAndReplace, +2 more
midnight-check-breaking-changesARead-only
Check if there are breaking changes between your current version and the latest release. Essential before upgrading dependencies.
Inputs: repo (required), currentVersion (required).
midnight-check-versionARead-onlyIdempotent
🔄 Check if you're running the latest version of midnight-mcp. Compares your installed version against npm registry and provides update instructions if outdated. Use this if tools seem missing or you want to ensure you have the latest features.
Inputs: no named parameters. Returns: currentVersion, latestVersion, isUpToDate, message, +2 more
midnight-compare-syntaxARead-onlyIdempotent
Compare a file between two versions to see what changed. Use this before recommending code patterns to ensure they work with the user's version.
Inputs: repo (required), path (required), oldVersion (required), newVersion.
midnight-compile-contractARead-onlyIdempotent
🔧 REAL COMPILATION - Compile Compact code using the hosted compiler service.
Unlike static analysis tools, this ACTUALLY COMPILES the contract and returns real compiler errors.
Use this to: • Validate that generated code compiles before showing to users • Get actual compiler error messages with line numbers • Check if a contract is syntactically and semantically correct
Options: • skipZk=true (default): Fast syntax validation only (~1-2s) • fullCompile=true: Full compilation with ZK circuit generation (~10-30s)
FALLBACK BEHAVIOR: • If the compiler service is unavailable, automatically falls back to static analysis • Check 'validationType' in response: 'compiler' = real compilation, 'static-analysis-fallback' = fallback mode • Fallback provides structure/security analysis but may miss semantic errors
USAGE GUIDANCE: • Call after generating or modifying Compact code • Use skipZk=true for quick validation during development • Use fullCompile=true for final validation before deployment
Inputs: code (required), skipZk, fullCompile. Returns: Compilation result with detailed output, or static analysis fallback if service…
midnight-document-contractARead-onlyIdempotent
📝 AI-POWERED DOCUMENTATION GENERATION
Generates comprehensive documentation for Compact smart contracts. Uses the client's LLM to create detailed, human-readable docs.
FORMATS: • markdown - Full Markdown documentation with examples • jsdoc - JSDoc-style inline comments
MARKDOWN INCLUDES: • Contract overview and purpose • State variables with privacy annotations • Circuit function documentation • Witness function documentation • Usage examples • Security considerations
⚠️ REQUIRES: Client with sampling capability (e.g., Claude Desktop)
Inputs: code (required), format. Returns: documentation, format, samplingAvailable
midnight-explain-circuitARead-onlyIdempotent
Explain what a specific Compact circuit does in plain language, including its zero-knowledge proof implications and privacy considerations.
USAGE GUIDANCE: • Call once per circuit - explanations are deterministic • Provide complete circuit code including parameters and body • For full contract analysis, use midnight-analyze-contract first
Inputs: circuitCode (required). Returns: Detailed circuit explanation with privacy analysis
midnight-extract-contract-structureARead-onlyIdempotent
Extract and analyze Compact contract structure (circuits, witnesses, ledger). CRITICAL CHECKS: deprecated 'ledger { }' block syntax, 'Void' return type (should be []), old pragma format, unexported enums, deprecated Cell wrapper. Also detects: module-level const, stdlib name collisions, division operator, Counter.value access, missing disclose() calls, potential overflow. Use BEFORE generating contracts to catch syntax errors. Note: Static analysis only - catches common patterns but not semantic errors.
Inputs: code, filePath. Returns: success, filename, languageVersion, imports, +6 more
midnight-fetch-docsARead-onlyIdempotent
🌐 LIVE FETCH: Retrieve latest documentation directly from docs.midnight.network (SSG-enabled).
Unlike midnight-search-docs which uses pre-indexed content, this tool fetches LIVE documentation pages in real-time. Use when you need: • The absolute latest content (just updated docs) • A specific page you know the path to • Full page content rather than search snippets
COMMON PATHS: • /develop/faq - Frequently asked questions • /getting-started/installation - Installation guide • /getting-started/create-mn-app - Create an MN app • /compact - Compact language reference • /develop/tutorial/building - Build guide • /develop/reference/midnight-api - API documentation • /learn/what-is-midnight - What is Midnight • /blog - Dev diaries
USAGE GUIDANCE: • Use extractSection to get only a specific heading (e.g., "Developer questions") • Prefer midnight-search-docs for discovery, use this for known pages • Content is truncated at 15KB for token efficiency
Inputs: path (required), extractSection. Returns: Live documentation page content
midnight-generate-contractA
🔮 AI-POWERED CONTRACT GENERATION
Generates Compact smart contracts from natural language requirements. Uses the client's LLM through MCP sampling to create contracts.
REQUIREMENTS FORMAT:
Describe what the contract should do
Specify state variables needed
Define access control requirements
List the operations/circuits needed
CONTRACT TYPES: • counter - Simple counter with increment/decrement • token - Token with transfers and balances • voting - Voting/governance mechanisms • custom - Free-form custom contract
EXAMPLE USAGE: "Create a token contract with private balances, mint/burn capabilities for admin, and transfer functionality between users"
⚠️ REQUIRES: Client with sampling capability (e.g., Claude Desktop)
Inputs: requirements (required), contractType, baseExample. Returns: code, explanation, warnings, samplingAvailable
midnight-get-fileARead-only
Retrieve a specific file from Midnight repositories. Use repository aliases like 'compact', 'midnight-js', 'counter', or 'bboard' for convenience.
USAGE GUIDANCE: • Use midnight-list-examples first if you're unsure which file to get • For searching across files, use midnight-search-* tools instead • Use 'ref' parameter to get specific versions (branch, tag, or commit) • Use startLine/endLine to request specific sections of large files • Files >50KB are truncated (first 25KB + last 25KB preserved)
Inputs: repo (required), path (required), ref, startLine, +1 more.
midnight-get-file-at-versionARead-onlyIdempotent
Get the exact content of a file at a specific version. CRITICAL: Use this to ensure code recommendations match the user's version. Always prefer this over get-file when version accuracy matters.
Inputs: repo (required), path (required), version (required).
midnight-get-latest-syntaxARead-only
🚨 CALL THIS BEFORE GENERATING ANY COMPACT CODE! Get the authoritative Compact syntax reference. Prevents hallucination by providing:
Correct syntax patterns (Compact is NOT TypeScript!)
commonMistakes array with wrong→correct mappings
Type casting rules (Uint→Bytes needs two casts)
disclose() requirements for circuit params
Map.lookup()/Set.member() ARE available in circuits
ALWAYS check this reference before writing Compact contracts.
Inputs: repo.
midnight-get-latest-updatesBRead-only
Retrieve recent changes and commits across Midnight repositories. Useful for staying up-to-date with the latest developments.
Inputs: since, repos.
midnight-get-migration-guideARead-only
Get a detailed migration guide for upgrading between versions, including all breaking changes, deprecations, and recommended steps.
Inputs: repo (required), fromVersion (required), toVersion.
midnight-get-repo-contextARead-only
🚀 COMPOUND TOOL: Get everything needed to start working with a repository in ONE call. Combines version info + syntax reference + relevant examples. Use this at the start of a coding session instead of multiple individual calls. Saves ~50% tokens.
Inputs: repo (required), includeExamples, includeSyntax. Returns: repository, quickStart, version, syntax, +1 more
midnight-get-statusARead-onlyIdempotent
Get current server status including rate limits and cache statistics. Quick status check without external API calls.
Inputs: no named parameters. Returns: Current server status and statistics
midnight-get-update-instructionsARead-onlyIdempotent
📋 Get detailed, platform-specific instructions for updating Midnight MCP to the latest version. Provides step-by-step guidance including config file locations, commands to run, and troubleshooting tips. Use this when a user needs help updating or is having issues with outdated versions.
Inputs: platform, editor. Returns: title, currentSetup, steps, troubleshooting, +2 more
midnight-get-version-infoARead-only
Get the latest version, release notes, and recent breaking changes for a Midnight repository. Use this to ensure you're working with the latest implementation.
Inputs: repo (required).
midnight-health-checkARead-onlyIdempotent
Check the health status of the Midnight MCP server. Returns server status, API connectivity, and resource availability.
Inputs: detailed. Returns: Server health status with optional detailed diagnostics
midnight-list-category-toolsARead-onlyIdempotent
📋 DISCOVERY TOOL: List tools within a specific category. Use after midnight-list-tool-categories to see detailed tool information for a category of interest. Supports progressive disclosure pattern.
Inputs: category (required), includeSchemas. Returns: Tools within a specific category
midnight-list-examplesARead-onlyIdempotent
List available Midnight example contracts and DApps with descriptions, complexity ratings, and key features.
Inputs: category.
midnight-list-tool-categoriesARead-onlyIdempotent
📋 DISCOVERY TOOL: List available tool categories for progressive exploration. Use this FIRST to understand what capabilities are available, then drill into specific categories with midnight-list-category-tools. Reduces cognitive load by organizing 28 tools into 7 logical groups.
Inputs: includeToolCounts. Returns: Tool categories for progressive discovery
midnight-review-contractARead-onlyIdempotent
🔍 AI-POWERED CONTRACT REVIEW
Performs security review and analysis of Compact smart contracts. Uses the client's LLM to identify issues and suggest improvements.
CHECKS PERFORMED: • Security vulnerabilities • Privacy concerns (shielded state handling) • Logic errors • Best practice violations • Performance issues
OUTPUT INCLUDES: • Summary of contract quality • List of issues with severity levels • Suggested fixes for each issue • Improved code version if applicable
⚠️ REQUIRES: Client with sampling capability (e.g., Claude Desktop)
Inputs: code (required). Returns: summary, issues, improvedCode, samplingAvailable
midnight-search-compactARead-onlyIdempotent
Semantic search across Compact smart contract code and patterns. Use this to find circuit definitions, witness functions, ledger declarations, and best practices for Midnight smart contracts.
USAGE GUIDANCE: • Call at most 2 times per question - if first search doesn't help, try different keywords • For comprehensive results, combine with midnight-search-docs • Use specific terms like "ledger", "circuit", "witness" for better matches
Inputs: query (required), limit, filter. Returns: Search results with relevance scores and source information
midnight-search-docsARead-onlyIdempotent
Full-text search across official Midnight documentation. Use this to find guides, API documentation, and conceptual explanations about Midnight blockchain and the Compact language.
USAGE GUIDANCE: • Call at most 2 times per question - use different keywords if first search fails • For code examples, combine with midnight-search-compact or midnight-search-typescript • Use category filter to narrow results (guides, api, concepts)
Inputs: query (required), category, limit. Returns: Search results with relevance scores and source information
midnight-search-typescriptARead-onlyIdempotent
Search TypeScript SDK code, types, and API implementations. Use this to find how to use the Midnight JavaScript SDK, type definitions, and integration patterns.
USAGE GUIDANCE: • Call at most 2 times per question - refine keywords rather than repeating • For contract code, use midnight-search-compact instead • Include "type" or "interface" in query for type definitions
Inputs: query (required), includeTypes, includeExamples, limit. Returns: Search results with relevance scores and source information
midnight-suggest-toolARead-onlyIdempotent
🎯 SMART DISCOVERY: Describe what you want to do in natural language, and get tool recommendations.
EXAMPLES: • "I want to find example voting contracts" → midnight-search-compact • "Check if my version is outdated" → midnight-upgrade-check • "Analyze my contract for security issues" → midnight-analyze-contract • "I'm new to Midnight and want to get started" → midnight-get-repo-context
This tool matches your intent against known patterns and suggests the most appropriate tools with confidence levels.
USAGE GUIDANCE: • Call once with your intent - no need to call repeatedly • More specific intents get better matches • Use the primaryRecommendation for the best match
Inputs: intent (required). Returns: Tool suggestions based on intent
midnight-upgrade-checkARead-only
🚀 COMPOUND TOOL: Complete upgrade analysis in ONE call. Combines version check + breaking changes + migration guide. Use this instead of calling midnight-get-version-info, midnight-check-breaking-changes, and midnight-get-migration-guide separately. Saves ~60% tokens.
Inputs: currentVersion (required), repo. Returns: repository, currentVersion, version, breakingChanges, +3 more
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 30 tools
Tools are mostly distinct with clear purposes. Some overlap exists among version-checking tools and search tools, but descriptions effectively differentiate them. A few compound tools also help reduce ambiguity.
All tools follow a consistent 'midnight-verb-noun' pattern in snake_case. Verbs are descriptive and uniform, with only minor deviations like 'auto-update' using a dash within a compound word.
With 30 tools, the server covers a wide range of functionality for Midnight development. While comprehensive, the count is on the higher side and could potentially be streamlined by merging some overlapping tools without losing clarity.
The tool surface covers the full development cycle: analysis, generation, compilation, security review, documentation, version management, and search. Minor gaps exist (e.g., no deployment or testing tools), but these are within the intended scope of an MCP assistant.
Maintenance
Related MCP Connectors
Driflyte MCP server which lets AI assistants query topic-specific knowledge from web and GitHub.
An MCP server that gives your AI access to the source code and docs of all public github repos
MCP server for AI agent profiles and smart notes. 60+ coding prompt packs with expert personas.
Official MCP server for Agentwork — delegate tasks to AI agents with human-in-the-loop
Related MCP Servers
- AlicenseBqualityDmaintenanceAn MCP server that provides cryptocurrency project data to AI agents11MIT
- -licenseNot gradedqualityNot gradedmaintenanceAn MCP server that gives AI agents real-time Solana DeFi intelligence — smart money tracking, rug detection, wallet analysis, and token research.-
- AlicenseNot gradedqualityDmaintenanceMCP server providing AI assistants with tools for advanced EVM smart contract analysis, including proxy detection, implementation resolution, and security analysis.1MIT
- AlicenseAqualityBmaintenanceAn MCP server that equips AI assistants with curated knowledge and live chain data for the Alkanes metaprotocol and Subfrost network, enabling them to read docs, query the chain, and scaffold contracts.213MIT