0G MCP Server
Model Context Protocol (MCP) server for accessing 0G.AI documentation and code examples. Built with Mastra MCP framework and Bun.
What It Does - Quick Examples
š Access 0G Documentation
š¾ Upload Files to 0G Storage
š„ Download from 0G Storage
šļø Store Key-Value Data
š¤ List Available AI Services
Example Output:
š Extract Code Examples
Features
0gDocs Tool: Access 0g.ai documentation by path, with keyword search support
0gExamples Tool: Extract and filter code examples from documentation
0G Storage SDK Tools: Complete integration with 0G Storage network
File upload/download
Storage node information
Key-value store operations
0G Compute Network Tools: Live integration with 0G Compute Network
List available AI services (inference & fine-tuning)
Service discovery with detailed pricing
Provider verification status (TEE support)
Real-time service availability
0G Compute Network Documentation: Access compute layer documentation
Inference SDK guides and complete examples
Fine-tuning provider setup
CLI usage examples
Broker architecture and design (provider & user brokers)
TypeScript SDK interface documentation
Smart Contract Documentation: Deep dive into on-chain mechanics
Settlement and ZK-proof verification
Account and service management
Nonce-based replay protection
Refund mechanisms and lock times
0G Agent NFT (iNFT) Documentation: ERC-7857 standard implementation
Complete EIP-7857 specification for AI Agent NFTs
Private metadata management (models, memory, character definitions)
Verifiable data transfer with TEE/ZKP proofs
Full Solidity contract implementations (AgentNFT, verifiers, interfaces)
Transfer, clone, and authorization mechanisms
Sealed key encryption for secure data access
Reference implementation with proxy patterns
Knowledge Base with Mermaid Diagrams: Custom architecture documentation
System architecture diagrams
Sequence diagrams for complete flows
State transition diagrams
Component interaction diagrams
LLM-readable Mermaid format for better understanding
Automatic documentation syncing via git submodule
Built-in logging and error handling
Compatible with Claude Code, Cursor, and other MCP clients
Installation
Usage
Starting the Server
MCP Client Configuration
Claude Code
Add the server using the Claude CLI:
Or manually add to your MCP configuration:
Note: Replace /path/to/0g-mcp-server with your actual project path.
After adding, restart Claude Code or reconnect to the MCP server using:
Cursor
Add to .cursor/mcp.json:
Windsurf
Add to ~/.codeium/windsurf/mcp_config.json:
MCP Tools
Documentation Tools
0gDocs
Retrieve 0g.ai documentation by path.
Parameters:
paths(string[]): One or more documentation paths to fetchqueryKeywords(string[], optional): Keywords for matching relevant documentation
Example:
0gExamples
Get code examples from 0g.ai documentation.
Parameters:
category(string, optional): Filter by category (e.g., "developer-hub", "storage", "da")language(string, optional): Filter by programming language (e.g., "typescript", "python", "solidity")
Example:
Storage Tools
All storage tools require either the OG_PRIVATE_KEY environment variable or privateKey parameter for operations that write to the blockchain.
0gStorageUpload
Upload a file to 0G Storage network.
Parameters:
filePath(string): Absolute path to the file to uploadprivateKey(string, optional): Private key for signing transactionsevmRpc(string, optional): EVM RPC endpoint (default: testnet)indexerRpc(string, optional): Indexer RPC endpoint (default: testnet)withMerkleTree(boolean, optional): Include Merkle tree information
Returns:
rootHash: Unique identifier for the uploaded filetxHash: Transaction hashmerkleTree(optional): Merkle tree information
Example:
0gStorageDownload
Download a file from 0G Storage network by its root hash.
Parameters:
rootHash(string): Root hash of the file to downloadoutputPath(string): Absolute path where the file should be savedwithProof(boolean, optional): Verify download with Merkle proof (default: true)indexerRpc(string, optional): Indexer RPC endpoint
Returns:
filePath: Path to downloaded fileverified: Whether the file was verified with Merkle proof
Example:
0gStorageNodes
Get information about available 0G Storage nodes.
Parameters:
count(number, optional): Number of storage nodes to select (default: 5)indexerRpc(string, optional): Indexer RPC endpoint
Returns:
nodes: List of selected storage nodes with their detailscount: Number of nodes returned
Example:
0gKvSet
Set key-value pairs in 0G Storage KV store.
Parameters:
streamId(string): Stream ID for the KV storedata(array): Array of key-value pairs to setkey(string): Key to setvalue(string): Value to store
privateKey(string, optional): Private key for signing transactionsevmRpc(string, optional): EVM RPC endpointindexerRpc(string, optional): Indexer RPC endpointflowContract(string, optional): Flow contract address
Returns:
txHash: Transaction hashkeysSet: Number of keys setkeys: Array of keys that were set
Example:
0gKvGet
Retrieve a value from 0G Storage KV store by key.
Parameters:
streamId(string): Stream ID for the KV storekey(string): Key to retrievekvUrl(string, optional): KV client URL
Returns:
value: Retrieved value (decoded)rawValue: Raw value from storagekey: The key that was queried
Example:
Compute Tools
0gComputeListServices
List all available AI services on the 0G Compute Network.
Parameters:
evmRpc(string, optional): EVM RPC endpoint (default: testnet)contractAddress(string, optional): Serving contract address (uses default if not provided)
Returns:
success: Boolean indicating successcount: Number of services availableservices: Array of service objects with:provider: Provider wallet addressmodel: AI model name (e.g., "phala/gpt-oss-120b")serviceType: Type of service (e.g., "chatbot")endpoint: Service URLpricing: Object with input/output pricesverifiability: Verification type (e.g., "TeeML" for TEE support)lastUpdated: ISO timestamp
formatted: Human-readable table formatraw: Raw service data from contract
Example:
Example Output:
Project Structure
Development
Updating Documentation
To sync with the latest 0g documentation:
Adding Custom Documentation
To add your own architecture diagrams, guides, or documentation:
Create markdown files in
docs/0g-knowledge-base/:# Example structure docs/0g-knowledge-base/ āāā compute/ ā āāā your-diagram.md āāā storage/ ā āāā your-guide.md āāā guides/ āāā best-practices.mdInclude Mermaid diagrams in your markdown files:
## System Architecture ```mermaid graph TB User[User] --> Broker[Broker] Broker --> Contract[Smart Contract] ```Run prepare-docs to make them accessible:
bun run prepare-docsAccess via MCP tools:
// Via 0gDocs tool paths: ["knowledge-base/compute/your-diagram.md"]
Benefits:
Mermaid diagrams are LLM-readable (unlike PNG images)
Version controlled alongside code
Accessible to AI agents via MCP for better guidance
Scripts
bun run prepare-docs- Copy documentation from submodule to.docs/rawbun run start- Start the MCP serverbun run dev- Start with hot reload and auto-rebuild docsbun run build- Build for production
Environment Variables
Server Configuration
REBUILD_DOCS_ON_START(boolean, default: false) - Rebuild docs on server startupDOCS_PATH(string, default:./lib/0g-docs) - Path to documentation submoduleLOG_LEVEL(string, default:info) - Logging levelDEBUG(boolean) - Enable debug logging
Storage Tools Configuration
The storage tools use a centralized configuration system with the following priority:
Tool parameter (highest) - Override per individual call
Environment variable (medium) - Server-wide configuration
Default value (lowest) - Network-specific fallback
Available Environment Variables:
OG_PRIVATE_KEY(string, required for upload/KV write operations)Private key for signing blockchain transactions
Required for:
0gStorageUpload,0gKvSetCan be overridden per-tool with
privateKeyparameterImportant: Keep this secret and never commit to version control
OG_NETWORK(string, default:testnet)Network selection:
testnetormainnetAutomatically sets default RPC endpoints for the selected network
OG_EVM_RPC(string, optional)Custom EVM RPC endpoint
Overrides network default
OG_INDEXER_RPC(string, optional)Custom Indexer RPC endpoint
Overrides network default
OG_KV_URL(string, optional)Custom KV client URL
Overrides network default
OG_FLOW_CONTRACT(string, optional)Custom Flow contract address
Overrides network default
Example
Network Defaults:
Testnet:
EVM RPC:
https://evmrpc-testnet.0g.aiIndexer RPC:
https://indexer-storage-testnet-turbo.0g.aiKV URL:
http://3.101.147.150:6789Flow Contract:
0xb8F03061969da6Ad38f0a4a9f8a86bE71dA3c8E7
Mainnet: (Update when available)
EVM RPC:
https://evmrpc-mainnet.0g.aiIndexer RPC:
https://indexer-storage-mainnet.0g.aiKV URL:
http://mainnet-kv.0g.ai:6789Flow Contract: TBD
Compute Tools Configuration
The compute tools use the same configuration system as storage tools:
Available Environment Variables:
OG_NETWORK(string, default:testnet)Network selection:
testnetormainnetShared with storage tools
OG_EVM_RPC(string, optional)Custom EVM RPC endpoint
Shared with storage tools
OG_SERVING_CONTRACT(string, optional)Custom Serving contract address
Overrides SDK default
Example
Note: Compute tools require no private key for read-only operations like listing services. They create a temporary wallet internally for contract reads.
References
License
See LICENSE file for details.