Tools: Latest: Using midnight-mcp for Contract Development with Claude

Tools: Latest: Using midnight-mcp for Contract Development with Claude

Using midnight-mcp for Contract Development with Claude

What Is midnight-mcp?

Prerequisites

Installation

Connecting midnight-mcp to Claude

Step 1: Locate Your Claude MCP Configuration File

Step 2: Add midnight-mcp as an MCP Server

Step 3: Restart Claude Desktop

What midnight-mcp Exposes to Claude

1. Contract File Access

2. Midnight SDK Documentation

3. Contract Scaffolding Tools

4. Compilation Diagnostics

5. Deployment State Queries

Practical Workflow: Scaffolding Your First Contract with Claude

Scenario: Private Counter Contract

Iterating with Claude

Debugging Compact Contracts with Claude Assistance

1. Trigger a Compilation Error

2. Ask Claude to Diagnose

3. Proof Generation Failures

Advanced: Using midnight-mcp in VS Code

Tips for Effective AI-Assisted Midnight Development

Summary AI-assisted development is reshaping how engineers write software, and blockchain smart contract development is no exception. The midnight-mcp package brings the Model Context Protocol (MCP) to Midnight Network, allowing you to connect Claude — Anthropic's AI assistant — directly to your Midnight development environment. The result: a smarter coding partner that understands Compact (Midnight's smart contract language), can scaffold contracts, and can assist with debugging — all within your editor or AI chat interface. This tutorial walks through installing midnight-mcp, connecting it to Claude, understanding what the MCP exposes, and building a practical workflow for Compact contract development with AI assistance. Model Context Protocol (MCP) is an open standard that allows AI models to connect to external tools and data sources. Rather than pasting code into a chat window, MCP-enabled tools let Claude query live context — files, APIs, documentation — and take actions on your behalf. midnight-mcp (npm package: midnight-mcp) is an MCP server specifically built for Midnight Network development. When running, it exposes Midnight-specific capabilities to compatible AI clients (like Claude Desktop or Claude in VS Code via Anthropic's MCP integrations), allowing the AI to: Think of it as giving Claude a pair of "Midnight-native glasses" — instead of relying only on its training data about Midnight (which may be outdated or sparse), it gets live, structured access to your project and the Midnight SDK. Before installing midnight-mcp, make sure you have: Install midnight-mcp globally so it's available as an MCP server command: Or, if you prefer to install it locally within a project: Verify the installation: You should see the version number printed. If the command isn't found after global install, ensure your npm global bin directory is on your PATH: Claude Desktop uses a JSON configuration file to discover MCP servers. The file location depends on your OS: If the file doesn't exist, create it. Edit the configuration file to register midnight-mcp: Replace /path/to/your/midnight/project with the root directory of your Compact project (the folder containing your .compact files and package.json). If you installed midnight-mcp locally rather than globally, use the full path: Fully quit and relaunch Claude Desktop. When it starts, it will attempt to connect to all registered MCP servers. You should see a small indicator in the Claude interface showing connected tools. To verify the connection is working, open a new conversation in Claude and ask: "What Midnight tools do you have access to?" Claude should respond with a list of available midnight-mcp capabilities, not a generic "I don't have tools" reply. When connected, midnight-mcp provides Claude with several categories of tools and context: Claude can read your .compact source files directly, understanding the full contract structure — ledger state declarations, circuit functions, witness blocks, and exported types. midnight-mcp bundles or fetches Midnight API documentation, type definitions from @midnight-ntwrk/compact-runtime, and examples. This allows Claude to give accurate, version-specific answers rather than hallucinating outdated APIs. Claude can invoke scaffolding commands through midnight-mcp to generate boilerplate for common contract patterns: If your Compact compiler (compactc) is installed, midnight-mcp can trigger compilation and surface error messages back to Claude, enabling a tight feedback loop for debugging. When connected to a running Midnight node (devnet or testnet), midnight-mcp can query contract state, helping Claude understand the current on-chain context when advising on transaction construction. Here's a realistic development session using midnight-mcp and Claude: You: "I want to build a counter contract on Midnight where the count is private — only the owner can increment it and verify the value with a ZK proof. Scaffold this for me." Claude (with midnight-mcp active): Reads your project structure, checks Compact syntax rules, then generates a file like: Claude will explain what each section does, flag any type constraints to be aware of, and suggest next steps like adding ownership checks. Once you have the scaffold, continue the conversation: You: "Now add an owner field so only the wallet that deployed the contract can call increment." Claude can read the current contract state via midnight-mcp and return an updated version that adds a Cell<Bytes<32>> owner field with a signature verification in the circuit — all while being aware of the actual Compact type system. midnight-mcp's most powerful use case may be debugging. Here's a debugging workflow: Run your Compact compiler: If you get an error like: Paste the error into Claude (or, if midnight-mcp is configured with file access, Claude may already have the context). Ask: "My Compact contract is throwing a type mismatch error at line 12. What's wrong?" With midnight-mcp providing the source file, Claude can pinpoint the issue — for example, that you're passing a Uint<64> to a circuit expecting a Field element — and show the corrected code. If your proof server returns an error during ZK proof generation, the error messages can be cryptic (literally and figuratively). Claude + midnight-mcp can help interpret circuit witness errors, missing public input errors, and constraint violations — common pain points in ZK development. If you prefer VS Code to Claude Desktop, check whether the Claude VS Code extension supports MCP servers. The setup is similar — add the server configuration in the extension settings, point it to your project root, and Claude Inline Chat or the side panel will gain Midnight context. Some developers also use midnight-mcp with other MCP-compatible clients like Cursor or Continue.dev, following the same JSON configuration pattern. midnight-mcp bridges the gap between Claude's language intelligence and Midnight's specialized ZK contract development environment. By installing the npm package, configuring it as an MCP server in Claude Desktop, and pointing it at your project, you get: This is the frontier of AI-assisted blockchain development: not just autocomplete, but a coding partner that actually understands your blockchain's specific type system, proof model, and contract semantics. Then configure Claude Desktop, restart, and ask Claude to scaffold your next Midnight contract. The combination of Midnight's privacy primitives and Claude's code generation capabilities is one of the most compelling developer experiences in the current blockchain ecosystem. For more information on midnight-mcp, see the npm package page and the Midnight developer documentation. Templates let you quickly answer FAQs or store snippets for re-use. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse

Command

Copy

$ -weight: 500;">npm -weight: 500;">install -g midnight-mcp -weight: 500;">npm -weight: 500;">install -g midnight-mcp -weight: 500;">npm -weight: 500;">install -g midnight-mcp -weight: 500;">npm -weight: 500;">install --save-dev midnight-mcp -weight: 500;">npm -weight: 500;">install --save-dev midnight-mcp -weight: 500;">npm -weight: 500;">install --save-dev midnight-mcp midnight-mcp --version midnight-mcp --version midnight-mcp --version # Add to ~/.zshrc or ~/.bashrc export PATH="$(-weight: 500;">npm root -g)/../bin:$PATH" # Add to ~/.zshrc or ~/.bashrc export PATH="$(-weight: 500;">npm root -g)/../bin:$PATH" # Add to ~/.zshrc or ~/.bashrc export PATH="$(-weight: 500;">npm root -g)/../bin:$PATH" { "mcpServers": { "midnight": { "command": "midnight-mcp", "args": [], "env": { "MIDNIGHT_PROJECT_ROOT": "/path/to/your/midnight/project" } } } } { "mcpServers": { "midnight": { "command": "midnight-mcp", "args": [], "env": { "MIDNIGHT_PROJECT_ROOT": "/path/to/your/midnight/project" } } } } { "mcpServers": { "midnight": { "command": "midnight-mcp", "args": [], "env": { "MIDNIGHT_PROJECT_ROOT": "/path/to/your/midnight/project" } } } } { "mcpServers": { "midnight": { "command": "node", "args": ["/path/to/your/project/node_modules/.bin/midnight-mcp"] } } } { "mcpServers": { "midnight": { "command": "node", "args": ["/path/to/your/project/node_modules/.bin/midnight-mcp"] } } } { "mcpServers": { "midnight": { "command": "node", "args": ["/path/to/your/project/node_modules/.bin/midnight-mcp"] } } } pragma language_version >= 0.14.0; import CompactStandardLibrary; export ledger counter: Cell<Uint<64>>; export circuit increment(new_value: Uint<64>): [] { assert counter.value < new_value "Counter must increase"; counter.value = new_value; } export circuit get_count(): Uint<64> { return counter.value; } pragma language_version >= 0.14.0; import CompactStandardLibrary; export ledger counter: Cell<Uint<64>>; export circuit increment(new_value: Uint<64>): [] { assert counter.value < new_value "Counter must increase"; counter.value = new_value; } export circuit get_count(): Uint<64> { return counter.value; } pragma language_version >= 0.14.0; import CompactStandardLibrary; export ledger counter: Cell<Uint<64>>; export circuit increment(new_value: Uint<64>): [] { assert counter.value < new_value "Counter must increase"; counter.value = new_value; } export circuit get_count(): Uint<64> { return counter.value; } npx compactc src/myContract.compact npx compactc src/myContract.compact npx compactc src/myContract.compact Error: type mismatch: expected Field, got Uint<64> at line 12 Error: type mismatch: expected Field, got Uint<64> at line 12 Error: type mismatch: expected Field, got Uint<64> at line 12 -weight: 500;">npm -weight: 500;">install -g midnight-mcp -weight: 500;">npm -weight: 500;">install -g midnight-mcp -weight: 500;">npm -weight: 500;">install -g midnight-mcp - Read and understand Compact contract source files - Access Midnight API documentation and type definitions - Scaffold new Compact contracts from templates - Query ledger state or contract deployment information - Provide context-aware suggestions for ZK circuit design - Node.js 18+ (the Midnight SDK requires modern Node) - -weight: 500;">npm or yarn package manager - Claude Desktop app or another MCP-compatible Claude interface - Basic familiarity with Compact — Midnight's smart contract language - (Optional) An existing Midnight project created with npx @midnight-ntwrk/midnight-js-cli - macOS: ~/Library/Application Support/Claude/claude_desktop_config.json - Windows: %APPDATA%\Claude\claude_desktop_config.json - Linux: ~/.config/Claude/claude_desktop_config.json - Token contracts (mint/burn/transfer) - Access control contracts - Private voting contracts - Escrow patterns with ZK proofs - Keep contracts small and focused — Claude (and ZK proofs) handle simpler, single-purpose circuits better than monolithic contracts. - Always review generated code — AI scaffolding gives you a fast starting point, but the security implications of ZK circuit design require human review. - Ask Claude to explain, not just generate — "Explain why this circuit constraint is needed" builds your own understanding. - Use Claude for documentation — "Write Compact-style doc comments for this circuit" can save significant time. - Feed errors immediately — The most value comes from pasting compiler or proof errors directly into the Claude session while midnight-mcp has file context. - Context-aware contract scaffolding - Live access to Midnight SDK documentation - Intelligent debugging assistance for Compact type errors and ZK proof failures - A dramatically faster iteration cycle