Development Guide
This guide covers how to develop, extend, and contribute to the MCP 0G Server.Development Setup
Prerequisites
- Node.js 18.0 or higher
- TypeScript 4.9 or higher
- Git for version control
- Code editor (VS Code recommended)
Local Development
-
Clone Repository
-
Install Dependencies
-
Environment Setup
-
Development Mode
This starts the server with auto-reload on file changes.
Project Structure
Architecture Overview
Core Components
MCP Server
The main server implements the Model Context Protocol specification:Tool Registry
Tools are registered with the MCP server:Service Layer
Business logic is organized into services:Adding New Tools
Tool Structure
Each tool follows this pattern:Registration Process
-
Create Tool File
Create a new file in
src/tools/
following the naming convention. -
Implement Tool Logic
-
Register Tool
Add to the tool registry:
Best Practices for Tools
Input Validation
Always validate inputs using Zod schemas:Error Handling
Implement comprehensive error handling:Async Operations
Handle async operations properly:Service Development
Creating Services
Services encapsulate business logic:Service Integration
Integrate services with dependency injection:Testing
Unit Tests
Write unit tests for tools and services:Integration Tests
Test complete workflows:Running Tests
Configuration Management
Environment Variables
Define configuration schema:Feature Flags
Implement feature flags for gradual rollouts:Logging and Monitoring
Structured Logging
Implement structured logging:Metrics Collection
Add metrics for monitoring:Security Considerations
Input Sanitization
Always sanitize and validate inputs:Rate Limiting
Implement rate limiting:Secure Storage
Implement secure storage for sensitive data:Contributing
Code Style
Follow the established code style:Pull Request Process
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
Documentation
Update documentation for new features:- Add tool documentation to the appropriate files
- Update API references
- Include usage examples
- Update integration guides if needed