Architecture Guide

System architecture and design patterns for Neo N3 MCP Server

πŸ—οΈ System Overview

Neo N3 MCP Server is built as a modular, extensible system that bridges the gap between AI applications and the Neo N3 blockchain. The architecture follows industry best practices for security, performance, and maintainability.

High-Level Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   AI Client     β”‚    β”‚   MCP Server     β”‚    β”‚   Neo N3        β”‚
β”‚   (Claude, etc) │◄──►│   (This System)  │◄──►│   Network       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚   Tool & Resourceβ”‚
                       β”‚   Management     β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β–Ό           β–Ό           β–Ό
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚Blockchainβ”‚ β”‚ Wallet   β”‚ β”‚ Security β”‚
            β”‚ Service  β”‚ β”‚ Service  β”‚ β”‚ Service  β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”§ Core Components

🌐

MCP Protocol Handler

Manages the Model Context Protocol communication, handling tool calls, resource requests, and maintaining session state.

  • JSON-RPC 2.0 protocol
  • Session management
  • Request/response validation
  • Error handling & recovery
πŸ”—

Neo N3 Service

Core blockchain interaction layer that handles all Neo N3 network communications and operations.

  • RPC client management
  • Network switching (mainnet/testnet)
  • Connection pooling
  • Automatic failover
πŸ’°

Wallet Manager

Secure wallet operations including creation, import, and transaction signing with enterprise-grade encryption.

  • AES-256 encryption
  • Secure key derivation
  • Multi-signature support
  • Hardware wallet integration
πŸ“œ

Contract Registry

Manages famous contracts and provides standardized interfaces for smart contract interactions.

  • Contract metadata storage
  • ABI management
  • Method mapping
  • Parameter validation
πŸ›‘οΈ

Security Layer

Comprehensive security controls including input validation, rate limiting, and access control.

  • Input sanitization
  • Rate limiting
  • Confirmation requirements
  • Audit logging
πŸ“Š

Monitoring System

Real-time monitoring, metrics collection, and health checks for operational excellence.

  • Prometheus metrics
  • Health endpoints
  • Performance tracking
  • Alert generation

⚑ Data Flow

Request Processing Flow

1. AI Client Request
   β”‚
   β–Ό
2. MCP Protocol Validation
   β”‚
   β–Ό
3. Security Checks
   β”‚ β”œβ”€ Input Validation
   β”‚ β”œβ”€ Rate Limiting
   β”‚ └─ Authorization
   β–Ό
4. Tool Router
   β”‚
   β–Ό
5. Service Layer
   β”‚ β”œβ”€ Blockchain Service
   β”‚ β”œβ”€ Wallet Service
   β”‚ └─ Contract Service
   β–Ό
6. Neo N3 Network
   β”‚
   β–Ό
7. Response Processing
   β”‚ β”œβ”€ Data Transformation
   β”‚ β”œβ”€ Error Handling
   β”‚ └─ Metrics Collection
   β–Ό
8. MCP Response to Client
πŸ’‘ Design Principles
  • Modularity: Each component has a single responsibility
  • Security First: All inputs validated, all operations logged
  • Fault Tolerance: Graceful degradation and automatic recovery
  • Performance: Connection pooling and efficient caching
  • Observability: Comprehensive monitoring and logging

πŸ› οΈ Technology Stack

Node.js
18+
TypeScript
5.0+
Neo N3
SDK 3.x
Docker
24+
Prometheus
2.x
Jest
29+

Key Dependencies

{
  "dependencies": {
    "@cityofzion/neon-js": "^5.4.0",
    "@neo-project/neo-js": "^3.15.0",
    "express": "^4.18.2",
    "ws": "^8.13.0",
    "crypto": "node:crypto",
    "dotenv": "^16.3.1",
    "joi": "^17.9.2",
    "winston": "^3.10.0",
    "prom-client": "^14.2.0"
  },
  "devDependencies": {
    "@types/node": "^20.4.5",
    "typescript": "^5.1.6",
    "jest": "^29.6.2",
    "eslint": "^8.45.0",
    "prettier": "^3.0.0"
  }
}

πŸ›οΈ Design Patterns

🏭

Factory Pattern

Tool creation and service instantiation based on configuration and runtime requirements.

πŸ”Œ

Strategy Pattern

Different network handlers (mainnet/testnet) and encryption strategies for various security levels.

πŸ‘€

Observer Pattern

Event-driven architecture for monitoring, logging, and metric collection across components.

πŸ”„

Circuit Breaker

Prevents cascading failures when Neo N3 network is unavailable or experiencing issues.

πŸ”’ Security Architecture

Multi-Layer Security Model

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚            Application Layer            β”‚
β”‚  β”œβ”€ Input Validation                   β”‚
β”‚  β”œβ”€ Rate Limiting                      β”‚
β”‚  └─ Request Authentication             β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚             Service Layer               β”‚
β”‚  β”œβ”€ Business Logic Validation          β”‚
β”‚  β”œβ”€ Permission Checks                  β”‚
β”‚  └─ Operation Confirmation             β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚              Data Layer                 β”‚
β”‚  β”œβ”€ Encryption at Rest                 β”‚
β”‚  β”œβ”€ Secure Key Derivation              β”‚
β”‚  └─ Audit Logging                      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚            Network Layer                β”‚
β”‚  β”œβ”€ TLS/SSL Encryption                 β”‚
β”‚  β”œβ”€ Connection Security                β”‚
β”‚  └─ Network Isolation                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
πŸ›‘οΈ Security Features
  • Zero Trust: All operations require explicit validation
  • Principle of Least Privilege: Minimal permissions by default
  • Defense in Depth: Multiple security layers
  • Audit Trail: Complete operation logging
  • Secure by Default: Safe configuration out of the box

πŸ“ˆ Scalability & Performance

Performance Optimizations

πŸ”„

Connection Pooling

Efficient Neo N3 RPC connection management with automatic load balancing and failover.

⚑

Async Processing

Non-blocking operations with proper error handling and timeout management.

πŸ’Ύ

Smart Caching

Intelligent caching of blockchain data with appropriate TTL and invalidation strategies.

πŸ“Š

Resource Management

Memory-efficient operations with garbage collection optimization and leak prevention.