ping_n8n
Test n8n instance connectivity
ping_n8n
Test connectivity to your n8n instance and verify API credentials are working.
Overview
The ping_n8n tool performs a simple health check on your configured n8n instance. It's useful for:
- Verifying n8n is reachable
- Testing API key validity
- Checking connection configuration
- Troubleshooting connectivity issues
Usage
Natural Language
Ask your AI assistant:
Can you ping my n8n instance?
Test my n8n connection
Is my n8n instance working?
Direct Tool Call
Using the MCP SDK:
const result = await client.callTool({
name: 'ping_n8n',
arguments: {},
})
HTTP Request
curl -X POST http://localhost:3001/mcp?apiKey=mcp_your_key \
-H "Content-Type: application/json" \
-d '{
"method": "tools/call",
"params": {
"name": "ping_n8n",
"arguments": {}
}
}'
Parameters
This tool takes no parameters.
{
"name": "ping_n8n",
"arguments": {}
}
Response
Success Response
When n8n is reachable and API key is valid:
{
"success": true,
"message": "n8n connection successful",
"data": {
"version": "1.0.0",
"url": "https://n8n.example.com",
"authenticated": true
}
}
Fields:
success(boolean): Alwaystruefor successful pingmessage(string): Human-readable success messagedata.version(string): n8n instance versiondata.url(string): n8n instance URLdata.authenticated(boolean): API key authentication status
Error Response
When n8n is unreachable or API key is invalid:
{
"success": false,
"error": "n8n connection failed",
"details": "Could not connect to https://n8n.example.com",
"errorCode": "CONNECTION_FAILED"
}
Fields:
success(boolean): Alwaysfalsefor errorserror(string): Error messagedetails(string): Additional error informationerrorCode(string): Machine-readable error code
Error Codes
| Code | Description | Resolution |
|---|---|---|
CONNECTION_FAILED | Cannot reach n8n instance | Check URL and network |
INVALID_API_KEY | API key is invalid | Verify API key in n8n settings |
TIMEOUT | Request timed out | Check n8n performance |
UNKNOWN_ERROR | Unexpected error | Check logs for details |
Examples
Example 1: Successful Ping
Request:
User: "Can you test my n8n connection?"
AI Response:
I'll test your n8n connection...
✓ Connection successful!
Your n8n instance at https://n8n.example.com is running
version 1.0.0 and the API key is valid.
Example 2: Connection Failed
Request:
User: "Ping my n8n instance"
AI Response:
I tried to ping your n8n instance but the connection failed.
Error: Could not connect to https://n8n.example.com
This could mean:
1. n8n is not running
2. The URL is incorrect
3. Network connectivity issues
Would you like me to help troubleshoot?
Example 3: Invalid API Key
Request:
User: "Test n8n connectivity"
AI Response:
I was able to reach your n8n instance, but the API key
authentication failed.
Please check:
1. API key is correct in the dashboard
2. API key hasn't been revoked in n8n
3. API key has the required permissions
Would you like to update your API key?
What Gets Tested
The ping_n8n tool performs these checks:
-
Network Connectivity
- Can reach n8n URL
- DNS resolution works
- Port is accessible
-
API Authentication
- API key is valid
- Key has correct format
- Key has necessary permissions
-
n8n Health
- n8n API is responding
- n8n version can be retrieved
- n8n is not in maintenance mode
Implementation Details
Request Flow
sequenceDiagram
AI->>MCP Server: Call ping_n8n
MCP Server->>Next.js API: Validate API key
Next.js API->>Database: Get n8n connection
Database->>Next.js API: Return connection details
Next.js API->>MCP Server: Connection validated
MCP Server->>n8n Instance: GET /health
n8n Instance->>MCP Server: 200 OK
MCP Server->>AI: Success response
Timeout
- Default: 5 seconds
- Configurable: Via environment variable
- Behavior: Returns timeout error if exceeded
Caching
Results are not cached. Each call makes a fresh request to n8n.
Use Cases
1. Pre-flight Check
Before executing workflows, verify connectivity:
User: "Execute my payment workflow"
AI: "Let me first check your n8n connection..."
[Calls ping_n8n]
AI: "Connection is good. Executing payment workflow now."
2. Troubleshooting
When workflows fail, test connectivity:
User: "My workflow failed to execute"
AI: "Let me test your n8n connection to diagnose..."
[Calls ping_n8n]
AI: "I found the issue - your n8n instance is not responding."
3. Health Monitoring
Periodically check n8n health:
Script runs every 5 minutes:
- Call ping_n8n
- If fails, send alert
- Log result
4. Setup Validation
After adding an n8n connection:
User: "I just added my n8n connection"
AI: "Great! Let me verify it works..."
[Calls ping_n8n]
AI: "Perfect! Your connection is working correctly."
Best Practices
When to Use
✅ Do use ping_n8n:
- Before executing workflows
- After configuration changes
- When troubleshooting issues
- For health monitoring
❌ Don't use ping_n8n:
- Before every single workflow execution (unnecessary overhead)
- In high-frequency loops
- When caching would be more appropriate
Error Handling
Handle errors gracefully:
const result = await callTool('ping_n8n')
if (!result.success) {
switch (result.errorCode) {
case 'CONNECTION_FAILED':
// n8n is down, retry later
break
case 'INVALID_API_KEY':
// Prompt user to update key
break
case 'TIMEOUT':
// n8n is slow, maybe retry with longer timeout
break
default:
// Log and alert
break
}
}
Logging
Log ping results for monitoring:
const result = await callTool('ping_n8n')
logger.info('n8n ping', {
success: result.success,
errorCode: result.errorCode,
duration: result.duration,
timestamp: new Date().toISOString(),
})
Performance
Response Time
Typical response times:
- Fast network: 50-200ms
- Slow network: 500ms-2s
- Timeout: 5s (configured limit)
Resource Usage
Minimal resource usage:
- Single HTTP GET request
- No database writes
- No file I/O
- Lightweight processing
Monitoring
Metrics to Track
- Success rate: Percentage of successful pings
- Response time: Average ping duration
- Error distribution: Most common errors
- Availability: n8n uptime percentage
Alerting
Set up alerts for:
- Multiple consecutive ping failures
- Ping timeouts
- API key authentication failures
Security
What's Exposed
The ping endpoint exposes:
- n8n version number
- n8n URL
- API key validity
What's Protected
The ping does NOT expose:
- Actual API key value
- Workflow details
- User data
- Internal configuration
Rate Limiting
No built-in rate limiting currently. Consider:
- Adding rate limits for production
- Caching results for frequent pings
- Using health check endpoints
Limitations
Current limitations:
- No detailed diagnostics: Only basic connectivity check
- No credential validation: Doesn't test specific permissions
- No workflow testing: Doesn't validate workflows work
- No version compatibility: Doesn't check n8n version compatibility
Future Enhancements
Planned improvements:
- Detailed health check: CPU, memory, disk usage
- Credential validation: Test specific API key permissions
- Version compatibility: Warn about version mismatches
- Latency measurement: Measure and report ping latency
- Historical data: Track ping results over time
Troubleshooting
Ping Always Fails
If ping consistently fails:
-
Check n8n URL:
# Test in browser https://n8n.example.com -
Verify API key:
- Go to n8n → Settings → API
- Check key is active
- Try regenerating key
-
Test network:
curl https://n8n.example.com/health -
Check firewall:
- Allow outbound HTTPS
- Allow connections to n8n port
Ping Timeout
If ping times out:
- Check n8n server resources
- Verify network latency
- Increase timeout in config
- Check n8n logs for slowness
Intermittent Failures
If ping sometimes fails:
- Check n8n server stability
- Monitor network reliability
- Review n8n error logs
- Consider implementing retry logic
Related Tools
execute_workflow(planned) - Execute workflows after ping succeedsget_workflow_status(planned) - Check workflow healthlist_workflows(planned) - Verify workflows are accessible