A Model Context Protocol (MCP) server that integrates with the HighLevel API using OAuth2 authentication managed through n8n workflows.
This project provides a complete solution for managing HighLevel OAuth2 authentication and API interactions using n8n as the authentication orchestrator. The system automatically handles token storage, refresh, and retrieval, making it easy to build applications that interact with the HighLevel API.
The system consists of three main components:
Three automated workflows handle the OAuth2 flow:
- Authorization Workflow: Captures the OAuth callback and exchanges the authorization code for access and refresh tokens
- Token Refresh Workflow: Automatically refreshes the access token every 23 hours
- Token Retrieval API: Provides a webhook endpoint for the MCP server to retrieve the current access token
A Python-based server that:
- Retrieves access tokens from n8n
- Provides a clean interface for HighLevel API calls
- Handles token expiration and automatic retry
- Includes helper methods for common API operations
Tokens are stored as n8n environment variables:
HIGHLEVEL_ACCESS_TOKEN: Current access tokenHIGHLEVEL_REFRESH_TOKEN: Refresh token for obtaining new access tokens
Before setting up this integration, you need:
-
n8n Instance: A running n8n instance with API access
- Instance URL (e.g.,
https://n8n.mikee.ai) - API Key for programmatic access
- Instance URL (e.g.,
-
HighLevel OAuth App: Register an OAuth application in HighLevel Marketplace
- Client ID
- Client Secret
- Redirect URI (will be your n8n webhook URL)
-
Python Environment: Python 3.11+ with the following packages:
requests
git clone <repository-url>
cd highlevel-mcp-serverCreate a .env file or export the following environment variables:
export N8N_INSTANCE_URL="https://your-n8n-instance.com"
export N8N_API_KEY="your-n8n-api-key"
export HIGHLEVEL_CLIENT_ID="your-highlevel-client-id"
export HIGHLEVEL_CLIENT_SECRET="your-highlevel-client-secret"
export HIGHLEVEL_REDIRECT_URI="https://your-n8n-instance.com/webhook/oauth/callback/highlevel"The workflows have already been uploaded to your n8n instance:
- HighLevel OAuth2 - Authorization (ID:
ncH51cSQXxuKy6LB) - HighLevel OAuth2 - Token Refresh (ID:
Mrd1JuSoe9vKNwSn) - HighLevel OAuth2 - Token Retrieval API (ID:
uyPHv0OQeiWFEa84)
In your n8n instance, set the following environment variables:
- Go to Settings → Environment Variables
- Add the following variables:
HIGHLEVEL_CLIENT_ID: Your HighLevel OAuth app client IDHIGHLEVEL_CLIENT_SECRET: Your HighLevel OAuth app client secretHIGHLEVEL_REDIRECT_URI: Your OAuth callback URLN8N_INSTANCE_URL: Your n8n instance URL (already set)N8N_API_KEY: Your n8n API key (already set)
- Log in to your n8n instance
- Navigate to Workflows
- Find and activate the three HighLevel OAuth2 workflows:
- HighLevel OAuth2 - Authorization
- HighLevel OAuth2 - Token Refresh
- HighLevel OAuth2 - Token Retrieval API
- In your HighLevel OAuth app settings, get the installation URL
- Visit the installation URL to authorize the app
- You will be redirected to the n8n webhook, which will:
- Exchange the authorization code for tokens
- Store the tokens in n8n variables
- Display a success message
from mcp_server_improved import HighLevelMCPServer
# Initialize the server
server = HighLevelMCPServer()
# Get access token
token = server.get_access_token()
print(f"Access Token: {token}")
# Get locations
locations = server.get_locations()
print(f"Locations: {locations}")
# Get contacts for a location
contacts = server.get_contacts(location_id="your-location-id", limit=20)
print(f"Contacts: {contacts}")
# Create a new contact
new_contact = server.create_contact(
location_id="your-location-id",
contact_data={
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@example.com",
"phone": "+1234567890"
}
)
print(f"New Contact: {new_contact}")python3.11 mcp_server_improved.pyThis will:
- Initialize the MCP server
- Retrieve the access token from n8n
- Make a test API call to get locations
- Display the results
Trigger: Webhook at /webhook/oauth/callback/highlevel
Process:
- Receives OAuth callback with authorization code
- Exchanges code for access and refresh tokens
- Stores tokens in n8n variables
- Returns success response
Webhook URL: https://your-n8n-instance.com/webhook/oauth/callback/highlevel
Trigger: Schedule (every 23 hours)
Process:
- Retrieves current refresh token from n8n variables
- Requests new access and refresh tokens from HighLevel
- Updates tokens in n8n variables
Note: This workflow runs automatically to ensure tokens never expire.
Trigger: Webhook at /webhook/highlevel/access-token
Process:
- Receives request from MCP server
- Retrieves current access token from n8n variables
- Returns token in JSON format
Webhook URL: https://your-n8n-instance.com/webhook/highlevel/access-token
Retrieves the current HighLevel access token from n8n.
Returns: Access token string or None if retrieval failed
Makes a call to the HighLevel API.
Parameters:
endpoint: API endpoint (e.g., "v2/contacts/")method: HTTP method (GET, POST, PUT, DELETE)data: Request body data for POST/PUT requestsparams: Query parameters
Returns: API response data or None if request failed
Gets all locations accessible to the authenticated user.
Gets contacts for a specific location.
Creates a new contact.
Gets opportunities for a specific location.
Possible causes:
- Workflows are not activated in n8n
- OAuth authorization has not been completed
- Tokens are not stored in n8n variables
- n8n environment variables are not configured
Solution:
- Check that all three workflows are active in n8n
- Complete the OAuth authorization flow
- Verify environment variables in n8n settings
- Check n8n logs for errors
Possible causes:
- Access token has expired
- Invalid token
- Insufficient scopes
Solution:
- The MCP server automatically retries with a fresh token
- Check that the token refresh workflow is running
- Verify OAuth app scopes in HighLevel
Possible causes:
- Workflows are not activated
- Incorrect webhook path
- n8n instance not accessible
Solution:
- Activate workflows in n8n
- Verify webhook URLs match the workflow configuration
- Test webhook URLs with curl or browser
- Environment Variables: Never commit API keys or secrets to version control
- Token Storage: Tokens are stored securely in n8n's encrypted variable storage
- HTTPS: Always use HTTPS for n8n webhooks and API calls
- Access Control: Limit n8n API key permissions to only what's needed
- Token Refresh: Tokens are automatically refreshed to minimize exposure time
highlevel-mcp-server/
├── README.md # This file
├── SETUP_GUIDE.md # Detailed setup instructions
├── mcp_server.py # Original MCP server
├── mcp_server_improved.py # Improved MCP server with error handling
├── upload_workflows.py # Script to upload workflows to n8n
├── workflows/ # n8n workflow JSON files
│ ├── auth_workflow_simple.json # Authorization workflow
│ ├── refresh_workflow_simple.json # Token refresh workflow
│ └── retrieval_workflow_simple.json # Token retrieval workflow
├── MCP Server for HighLevel OAuth2 API - Design Document.md
└── marketplace.gohighlevel.com_docs_Authorization_OAuth2.0_index.html.md
Contributions are welcome! Please feel free to submit issues or pull requests.
MIT License - See LICENSE file for details
For issues or questions:
- Check the troubleshooting section
- Review n8n workflow execution logs
- Check HighLevel API documentation
- Open an issue in this repository
- Built with n8n - Workflow automation platform
- Integrates with HighLevel - All-in-one marketing platform
- Follows Model Context Protocol specifications