Development Guide

December 15, 2024 · View on GitHub

Environment Setup

  1. Prerequisites

    • Node.js 18+
    • npm/yarn
    • TypeScript
    • Gemini API key
  2. Installation

git clone https://github.com/aliargun/mcp-server-gemini.git
cd mcp-server-gemini
npm install
  1. Configuration
# Set your Gemini API key
export GEMINI_API_KEY=your_api_key_here

Development Workflow

  1. Start Development Server
npm run dev
  1. Build for Production
npm run build
  1. Run Tests
npm test

Project Structure

src/
├── index.ts         # Main entry point
├── types/           # TypeScript type definitions
├── utils/           # Utility functions
test/                # Test files
docs/                # Documentation

Adding Features

  1. Create new message handler:
if (request.method === 'newMethod') {
  // Handle new method
}
  1. Add capability:
capabilities: {
  experimental: {
    newFeature: true
  }
}

Testing

  1. Unit Tests
describe('Message Handler', () => {
  it('handles new method', () => {
    // Test implementation
  });
});
  1. Integration Tests
describe('WebSocket Server', () => {
  it('connects and processes messages', () => {
    // Test implementation
  });
});

Debugging

  1. Enable Debug Logging
const DEBUG = true;
if (DEBUG) console.log('Debug:', message);
  1. Use WebSocket Client
wscat -c ws://localhost:3005

Best Practices

  1. Code Style

    • Use TypeScript
    • Follow existing patterns
    • Document public APIs
  2. Error Handling

    • Use type-safe errors
    • Provide meaningful messages
    • Log appropriately
  3. Testing

    • Write unit tests
    • Add integration tests
    • Test error cases