Skip to content

OrderlyNetwork/mockpilot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

27 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

MockPilot - VS Code Extension

A powerful and intuitive Mock API Server extension for VS Code that helps developers quickly create, manage, and test mock APIs directly within their development environment.

โœจ Features

  • ๐Ÿ“ YAML-based Configuration - Simple, version-controllable mock API definitions
  • ๐Ÿš€ One-Click Server Control - Start/stop MockPilot server from Status Bar
  • ๐Ÿ”„ Hot Reload - Automatic reload when configuration files change
  • ๐ŸŽฏ Visual Editor - User-friendly WebView interface for editing mock APIs
  • ๐Ÿ“Š Real-time Status - Server status display in VS Code Status Bar
  • ๐Ÿงช Built-in Testing - Test APIs directly from the editor
  • ๐Ÿ“ Multiple Response Rules - Support for different response scenarios
  • โšก Zero Configuration - Works out of the box with sensible defaults
  • ๐Ÿค– AI-Powered Mock Generation - Generate mock rules using your IDE's AI (Copilot, Cursor, etc.)
  • ๐ŸŽฏ Claude Skill Auto-Installation - Automatically installs a specialized Claude Skill for generating mock rules

๐Ÿš€ Quick Start

  1. Install the extension from VS Code Marketplace

  2. Create .mock directory in your project root:

    • Use Command Palette: MockPilot: Create .mock Directory
    • Or manually: mkdir .mock
  3. Create a mock API configuration (e.g., .mock/get_positions.yaml):

name: Get All Positions Info
description: Get all trading positions information
method: GET
endpoint: /v1/positions
rules:
  - name: Success
    status: 200
    headers:
      Content-Type: application/json
    body:
      success: true
      timestamp: 1702989203989
      data:
        current_margin_ratio_with_orders: 1.2385
        free_collateral: 450315.09115
        total_collateral_value: 489865.71329
        rows:
          - symbol: PERP_BTC_USDC
            position_qty: -5
            average_open_price: 27908.14386047
            mark_price: 27794.9
            unsettled_pnl: 354.858492
            leverage: 10
    delay: 0
  1. Start the server:

    • Click the Status Bar item: MockPilot: Stopped
    • Or use Command Palette: MockPilot: Start Server
  2. Test your API:

curl http://localhost:9527/v1/positions

๐Ÿ“– Documentation

For detailed usage instructions, see USAGE.md

โš™๏ธ Configuration

Configure the extension in VS Code settings:

{
  "mockServer.port": 9527, // Server port (default: 9527)
  "mockServer.autoStart": false, // Auto-start server on activation
  "mockServer.mockDirectory": ".mock" // Mock configuration directory
}

๐ŸŽฎ Commands

Access via Command Palette (Cmd+Shift+P or Ctrl+Shift+P):

  • MockPilot: Start Server - Start the mock server
  • MockPilot: Stop Server - Stop the mock server
  • MockPilot: Toggle Server - Toggle server on/off
  • MockPilot: Reload Server - Reload all configurations
  • MockPilot: Create .mock Directory - Create mock config directory
  • MockPilot: Test Mock API - Test a specific API endpoint

๐ŸŽฏ Status Bar Integration

The extension adds a Status Bar item showing the server status:

  • Stopped: $(debug-stop) MockPilot: Stopped (yellow background)
  • Running: $(server-process) MockPilot: Running (5) - showing route count

Click the Status Bar item to quickly start/stop the server.

๐Ÿ“ YAML Configuration Format

name: API Name
description: API Description
method: GET | POST | PUT | DELETE | PATCH | HEAD | OPTIONS
endpoint: /api/path
rules:
  - name: Rule Name
    status: 200
    headers:
      Content-Type: application/json
    body:
      key: value
    delay: 0 # milliseconds

๐Ÿ”ฅ Hot Reload

The server automatically reloads when you:

  • Modify any .yaml or .yml file in .mock directory
  • Create new mock API files
  • Delete mock API files

No manual restart required!

๐Ÿค– AI-Powered Features

MockPilot is designed to work seamlessly with your IDE's AI capabilities (such as GitHub Copilot, Cursor, Claude in VS Code, etc.) to help you generate mock API configurations using natural language descriptions.

Special Feature: When you install MockPilot, it automatically installs a dedicated Claude Skill that's specifically trained to generate mock API configurations following MockPilot's YAML format standards. This ensures optimal AI-generated outputs when using Claude.

How It Works

Instead of providing a built-in AI command, MockPilot leverages your existing IDE AI tools. You simply describe your API requirements using a structured prompt template, and your AI assistant will generate the YAML configuration. MockPilot then manages and serves these mock APIs.

Using AI to Generate Mock Rules

1. Prerequisites

  • Have an AI assistant enabled in your IDE:
    • VS Code: GitHub Copilot, Claude, or other AI extensions
    • Cursor: Built-in AI capabilities
    • Other IDEs: Any AI coding assistant
  • MockPilot extension installed (includes auto-installed Claude Skill for Claude users)
  • A project with a .mock directory

2. Using Claude Skill (Auto-Installed)

If you're using Claude in VS Code, MockPilot automatically installs a specialized Claude Skill on first activation. This skill is optimized for generating MockPilot-compatible YAML configurations.

Simply ask Claude:

Generate a mock API for [your requirement]

The skill understands MockPilot's format and will generate properly structured YAML configurations automatically.

3. Prompt Template (For Other AI Assistants)

Use this template with your AI assistant to generate mock rules:

Create a mock API YAML configuration with the following requirements:
- Method: [GET/POST/PUT/DELETE/etc.]
- Endpoint: [/api/path]
- Description: [What this API does]
- Response scenarios: [success, error cases, edge cases]
- Data structure: [describe the expected response format]

Format the output as a YAML file following this structure:
name: [API Name]
description: [API Description]
method: [HTTP Method]
endpoint: [API Path]
rules:
  - name: [Rule Name]
    status: [HTTP Status Code]
    headers:
      Content-Type: application/json
    body:
      [response body]
    delay: [milliseconds]

4. Example Usage

Prompt to your AI assistant:

Create a mock API YAML configuration with the following requirements:
- Method: GET
- Endpoint: /v1/positions
- Description: Get all trading positions information
- Response scenarios:
  1. Success with positions data
  2. Success with empty positions
- Data structure: Include margin ratios, collateral info, and position details with symbol, quantity, price, and PnL

5. Workflow

  1. Ask your AI assistant using the prompt template above
  2. AI generates the YAML configuration based on your requirements
  3. Save the file in your .mock directory (e.g., .mock/get_positions.yaml)
  4. MockPilot automatically detects the new file and reloads
  5. Test your API immediately using the mock server

6. AI Generation Capabilities

Your AI assistant can help you create:

  • Complete Mock APIs - From endpoint definition to response bodies
  • Multiple Rules - Different scenarios (success, errors, edge cases)
  • Realistic Data - Sample user data, product catalogs, financial data, etc.
  • Complex Structures - Nested objects, arrays, and relationships
  • Headers and Delays - Simulate real-world API behavior
  • RESTful Patterns - Follow REST conventions automatically

7. Example Generated Output

Your AI assistant will generate:

name: Get All Positions Info
description: Get all trading positions information
method: GET
endpoint: /v1/positions
rules:
  - name: Success - With Positions
    status: 200
    headers:
      Content-Type: application/json
    body:
      success: true
      timestamp: 1702989203989
      data:
        current_margin_ratio_with_orders: 1.2385
        free_collateral: 450315.09115
        initial_margin_ratio: 0.1
        maintenance_margin_ratio: 0.05
        margin_ratio: 1.2385
        total_collateral_value: 489865.71329
        total_pnl_24_h: 0
        rows:
          - symbol: PERP_BTC_USDC
            position_qty: -5
            average_open_price: 27908.14386047
            mark_price: 27794.9
            unsettled_pnl: 354.858492
            leverage: 10
            imr: 0.1
            mmr: 0.05
    delay: 100

  - name: Success - No Positions
    status: 200
    headers:
      Content-Type: application/json
    body:
      success: true
      timestamp: 1702989203989
      data:
        current_margin_ratio_with_orders: 0
        free_collateral: 0
        total_collateral_value: 0
        rows: []
    delay: 50

Then simply:

  1. Save this as .mock/get_positions.yaml
  2. MockPilot automatically loads it
  3. Start testing at http://localhost:9527/v1/positions

8. Best Practices

  • Be Specific: Provide clear descriptions of expected responses
  • Include Scenarios: Mention different cases (success, errors, edge cases)
  • Specify Data Types: Indicate if you need numbers, dates, booleans, etc.
  • Mention Constraints: Include any validation rules or business logic
  • Review Output: Always review AI-generated configs before using
  • Iterate: Refine your prompt if the output needs adjustments

Benefits of AI-Assisted Generation

  • โšก Save Time: Generate complex mock rules in seconds
  • ๐ŸŽฏ Claude Skill Integration: Auto-installed skill ensures optimal results with Claude
  • ๐Ÿค Use Your Preferred AI: Works with Copilot, Cursor, Claude, or any AI assistant
  • ๐Ÿ“š Best Practices: AI follows YAML and REST conventions
  • ๐ŸŽฏ Comprehensive: Automatically includes multiple scenarios
  • ๐Ÿ”„ Iterative: Easily refine by adjusting your prompt
  • ๐Ÿ“– Learning Tool: Learn proper mock API structure from examples
  • ๐ŸŽจ Flexibility: Combine AI generation with manual editing as needed

MockPilot's Role

MockPilot focuses on what it does best:

  • ๐Ÿ“ Managing your mock configurations
  • ๐Ÿš€ Serving mock APIs with hot reload
  • ๐ŸŽฏ Testing APIs directly from VS Code
  • ๐Ÿ“Š Monitoring server status and routes

You bring the AI tool you're already comfortable with, and MockPilot handles the rest!

Prerequisites

  • Node.js >= 16
  • pnpm (recommended) or npm

Setup

git clone <repository>
cd mock-server
pnpm install

Build & Run

# Development build with watch mode
pnpm run watch-web

# Run in browser
pnpm run run-in-browser

# Production build
pnpm run package-web

# Run tests
pnpm test

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

Roadmap

[] Mock data programmatically [] Mock RPC Server

๐Ÿ“„ License

MIT License

๐Ÿ’ก Use Cases

  • Frontend Development - Mock backend APIs while frontend is under development
  • API Testing - Test different response scenarios (success, errors, edge cases)
  • Documentation - Create living API documentation with examples
  • Team Collaboration - Share mock configurations via version control
  • Offline Development - Work without backend dependencies

Enjoy mocking! ๐ŸŽ‰

Working with Markdown

You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts:

  • Split the editor (Cmd+\ on macOS or Ctrl+\ on Windows and Linux).
  • Toggle preview (Shift+Cmd+V on macOS or Shift+Ctrl+V on Windows and Linux).
  • Press Ctrl+Space (Windows, Linux, macOS) to see a list of Markdown snippets.

For more information

Enjoy!

About

Visual Mock API Server for VS Code

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published