Skip to content

All API calls return HTML: missing /api/v1/ path prefix #21

@Uniquecorn73

Description

@Uniquecorn73

Bug Description

All MCP tool calls (list_workflows, list_executions, get_workflow, etc.) return the n8n frontend HTML page instead of JSON API responses.

Root Cause

The axios base URL is set directly to N8N_HOST without the /api/v1/ path prefix:

const n8nApi = axios.create({
  baseURL: N8N_HOST,  // e.g. "https://my-n8n.example.com"
  ...
});

// This results in:
await n8nApi.get('/workflows');
// → GET https://my-n8n.example.com/workflows  ← WRONG (hits SPA catch-all → HTML)

// Should be:
// → GET https://my-n8n.example.com/api/v1/workflows  ← CORRECT (public API)

n8n has two API schemes:

  • /rest/... — internal endpoints requiring cookie/session auth (used by the n8n Editor UI)
  • /api/v1/... — public API endpoints accepting API key auth via X-N8N-API-KEY header

The package sends the X-N8N-API-KEY header (correct for the public API), but hits paths without /api/v1/ prefix. Since n8n's Vue.js SPA has a catch-all route, any unrecognized URL returns index.html.

Expected Fix

const n8nApi = axios.create({
  baseURL: `${N8N_HOST}/api/v1`,
  headers: {
    'X-N8N-API-KEY': N8N_API_KEY,
    'Content-Type': 'application/json'
  }
});

Environment

  • n8n version: 2.3.5 (self-hosted, HTTPS reverse proxy)
  • Package version: latest via npx -y @makafeli/n8n-workflow-builder
  • Used as MCP server in Claude Desktop

Steps to Reproduce

  1. Configure N8N_HOST=https://your-n8n-instance.com and a valid N8N_API_KEY
  2. Call any tool (e.g. list_workflows)
  3. Response is the n8n frontend HTML (<!DOCTYPE html>...) instead of JSON

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions