Skip to content

About

Trigger Hayhooks pipelines from Gmail via n8n

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hayhooks-gmail-trigger

A demo showing how to trigger Hayhooks pipelines from Gmail using n8n as the automation layer.


When a new email arrives, an n8n AI Agent calls three Hayhooks pipelines exposed as MCP tools:

  1. email_classifier — determines if the email is a Haystack-related question
  2. kb_search — searches the Haystack documentation for a relevant answer
  3. reply_drafter — drafts a grounded HTML reply, with source links

The reply is sent back to the original sender automatically. Non-Haystack emails get a short generic response.


Setup

1. Start n8n in Docker

docker run -it -p 5678:5678 -v ~/.n8n:/home/node/.n8n n8nio/n8n

Open n8n at http://localhost:5678 and create an account when prompted.


2. Start the Hayhooks MCP server

Open a second terminal:

HAYHOOKS_PIPELINES_DIR=./pipelines OPENAI_API_KEY=sk-... hayhooks mcp run 2>&1 | tee /tmp/hayhooks_mcp.log

The 2>&1 | tee /tmp/hayhooks_mcp.log keeps a log in a file as well as stdout — helpful for debugging.

Confirm the MCP server is working properly with:

curl -N http://localhost:1417/sse

It should hang open (SSE keeps the connection alive) — that means it's ready. Ctrl+C to exit.

To verify the full pipeline chain end-to-end before touching n8n:

.venv/bin/python test_chain_mcp.py

This calls all three pipelines via MCP and prints the drafted reply.


3. Import the workflow and configure it

In n8n: Workflows → Import from file

Select: n8n/gmail_to_hayhooks_mcp.workflow.json


4. Connect your Gmail account

4a. Create OAuth2 credentials in Google Cloud Console

  1. Go to console.cloud.google.com and select (or create) a project
  2. APIs & Services → Library → search for and enable the Gmail API
  3. APIs & Services → Credentials → + Create Credentials → OAuth client ID
  4. If prompted, configure the OAuth consent screen: External, add your email as a test user
  5. Application type: Web application
  6. Add this redirect URI:
    http://localhost:5678/rest/oauth2-credential/callback
    
  7. Save — copy the Client ID and Client Secret

5. Configure the workflow nodes

5a. Gmail credential

  1. In n8n, open the Gmail Trigger node → Credentials → Add credential → Gmail OAuth2 API
  2. Paste the Client ID and Client Secret
  3. Click Sign in with Google and complete the OAuth flow
  4. Do the same for the Send Reply node — you can reuse the credential you just created

5b. OpenAI Chat Model node

Add your OpenAI credential.

5c. MCP Client node

Verify:

  • Endpoint: http://host.docker.internal:1417/mcp/
  • Server Transport: HTTP Streamable

6. Test

  1. Send an email to the Gmail account you configured, for example:

    Subject: Haystack question

    Body: I want to use the LLM from Mistral within Haystack. How can I use it? Do you have a code example?

  2. In n8n, click Execute workflow

  3. You should receive an email back with the answer

About

Trigger Hayhooks pipelines from Gmail via n8n

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages