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/cliOr using yarn:
yarn global add @mesrai/cliOr using pnpm:
pnpm add -g @mesrai/cliVerify installation:
mesrai --version
# Output: @mesrai/cli v1.5.22. Authenticate
Login to your Mesrai account:
mesrai loginThis will:
- Open browser for authentication
- Generate API key
- Store credentials locally in
~/.mesrai/config
Manual authentication (for CI/CD):
mesrai login --token YOUR_API_KEYGet your API key from Mesrai Dashboard.
3. Initialize Project
Navigate to your project directory and link it with Mesrai:
cd your-project
mesrai initThis will:
- Link your project to your Mesrai account
- Enable automatic reviews on PRs
Configuration
All configuration is done through the Mesrai Dashboard:
Basic Configuration
- Go to app.mesrai.com → Select your repository
- Navigate to Settings → Review Settings
- 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 Settings → Advanced:
- 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_xxxxxxxxxxxxxxxxOptional 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=falseLoading 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_xxxxxxxxxxxxxxxxThen run:
direnv allowLocal Development
Testing Reviews Locally
Run review on current branch:
mesrai reviewReview specific files:
mesrai review src/components/Button.tsxReview with specific focus:
mesrai review --focus security
mesrai review --focus performance
mesrai review --focus styleMock Mode
Test without consuming tokens:
mesrai review --mockUses cached responses or sample data.
Debug Mode
Enable verbose logging:
mesrai review --debugOutput:
[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.2sIDE Integration
VS Code Extension
Install Mesrai extension:
- Open VS Code
- Go to Extensions (Cmd+Shift+X)
- Search “Mesrai”
- 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:
- Go to Settings → Plugins
- Search “Mesrai”
- Click Install
- 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 = 1Commands:
:MesraiReview " Review current file
:MesraiReviewAll " Review all changed files
:MesraiStatus " Show review statusCI/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_requestsCircleCI
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: mainJenkins
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-envDocker 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 mesraiTroubleshooting
Authentication Errors
Error: Invalid API key
Solution:
# Verify API key
echo $MESRAI_API_KEY
# Re-authenticate
mesrai logout
mesrai loginConfiguration Errors
Error: Invalid configuration
Solution:
- Verify your repository is linked in the dashboard
- Check repository settings at app.mesrai.com
- Re-run
mesrai initto 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 reviewPermission Issues
Error: Permission denied
Solution:
# Fix file permissions
chmod +x ~/.mesrai/bin/mesrai
# Fix directory permissions
chmod 700 ~/.mesraiUninstallation
Remove CLI
npm uninstall -g @mesrai/cliRemove Configuration
rm -rf ~/.mesraiRemove Project Linking
Unlink your project via the dashboard or CLI:
mesrai unlinkNext Steps
Support
Need help with setup?