MCP Endpoint Shield via Cursor Hooks
MCP Endpoint Shield via Cursor Hooks provides zero-installation runtime security for MCP servers by leveraging Cursor's native hook system. It intercepts all MCP calls (requests and responses), performs validation, blocks malicious activity, and reports threats to your security dashboard—without requiring any MCP server configuration or wrapper installation.
✨ Key Advantages
✅ Zero Installation - No standalone apps or packages to install
✅ No MCP Config Changes - Works without wrapping your MCP servers
✅ Transparent Integration - Uses Cursor's native hook mechanism
✅ Real-time Protection - Intercepts every MCP request and response
✅ Centralized Monitoring - All threats reported to Akto dashboard
✅ Automatic Updates - Hook scripts auto-sync security policies
✅ Minimal Overhead - Lightweight scripts with negligible performance impact
🔄 How It Works
Cursor's hook system allows you to execute custom scripts before and after MCP operations. Akto leverages these hooks to provide comprehensive security:
┌────────────────────────────────────────────────────────────────────┐
│ Cursor IDE │
│ │
│ User Request ──▶ beforeMCPExecution Hook │
│ │ │
│ ▼ │
│ [mcp-guard-before.sh] │
│ │ │
│ ├─ Check guardrail policies │
│ ├─ Validate request syntax │
│ ├─ Detect malicious patterns │
│ │ │
│ ├─ If malicious: │
│ │ ├─ Block request │
│ │ └─ Report to Akto Dashboard ────────┐ │
│ │ │ │
│ ├─ If safe: │ │
│ │ └─ Report event to Akto Dashboard ──┤ │
│ │ │ │
│ ▼ │ │
│ MCP Server Execution │ │
│ │ │ │
│ ▼ ▼ │
│ afterMCPExecution Hook ┌──────────────┐ │
│ │ │ Akto │ │
│ ▼ │ Dashboard │ │
│ [mcp-guard-after.sh] │ │ │
│ │ │ - Threats │ │
│ ├─ Check guardrail policies │ - Analytics │ │
│ ├─ Analyze response data │ - Alerts │ │
│ ├─ Detect sensitive leaks │ - Reports │ │
│ │ └──────────────┘ │
│ ├─ If malicious: │ │
│ │ ├─ Block/Redact response │ │
│ │ └─ Report to Akto Dashboard ────────┘ │
│ │ │
│ ├─ If safe: │
│ │ └─ Report event to Akto Dashboard ────────────┘
│ │ │
│ ▼ │
│ Response to User │
└────────────────────────────────────────────────────────────────────┘Key Points:
beforeMCPExecutionhook checks guardrail policies and validates requestsafterMCPExecutionhook checks guardrail policies and analyzes responsesBoth hooks report to Akto Dashboard regardless of whether threats are detected
Malicious requests/responses are blocked with standard JSON-RPC errors
All events (safe and malicious) are logged for compliance and analytics
📦 Setup Guide
Prerequisites
Cursor IDE installed (version 0.40+ with hooks support)
Akto API token (Get from Akto Dashboard)
macOS, Linux, or Windows with bash/zsh support
Step 1: Create Hook Directory
Create the Cursor hooks directory if it doesn't exist:
Step 2: Download Hook Scripts
Download the Akto MCP guard scripts from our GitHub repository:
Option A: Using curl
Option B: Using wget
Option C: Clone the Repository
Latest Version:
Step 3: Configure Hooks in Cursor
Create or edit the Cursor hooks configuration file:
Configuration Options:
version: Hook configuration schema version (currently1)beforeMCPExecution: Array of hooks to run before MCP server executionafterMCPExecution: Array of hooks to run after MCP server executioncommand: Absolute path to the hook script
Example with multiple hooks:
Step 4: Set Your Akto API Token
The hook scripts need your Akto API token to report security events.
Option A: Environment Variable (Recommended)
Add to your shell configuration file (~/.bashrc, ~/.zshrc, or ~/.profile):
Reload your shell:
Option B: Configuration File
Create a configuration file:
The hook scripts will automatically read from this file.
Option C: Inline in Hook Script
Edit the hook scripts to include your token directly (less secure):
Step 5: Restart Cursor
Restart Cursor IDE to activate the hooks:
Step 6: Verify Installation
Check that hooks are working:
Open Cursor Settings
Go to
Settings→Extensions→MCPLook for "Hooks enabled" indicator
Check Hook Logs
Test with MCP Operation
Use any MCP tool in Cursor (e.g., file search, code completion). You should see:
🛡️ Security Features
Request Validation (beforeMCPExecution)
The before-execution hook performs:
Guardrail Policy Check - Applies organization-wide security policies
Request Validation - Validates JSON-RPC structure and parameters
Threat Detection - Identifies malicious patterns:
SQL Injection Attempts - Blocks malicious SQL patterns in tool arguments
Path Traversal - Prevents access to sensitive file paths (
/etc/passwd,.env, etc.)Command Injection - Detects shell command injection attempts
Unsafe Tool Calls - Blocks dangerous MCP tool invocations
Rate Limiting - Prevents abuse through excessive requests
Dashboard Reporting - Reports all events (safe and malicious) to Akto Dashboard
Example: Blocked Request
Example: Log Entry for Blocked Request
Response Analysis (afterMCPExecution)
The after-execution hook performs:
Guardrail Policy Check - Applies response-specific security policies
Response Validation - Validates response structure and data
Threat Detection - Identifies security issues:
Sensitive Data Exposure - Detects credentials, API keys, tokens
PII Leakage - Identifies personal information (SSN, credit cards, emails)
Excessive Data Return - Flags responses with unusually large payloads
Anomalous Behavior - Detects deviations from normal patterns
Data Exfiltration - Monitors for suspicious data access patterns
Compliance Violations - Checks against configured security policies
Dashboard Reporting - Reports all events (safe and malicious) to Akto Dashboard
Example: Detected Sensitive Data
Comprehensive Reporting
All events are reported to Akto Dashboard:
✅ Safe Requests - Normal operations logged for analytics
✅ Safe Responses - Clean responses tracked for compliance
⚠️ Blocked Requests - Threat details and remediation actions
⚠️ Blocked Responses - Sensitive data exposures and redactions
This provides complete visibility into:
Total MCP operation volume
Security threat trends
Compliance audit trails
Developer behavior patterns
Risk assessment data
📊 Akto Dashboard Integration
Viewing Security Events
Login to Akto Dashboard: https://app.akto.io
Navigate to MCP Shield Section:
Go to
Security→MCP Endpoint Shield→Cursor Hooks
View Real-time Events:
See all MCP requests/responses from your Cursor IDE
Filter by severity, threat type, MCP server, or time range
Drill down into specific incidents for detailed analysis
Event Categories
The dashboard organizes events into categories:
Safe Operations:
mcp.request.allowed- Request passed all guardrail checksmcp.response.clean- Response contained no sensitive data
Threat Events:
mcp.request.blocked- Request violated guardrail policymcp.response.blocked- Response contained sensitive/malicious datamcp.anomaly.detected- Unusual behavior pattern identified
Each event includes:
Timestamp and duration
MCP server name and tool called
Request/response payload (sanitized)
Guardrail policies evaluated
Threat type and severity (if applicable)
User and machine identifier
Remediation action taken
Key Metrics
The dashboard shows:
Total MCP Calls - Volume of MCP operations per day/week/month
Blocked Threats - Count and types of threats prevented
Sensitive Data Exposures - Detected leaks of credentials or PII
Top Threat Actors - Users/machines with most security events
MCP Server Risk Scores - Which servers pose highest risk
Compliance Status - Adherence to security policies
Guardrail Policy Effectiveness - Which policies trigger most often
Alert Configuration
Set up notifications for critical events:
Go to
Settings→Alerts→MCP ShieldConfigure alert rules:
Immediate Alert: Any high-severity threat detected
Daily Digest: Summary of all security events
Threshold Alert: More than 5 blocked requests in 1 hour
Choose notification channels:
Slack webhook
Email
PagerDuty
Custom webhooks
Example Alert Rule:
🔧 Configuration Options
Hook Script Environment Variables
Configure the hook behavior via environment variables:
Advanced Hook Configuration
Edit ~/.cursor/hooks.json for advanced scenarios:
Conditional Hook Execution:
Hook with Arguments:
Timeout Configuration:
Custom Guardrail Policies
Create custom guardrail policies in your Akto dashboard:
Go to
Settings→MCP Shield→Guardrail PoliciesCreate a new policy or edit default policy
Configure rules for both request and response phases
Example Policy:
🏢 Enterprise Deployment
Centralized Configuration Management
For organizations deploying to multiple developers:
Step 1: Create Organization-wide Config Repository
Step 2: Create Deployment Script
Step 3: Distribute to Developers
Policy Enforcement
Enforce hook installation across the organization:
Option A: Pre-commit Checks
Add to your git hooks:
Option B: CI/CD Verification
Option C: Automated Monitoring
Deploy monitoring script via MDM:
Audit and Compliance
SOC 2 / ISO 27001 Requirements:
Access Logging: All MCP operations logged to Akto dashboard
Threat Prevention: Real-time blocking of malicious requests/responses
Data Loss Prevention: Detection of sensitive data exposures
Incident Response: Automated alerting and reporting
Audit Trail: Immutable logs for compliance audits
Complete Coverage: Both request and response phases monitored
Generate Compliance Report:
🧩 Troubleshooting
Hooks Not Executing
Issue: MCP operations work but hooks don't seem to run
Diagnosis:
Fix:
API Token Not Set
Issue: AKTO_API_TOKEN is not set in logs
Fix:
Slow Hook Execution
Issue: MCP operations are noticeably slower
Diagnosis:
Fix:
Permission Denied Errors
Issue: Permission denied: ~/.cursor/hooks/mcp-guard-before.sh
Fix:
Hook Script Crashes
Issue: Hook exits with error code, MCP operations fail
Diagnosis:
Fix:
Events Not Appearing in Dashboard
Issue: Hooks execute but events don't appear in Akto dashboard
Diagnosis:
Fix:
🔄 Comparison: Cursor Hooks vs Traditional Installation
Installation
Simple script + JSON config
Requires .pkg/.deb/.exe installer
MCP Config Changes
None required
Automatic config wrapping
IDE Support
Cursor only
Cursor, VS Code, Claude Desktop
Updates
Manual script update via Git
Auto-update via agent
Performance Overhead
~5-10ms per call
~2-5ms per call
Enterprise Deployment
Via script distribution
Via MDM (Jamf, Intune)
Multi-IDE Protection
Requires separate setup
Single agent protects all IDEs
Offline Mode
Limited (requires API calls)
Full offline detection available
Customization
Edit hook scripts locally
Central policy management
Maintenance
Manual script updates
Automatic via package manager
Reporting Coverage
Request + Response reporting
Request + Response reporting
When to use Cursor Hooks:
You only use Cursor IDE
Want zero-installation security
Need quick setup for individual developers
Prefer scriptable, transparent solution
Want to inspect/modify hook scripts
When to use Traditional Installation:
Multiple IDEs in use (Cursor + VS Code + Claude)
Enterprise-wide deployment via MDM
Need automatic updates and centralized management
Require offline/air-gapped operation
Want lowest possible performance overhead
📚 Additional Resources
Documentation
Source Code
Support
Email: [email protected]
Discord: https://www.akto.io/community
Slack: Join
#mcp-endpoint-shieldchannelGitHub Issues: Report bugs
Community
Akto Blog - Latest security insights
Case Studies - How teams use Akto
🔒 Security Guarantees
✅ Transparency: Safe MCP traffic is never altered or delayed
✅ Clarity: Blocked requests return standard JSON-RPC errors with clear explanations
✅ Privacy: All data is encrypted in transit (TLS 1.3)
✅ Compliance: SOC 2, ISO 27001, GDPR compliant
✅ Minimal Footprint: Hooks execute in <10ms for 99.9% of requests
✅ Reliability: Graceful degradation - if hook fails, MCP operation proceeds
✅ Complete Coverage: Both request and response phases protected
✅ Comprehensive Reporting: All events logged to Akto Dashboard
📄 License
Akto MCP Endpoint Shield via Cursor Hooks is provided under the Akto Enterprise License.
🎯 Get Started Now
Last updated: 2025-12-24
Last updated
Was this helpful?