> ## Documentation Index
> Fetch the complete documentation index at: https://docs.quantspace.limex.pro/llms.txt
> Use this file to discover all available pages before exploring further.

# n8n Workflows

> Build webhook and scheduled n8n workflows around hosted QuantX MCP servers

## Overview

n8n can sit in front of a hosted MCP server as a lightweight workflow layer. A common pattern is:

1. Trigger the workflow from a Webhook, Manual Trigger, or Schedule Trigger.
2. Normalize the incoming JSON, form data, or uploaded CSV in Code nodes.
3. Call the MCP endpoint with an n8n MCP Client node or with HTTP Request nodes.
4. Resolve stored outputs with `result_get` when a tool returns a `result_id`.
5. Assemble a JSON, log, email, or chat response from sanitized result fields.

## Safe Workflow Exports

Workflow exports can include API keys, credential IDs, email addresses, chat recipients, webhook paths, and delivery-service settings. Do not publish raw n8n workflow JSON unless it has been reviewed and scrubbed.

When sharing a workflow:

* Keep secrets in n8n Credentials or environment variables.
* Replace webhook paths with examples such as `my-factor-report`.
* Remove credential `id` / `name` blocks from exported nodes.
* Remove delivery recipients and bot/channel identifiers.
* Keep only endpoint URLs, tool names, request shapes, and routing notes.

## Workflow Templates and Webhooks

The workflow JSON files below are sanitized templates: credential blocks, private recipients, private webhook identifiers, and literal secrets have been removed. Import them into your own n8n instance, then attach your own MCP Client credentials and delivery credentials.

| Server                                                                 | Workflow JSON                                                                                                              | Webhook                                                                   | Notes                                                                                                                                               |
| ---------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Fama-French Replicate](/quantx/servers/fama-french-replicate)         | [Factor Loading Report](/quantx/servers/deployed/workflows/fama-french-factor-loading-report.json)                         | `POST https://n8n.limex.pro/webhook/ff-factor-loading-report`             | CSV portfolio API for loadings and alpha. No Lime, email, or chat delivery is configured in the public webhook.                                     |
| [Fama-French Replicate](/quantx/servers/fama-french-replicate)         | [Extended Factor Loading Report](/quantx/servers/deployed/workflows/fama-french-factor-loading-report-extended.json)       | Not published                                                             | Import into your own n8n instance when you need manual runs, schedules, Lime portfolio lookup, or delivery nodes.                                   |
| [Statistical Factor Models](/quantx/servers/statistical-factor-models) | [Statistical Factor Models User Workflow](/quantx/servers/deployed/workflows/statistical-factor-models-user-workflow.json) | `POST https://n8n.limex.pro/webhook/stat-factor-model-fit`                | Accepts JSON or CSV panel input and routes to complete-panel, Stock-Watson, or Banbura-Modugno fit tools.                                           |
| [Jump Models](/quantx/servers/jump-models)                             | [Regime Model](/quantx/servers/deployed/workflows/jump-models-regime-model.json)                                           | `POST https://n8n.limex.pro/webhook/9f2988bf-7247-4c07-95c7-9e37188e93c9` | Returns a regime report through the webhook. The public template removes scheduled email delivery; add your own delivery nodes after import.        |
| [EP Ratio Screener](/quantx/servers/ep-ratio-screener)                 | [EP Ratio Screener](/quantx/servers/deployed/workflows/ep-ratio-screener.json)                                             | `POST https://n8n.limex.pro/webhook/a1b2c3d4-e5f6-7890-abcd-ef1234567890` | Returns a ranked ticker screen through the webhook. The public template removes scheduled email delivery; add your own delivery nodes after import. |

## MCP Client Node Pattern

Use this when your n8n installation has an MCP Client node that supports streamable HTTP.

| Field           | Value                     |
| --------------- | ------------------------- |
| Connection type | HTTP / Streamable HTTP    |
| Endpoint URL    | Server-specific MCP URL   |
| Operation       | Execute tool              |
| Tool name       | Server-specific tool name |
| Tool parameters | `{"request": {...}}`      |

For example, a Statistical Factor Models workflow can route validated input to `complete-panel-factor-extractor-fit`, `swfactor-extractor-fit`, or `bmfactor-extractor-fit` through separate MCP Client nodes.

## HTTP Request Node Pattern

Use this when you want explicit session control or need to call helper tools such as `result_get`.

### 1. Initialize

```json theme={null}
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "initialize",
  "params": {
    "protocolVersion": "2025-03-26",
    "capabilities": {},
    "clientInfo": {
      "name": "n8n",
      "version": "1.0"
    }
  }
}
```

Store the `mcp-session-id` response header.

### 2. Send Initialized

```json theme={null}
{
  "jsonrpc": "2.0",
  "method": "notifications/initialized",
  "params": {}
}
```

Send it with the stored `MCP-Session-Id` header.

### 3. Call a Tool

```json theme={null}
{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "tools/call",
  "params": {
    "name": "result_get",
    "arguments": {
      "request": {
        "result_id": "<result-id>"
      }
    }
  }
}
```

Keep `Content-Type: application/json` and `Accept: application/json, text/event-stream` on every HTTP Request node. If the endpoint is protected, add the `Authorization` header through n8n Credentials instead of hard-coding it.

## Webhook Pattern

For user-facing workflows, configure a Webhook Trigger with `POST` and `responseMode: responseNode`.

Typical body shapes:

```json theme={null}
{
  "tickers": ["MSFT", "AAPL"],
  "runMode": "once",
  "delivery": "webhook"
}
```

```json theme={null}
{
  "algorithm": "stock-watson",
  "panelCsv": "series,date,value\nSPY,2024-01-01,0.01",
  "extractorInitKwargs": {
    "n_factors_max": 2,
    "flow_series": {},
    "flow_series_diff": {}
  }
}
```

The workflow should validate input early and route errors to a Respond to Webhook node with `{"ok": false, "error": "..."}`.

## Server Examples

| Server                                                                 | Trigger shape                                  | MCP calls                                                                                                                               |
| ---------------------------------------------------------------------- | ---------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| [Fama-French Replicate](/quantx/servers/fama-french-replicate)         | Manual, scheduled, or webhook portfolio report | `get-proxy-ff-factors`, `get-loadings-and-alpha`, `result_get`                                                                          |
| [Statistical Factor Models](/quantx/servers/statistical-factor-models) | Webhook or manual panel fit                    | `complete-panel-factor-extractor-*`, `swfactor-extractor-*`, `bmfactor-extractor-*`, `result_get`                                       |
| [Jump Models](/quantx/servers/jump-models)                             | Scheduled or webhook regime report             | Dataloader `fetch-ohlcvs`, `jump-model-create`, `jump-model-fit`, `jump-model-predict-proba-online`, `jump-model-predict`, `result_get` |
| [EP Ratio Screener](/quantx/servers/ep-ratio-screener)                 | Scheduled or webhook ticker screen             | `load_skills`, `screen-tickers`                                                                                                         |

## Delivery

Keep delivery separate from MCP calls. The MCP nodes should produce structured JSON; delivery nodes can then send:

* webhook JSON response;
* n8n execution logs;
* email report;
* chat or bot notification;
* saved CSV or image artifact.

Do not put delivery API keys or recipients into Code node constants. Use n8n Credentials, workflow variables, or environment variables.

## Checklist

* The MCP URL is the server-specific `/mcp/...` URL, not the `/health` URL.
* Every tool payload is wrapped as `{"request": {...}}`.
* Direct HTTP Request flows keep and reuse `MCP-Session-Id`.
* Stored outputs are resolved with `result_get` before formatting reports.
* Workflow exports are scrubbed before they are shared or committed.
