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:
- email_classifier — determines if the email is a Haystack-related question
- kb_search — searches the Haystack documentation for a relevant answer
- 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.
docker run -it -p 5678:5678 -v ~/.n8n:/home/node/.n8n n8nio/n8nOpen n8n at http://localhost:5678 and create an account when prompted.
Open a second terminal:
HAYHOOKS_PIPELINES_DIR=./pipelines OPENAI_API_KEY=sk-... hayhooks mcp run 2>&1 | tee /tmp/hayhooks_mcp.logThe
2>&1 | tee /tmp/hayhooks_mcp.logkeeps 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/sseIt 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.pyThis calls all three pipelines via MCP and prints the drafted reply.
In n8n: Workflows → Import from file
Select: n8n/gmail_to_hayhooks_mcp.workflow.json
- Go to console.cloud.google.com and select (or create) a project
- APIs & Services → Library → search for and enable the Gmail API
- APIs & Services → Credentials → + Create Credentials → OAuth client ID
- If prompted, configure the OAuth consent screen: External, add your email as a test user
- Application type: Web application
- Add this redirect URI:
http://localhost:5678/rest/oauth2-credential/callback - Save — copy the Client ID and Client Secret
- In n8n, open the Gmail Trigger node → Credentials → Add credential → Gmail OAuth2 API
- Paste the Client ID and Client Secret
- Click Sign in with Google and complete the OAuth flow
- Do the same for the Send Reply node — you can reuse the credential you just created
Add your OpenAI credential.
Verify:
- Endpoint:
http://host.docker.internal:1417/mcp/ - Server Transport: HTTP Streamable
-
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?
-
In n8n, click Execute workflow
-
You should receive an email back with the answer
