Integrates with Google's Gemini models for browser automation and text rewriting operations, supporting models like gemini-2.5-flash through the Google Generative AI API.
Automates Grammarly's web interface to analyze text for AI detection and plagiarism scores, and optimizes content through iterative rewrites to meet specified thresholds for AI detection and plagiarism percentages.
Supports OpenAI's API as an LLM provider for both browser automation operations and text rewriting tasks.
Grammarly MCP Server
Single-tool Model Context Protocol (MCP) server for AI detection and plagiarism scoring via Grammarly's web interface. Supports two browser automation providers: Stagehand + Browserbase (default) and Browser Use Cloud (fallback).
What it does
Automates Grammarly's docs UI to get AI detection and plagiarism percentages
Rewrites text via Claude to reduce AI detection scores
Exposes one MCP tool:
grammarly_optimize_text
Note: This server interacts with app.grammarly.com through browser automation. It does not use Grammarly APIs.
Table of Contents
Quick Start
Option A: Stagehand + Browserbase (Recommended)
Prerequisites: Node.js 18+, Grammarly Pro account, Browserbase account
Option B: Browser Use Cloud (Legacy)
Prerequisites: Node.js 18+, Grammarly Pro account, Browser Use Cloud account
Features
Dual provider support: Stagehand + Browserbase (default) or Browser Use Cloud (fallback)
Session persistence: Browserbase contexts preserve Grammarly login across sessions
Self-healing automation: Stagehand adapts to DOM changes automatically
Multi-LLM support: Separate providers for browser automation (
STAGEHAND_LLM_PROVIDER) and text rewriting (REWRITE_LLM_PROVIDER)Live debug URLs: Real-time browser preview during execution
Action caching: Optional caching for faster repeated operations
Structured output: JSON or markdown response formats
Progress notifications: MCP 2025-11-25 progress tracking support
Requirements
All Configurations
Node.js 18+
Grammarly Pro account (for AI detection and plagiarism features)
Claude Code CLI for text rewriting:
npm install -g @anthropic-ai/claude-code claude login
Stagehand Provider (Default)
Browserbase account
BROWSERBASE_API_KEYandBROWSERBASE_PROJECT_ID
Browser Use Provider (Fallback)
Browser Use Cloud account
BROWSER_USE_API_KEYandBROWSER_USE_PROFILE_IDBrowser profile synced with Grammarly login state
Installation
Provider Selection
This server supports two browser automation providers:
Feature | Stagehand (Default) | Browser Use Cloud |
Provider | Browserbase | Browser Use Cloud |
Automation | observe/act/extract | Natural language tasks |
Self-healing | Yes | Limited |
Session persistence | Context IDs | Profile sync |
Debug URL | Real-time | Per-task |
Action caching | Yes | No |
Reliability | Higher | Moderate |
When to Use Stagehand
Production workloads requiring reliability
Need session persistence to avoid re-login overhead
Want real-time debug visibility
Require self-healing for Grammarly UI changes
When to Use Browser Use Cloud
Existing Browser Use Cloud setup
Prefer simpler natural language task descriptions
One-off or testing scenarios
Set the provider via environment variable:
Environment Variables
Environment Isolation
Variable | Required | Default | Description |
| No |
| When
, ignores shell env vars and uses only
file. Prevents IDE-inherited env pollution. |
Provider Configuration
Variable | Required | Default | Description |
| No |
|
or
|
Stagehand + Browserbase
Required when BROWSER_PROVIDER=stagehand:
Variable | Required | Description |
| Yes | API key from |
| Yes | Project ID from Browserbase dashboard |
| No | Persistent context for Grammarly login state |
| No | Reuse existing session (advanced) |
| No | Deprecated. Use
+ model vars instead |
| No | Directory for action caching |
| No* | Google API key for Gemini models. Also accepts
|
* Required when using Google/Gemini models (the default). Get from aistudio.google.com.
Browser Use Cloud
Required when BROWSER_PROVIDER=browser-use:
Variable | Required | Description |
| Yes | API key from |
| Yes | Profile with synced Grammarly login |
LLM Provider Controls
Separate LLM providers for browser automation and text rewriting (can use different providers):
Variable | Required | Default | Description |
| No | Auto-detect | LLM for browser automation:
,
,
,
|
| No | Auto-detect | LLM for text rewriting:
,
,
,
|
If not set, auto-detects from API keys (priority: OpenAI > Google > Anthropic > Claude Code).
Model Selection
Variable | Required | Default | Description |
| No |
| Claude model:
,
,
,
. Auto-selects based on text length and iteration count. |
| No |
| Anthropic model id when using direct Anthropic provider. |
| No |
| OpenAI model name |
| No |
| Google/Gemini model name |
API Keys
Variable | Required | Description |
| No | Claude API key. If not set, uses
CLI auth |
| No* | OpenAI API key. Required when using OpenAI provider. |
| No* | Google API key. Also accepts
. Required for Google provider. |
| No* | Anthropic API key. Required when using direct Anthropic provider. |
* Required when explicitly setting the corresponding LLM provider or for auto-detection.
Timeouts and Logging
Variable | Required | Default | Description |
| No |
|
,
,
,
|
| No |
| LLM request timeout (ms).
is still accepted for compatibility. |
| No |
| MCP connection timeout (ms) |
Running the Server
The server uses stdio transport for MCP communication.
Client Configuration
Configure environment variables in your MCP client. Required:
BROWSERBASE_API_KEY- From browserbase.comBROWSERBASE_PROJECT_ID- From Browserbase dashboard
Automatic Setup
Run the interactive setup script to automatically configure your MCP clients using values from your .env file:
The script will:
Show available MCP clients for your platform
Let you select which clients to configure
Back up existing configs before modifying
Write the appropriate config format (JSON or TOML)
Manual Configuration
Via CLI command:
Or add to ~/.claude/settings.json:
Add to your Claude Desktop config file:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.jsonLinux:
~/.config/Claude/claude_desktop_config.json
Add to ~/.cursor/mcp.json:
Or via UI: Settings → MCP → Add new MCP Server
Add to .vscode/mcp.json in your workspace:
Or via CLI:
Add to ~/.codeium/windsurf/mcp_config.json:
Add to ~/.gemini/settings.json:
Add to ~/.codex/config.toml:
Add to .continue/config.json:
Recommended Configurations
Uses your Claude subscription - no extra API keys:
Forces the cheapest Claude model:
Gemini for browser automation (fast), Claude for rewriting (quality):
Tool: grammarly_optimize_text
Input Parameters
Parameter | Type | Default | Description |
| string | (required) | Text to analyze/optimize |
| enum |
|
,
, or
|
| number |
| Target AI detection threshold (0-100) |
| number |
| Target plagiarism threshold (0-100) |
| number |
| Maximum rewrite iterations (1-20) |
| enum |
|
,
,
,
,
|
| string | — | Domain context (e.g., "legal", "medical") |
| string | — | Additional rewriting instructions |
| string | — | ISO 3166-1 alpha-2 country code for geo-routing |
| enum |
|
or
|
| number |
| Maximum browser automation steps (5-100) |
Output Schema
LLM Configuration
This server uses separate LLM providers for browser automation and text rewriting:
Purpose | Env Var | Use Case |
Browser automation |
| Stagehand observe/act/extract operations |
Text rewriting |
| Claude rewrites text to reduce AI detection |
Example: Different providers for each task:
Auto-detection priority (when provider not explicitly set):
OpenAI - If
OPENAI_API_KEYis setGoogle - If
GOOGLE_GENERATIVE_AI_API_KEYorGEMINI_API_KEYis setAnthropic - If
ANTHROPIC_API_KEYis setClaude Code CLI (fallback) - Uses
claude loginauthentication
Claude model auto-selection (when CLAUDE_MODEL=auto):
Text Length | Iterations | Model |
< 3k chars | ≤ 3 | Haiku (fastest, cheapest) |
3k-12k chars | 4-8 | Sonnet (balanced) |
> 12k chars | > 8 | Opus (highest quality) |
Browser Use LLM Options
When using Browser Use Cloud (BROWSER_PROVIDER=browser-use), the automation uses Browser Use's built-in LLM at $0.002/step. Text rewriting still uses the configured REWRITE_LLM_PROVIDER.
Session Persistence
Browserbase contexts allow you to persist Grammarly login state across sessions.
How Persistence Works
First run: Server creates a Browserbase session. Use the debug URL to manually log into Grammarly.
Note context ID: The context ID appears in server logs or session response.
Subsequent runs: Set
BROWSERBASE_CONTEXT_IDto skip login.
Setup
Performance
Scenario | Initialization Time |
New session, no context | ~30-45 seconds |
Existing context | ~5-10 seconds |
Reusing active session | ~1-2 seconds |
How It Works
Architecture
Stagehand Flow
Get or create Browserbase session with optional context
Initialize Stagehand instance connected to session
Navigate to app.grammarly.com
Use
observe()to find UI elements (new document button, AI detector)Use
act()to interact (click, type text)Use
extract()with Zod schema to get structured scoresReturn scores with debug URL
Browser Use Flow
Create Browser Use session with synced profile
Send natural language task to Browser Use agent
Agent navigates Grammarly, pastes text, runs checks
Return structured scores
Optimization Loop
Initial scoring (iteration 0) on original text
In optimize mode: Loop up to
max_iterations:LLM (via
REWRITE_LLM_PROVIDER) rewrites text based on current scores, tone, domainRe-score via Grammarly
Break early if thresholds met
Generate summary via configured rewrite LLM provider
Development
Build & Quality
Testing
Coverage thresholds (enforced in CI): 85% lines, 85% functions, 75% branches.
Tests use Vitest with V8 coverage. See tests/ for test structure and CLAUDE.md for testing conventions.
Troubleshooting
Server Issues
Server won't start
Check that required environment variables are set:
Stagehand:
BROWSERBASE_API_KEY,BROWSERBASE_PROJECT_IDBrowser Use:
BROWSER_USE_API_KEY,BROWSER_USE_PROFILE_ID
Tool not appearing in client
Verify path to
dist/server.jsis absolute and correctRun
pnpm buildto ensure compilation succeededRestart your MCP client after configuration changes
Stagehand Issues
Browserbase session creation fails
Verify API key and project ID at browserbase.com
Check Browserbase dashboard for quota/limits
Context not persisting login
Ensure you logged into Grammarly while context was active
Context ID must match the session where login occurred
Grammarly sessions may expire; re-login if needed
Self-heal failures
Grammarly UI may have changed significantly
Try with
LOG_LEVEL=debugto see Stagehand observationsReport persistent issues
Browser Use Issues
Session creation fails
Verify API key at cloud.browser-use.com
Check that profile exists and is properly synced
Profile sync issues
Re-sync your Grammarly login using Browser Use tools
Grammarly cookies may have expired
Grammarly Issues
AI detection scores are null
Your Grammarly plan may not include AI Detector. This requires Grammarly Pro with AI detection enabled.
Plagiarism scores are null
Plagiarism checking requires Grammarly Pro subscription.
Claude Issues
Authentication errors
Using CLI auth (recommended):
Using API key:
Ensure CLAUDE_API_KEY is set correctly.
Security Considerations
API Keys: Store securely. Never commit to version control.
Browserbase Contexts: Contain session cookies. Treat context IDs as sensitive.
Browser Use Profiles: Contain Grammarly session state. Treat profile IDs as sensitive.
Data Flow: Text passes through:
Browserbase or Browser Use Cloud (browser automation)
Grammarly (via web UI)
Claude API (for rewriting)
Review each service's privacy policy.
Local Execution: MCP server runs locally via stdio, not over network.
Notes and Limitations
Grammarly Pro Required: AI Detector and Plagiarism Checker require Grammarly Pro. Scores return
nullif unavailable.UI Dependency: Automation uses observe/act/extract (Stagehand) or natural language (Browser Use). Grammarly UI changes may affect reliability.
Text Length: Very long texts may exceed context limits. Consider chunking.
Rate Limits: Browserbase, Browser Use Cloud, and Grammarly have usage limits.
Session Limits: Browserbase sessions have timeout limits. Use contexts for persistence.
External Resources
Browserbase: browserbase.com | Docs
Browser Use: cloud.browser-use.com | Docs
Claude Code: ai-sdk-provider-claude-code
License
MIT License - see LICENSE for details.