Skip to main content

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

  1. Clone Repository
  2. Install Dependencies
  3. Environment Setup
  4. 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

  1. Create Tool File Create a new file in src/tools/ following the naming convention.
  2. Implement Tool Logic
  3. 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

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. 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

Deployment

Production Build

Docker Deployment

Create a Dockerfile:
Build and run:

Monitoring in Production

Set up monitoring and alerting:
This development guide provides the foundation for extending and contributing to the MCP 0G Server. For specific questions or advanced use cases, refer to the community resources and documentation.