SetupEnvironment Setup

Environment Setup

Configure your development environment to work with Mesrai for local testing and CI/CD integration.

Prerequisites

Before setting up Mesrai locally, ensure you have:

  • Node.js: v18+ or v20+ (LTS recommended)
  • Git: v2.30+
  • Package Manager: npm, yarn, or pnpm
  • GitHub Account: With repository access
  • Mesrai Account: Sign up here

Installation

1. Install Mesrai CLI

Install globally via npm:

npm install -g @mesrai/cli

Or using yarn:

yarn global add @mesrai/cli

Or using pnpm:

pnpm add -g @mesrai/cli

Verify installation:

mesrai --version
# Output: @mesrai/cli v1.5.2

2. Authenticate

Login to your Mesrai account:

mesrai login

This will:

  1. Open browser for authentication
  2. Generate API key
  3. Store credentials locally in ~/.mesrai/config

Manual authentication (for CI/CD):

mesrai login --token YOUR_API_KEY

Get your API key from Mesrai Dashboard.

3. Initialize Project

Navigate to your project directory and link it with Mesrai:

cd your-project
mesrai init

This will:

  • Link your project to your Mesrai account
  • Enable automatic reviews on PRs

Configuration

All configuration is done through the Mesrai Dashboard:

Basic Configuration

  1. Go to app.mesrai.com → Select your repository
  2. Navigate to SettingsReview Settings
  3. Configure:
    • Project name: my-awesome-app
    • Language: JavaScript/TypeScript/Python
    • Framework: React/Vue/Next.js
    • Auto-review: Enable automatic PR reviews
    • Review triggers: Pull requests, push to main
    • File exclusions: node_modules/**, dist/**, **/*.test.js

Advanced Configuration

Navigate to SettingsAdvanced:

  • Multi-language support: Enable multiple languages per repo
  • Custom rules: Security (high severity), Performance (complexity checks), Style enforcement
  • Token optimization: Context depth, max tokens, caching
  • Notifications: Slack webhooks, email recipients

Environment Variables

Required Variables

# .env
MESRAI_API_KEY=mr_xxxxxxxxxxxxxxxx
MESRAI_PROJECT_ID=proj_xxxxxxxxxxxxxxxx

Optional Variables

# Advanced configuration
MESRAI_API_URL=https://api.mesrai.com
MESRAI_TIMEOUT=30000
MESRAI_MAX_RETRIES=3
MESRAI_LOG_LEVEL=info
 
# Feature flags
MESRAI_ENABLE_CACHING=true
MESRAI_ENABLE_TELEMETRY=false

Loading Environment Variables

Using dotenv (Node.js):

// index.js
require("dotenv").config();
const { MesraiClient } = require("@mesrai/sdk");
 
const client = new MesraiClient({
  apiKey: process.env.MESRAI_API_KEY,
});

Using direnv (Shell):

# .envrc
export MESRAI_API_KEY=mr_xxxxxxxxxxxxxxxx
export MESRAI_PROJECT_ID=proj_xxxxxxxxxxxxxxxx

Then run:

direnv allow

Local Development

Testing Reviews Locally

Run review on current branch:

mesrai review

Review specific files:

mesrai review src/components/Button.tsx

Review with specific focus:

mesrai review --focus security
mesrai review --focus performance
mesrai review --focus style

Mock Mode

Test without consuming tokens:

mesrai review --mock

Uses cached responses or sample data.

Debug Mode

Enable verbose logging:

mesrai review --debug

Output:

[DEBUG] Loading configuration from dashboard
[DEBUG] Authenticating with API key: mr_***************
[DEBUG] Fetching changed files...
[DEBUG] Found 5 changed files
[DEBUG] Building context (max 50 files)...
[DEBUG] Context built: 23 files, 8,456 tokens
[DEBUG] Submitting review request...
[DEBUG] Review ID: rev_abc123
[DEBUG] Polling for results...
[DEBUG] Review completed in 3.2s

IDE Integration

VS Code Extension

Install Mesrai extension:

  1. Open VS Code
  2. Go to Extensions (Cmd+Shift+X)
  3. Search “Mesrai”
  4. Click Install

Features:

  • Inline review suggestions
  • Real-time code analysis
  • Quick fixes
  • Review status in status bar

Configuration (settings.json):

{
  "mesrai.enabled": true,
  "mesrai.autoReview": true,
  "mesrai.showInlineHints": true,
  "mesrai.apiKey": "${env:MESRAI_API_KEY}"
}

IntelliJ/WebStorm Plugin

Install from JetBrains Marketplace:

  1. Go to SettingsPlugins
  2. Search “Mesrai”
  3. Click Install
  4. Restart IDE

Configuration:

File → Settings → Tools → Mesrai
- API Key: [Enter key]
- Auto Review: ✓
- Show Inline Hints: ✓

Vim/Neovim Plugin

Install via vim-plug:

" .vimrc or init.vim
Plug 'mesrai/vim-mesrai'
 
" Configuration
let g:mesrai_api_key = $MESRAI_API_KEY
let g:mesrai_auto_review = 1

Commands:

:MesraiReview          " Review current file
:MesraiReviewAll       " Review all changed files
:MesraiStatus          " Show review status

CI/CD Integration

GitHub Actions

Create workflow file:

# .github/workflows/mesrai.yml
name: Mesrai Code Review
 
on:
  pull_request:
    types: [opened, synchronize]
 
jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
 
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: "20"
 
      - name: Install Mesrai CLI
        run: npm install -g @mesrai/cli
 
      - name: Run Mesrai Review
        env:
          MESRAI_API_KEY: ${{ secrets.MESRAI_API_KEY }}
        run: |
          mesrai review \
            --format github \
            --output review.json
 
      - name: Post Review Results
        uses: actions/github-script@v6
        with:
          script: |
            const fs = require('fs');
            const review = JSON.parse(fs.readFileSync('review.json'));
 
            await github.rest.issues.createComment({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: context.issue.number,
              body: review.summary
            });

GitLab CI

Add to .gitlab-ci.yml:

# .gitlab-ci.yml
mesrai_review:
  stage: test
  image: node:20
  before_script:
    - npm install -g @mesrai/cli
    - mesrai login --token $MESRAI_API_KEY
  script:
    - mesrai review --format gitlab
  only:
    - merge_requests

CircleCI

Add to .circleci/config.yml:

# .circleci/config.yml
version: 2.1
 
jobs:
  mesrai_review:
    docker:
      - image: cimg/node:20.0
    steps:
      - checkout
      - run:
          name: Install Mesrai
          command: npm install -g @mesrai/cli
      - run:
          name: Run Review
          command: |
            mesrai login --token $MESRAI_API_KEY
            mesrai review
 
workflows:
  version: 2
  review:
    jobs:
      - mesrai_review:
          filters:
            branches:
              ignore: main

Jenkins

Add to Jenkinsfile:

// Jenkinsfile
pipeline {
    agent any
 
    environment {
        MESRAI_API_KEY = credentials('mesrai-api-key')
    }
 
    stages {
        stage('Code Review') {
            steps {
                sh 'npm install -g @mesrai/cli'
                sh 'mesrai login --token $MESRAI_API_KEY'
                sh 'mesrai review --format json > review.json'
            }
        }
 
        stage('Post Results') {
            steps {
                archiveArtifacts artifacts: 'review.json'
                publishHTML([
                    reportDir: '.',
                    reportFiles: 'review.json',
                    reportName: 'Mesrai Review'
                ])
            }
        }
    }
}

Docker Setup

Dockerfile

Create containerized environment:

# Dockerfile
FROM node:20-alpine
 
# Install Mesrai CLI
RUN npm install -g @mesrai/cli
 
# Set working directory
WORKDIR /app
 
# Copy project files
COPY . .
 
# Install dependencies
RUN npm install
 
# Default command
CMD ["mesrai", "review"]

Build and run:

docker build -t mesrai-env .
docker run -e MESRAI_API_KEY=$MESRAI_API_KEY mesrai-env

Docker Compose

# docker-compose.yml
version: "3.8"
 
services:
  mesrai:
    image: node:20-alpine
    working_dir: /app
    volumes:
      - .:/app
    environment:
      - MESRAI_API_KEY=${MESRAI_API_KEY}
    command: >
      sh -c "npm install -g @mesrai/cli &&
             mesrai login --token $MESRAI_API_KEY &&
             mesrai review"

Run:

docker-compose up mesrai

Troubleshooting

Authentication Errors

Error: Invalid API key

Solution:

# Verify API key
echo $MESRAI_API_KEY
 
# Re-authenticate
mesrai logout
mesrai login

Configuration Errors

Error: Invalid configuration

Solution:

  1. Verify your repository is linked in the dashboard
  2. Check repository settings at app.mesrai.com
  3. Re-run mesrai init to re-link your project

Network Issues

Error: Connection timeout

Solution:

# Check connectivity
curl https://api.mesrai.com/health
 
# Use proxy if needed
export HTTPS_PROXY=http://proxy.example.com:8080
mesrai review

Permission Issues

Error: Permission denied

Solution:

# Fix file permissions
chmod +x ~/.mesrai/bin/mesrai
 
# Fix directory permissions
chmod 700 ~/.mesrai

Uninstallation

Remove CLI

npm uninstall -g @mesrai/cli

Remove Configuration

rm -rf ~/.mesrai

Remove Project Linking

Unlink your project via the dashboard or CLI:

mesrai unlink

Next Steps

Support

Need help with setup?