AI SQL Agent for Workflow Credential Dependency Mapping - n8n Workflow

Query your n8n workflows using an AI SQL agent. Discover which n8n node dependencies (credentials) are used across all your n8n templates quickly and efficiently for better auditing.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

n8n administrators managing large instances with many n8n templates.
Developers needing to audit credential usage across various n8n workflow definitions.
Users looking for advanced examples of combining AI agents with internal n8n API data fetching.
Anyone interested in creating a conversational interface for operational insights within their n8n environment.

Overview

As your n8n instance scales, managing credential dependencies across numerous n8n workflows can become complex. This automation solves that problem by transforming your n8n instance metadata into a queryable knowledge base accessible via a conversational AI SQL agent. The process first uses an internal n8n node to fetch metadata for all available n8n templates, extracts credential linkages, and stores them in a temporary SQLite database. Subsequently, an AI Agent is given a specialized tool to execute SQL queries against this database, allowing users to ask natural language questions like, "Which n8n workflow uses both Slack and Google Sheets credentials?" This solution significantly improves operational visibility and audit capabilities within your n8n environment, making credential management easier than ever.

How it Works

The n8n workflow operates in two distinct phases: Initialization and Querying.


  1. Initialization (Manual n8n Trigger): The process is started manually using the initial n8n trigger ("When clicking 'Test workflow'"). This initiates the indexing of all current n8n templates.

  2. Fetch n8n Metadata: An n8n node queries the internal n8n API (requires an n8n API key) to retrieve the JSON definition for every active n8n workflow.

  3. Data Mapping: The Map Workflows & Credentials n8n node transforms the retrieved API data. It specifically iterates through every n8n node definition in the workflow to identify and flatten associated credential names and types, structuring them for efficient storage and later querying.

  4. Database Population: A Python Code n8n node creates a temporary SQLite database (n8nworkflowcredentials.db) and inserts records containing the workflowid, workflowname, and a JSON string of the credentials used by that n8n workflow.

  5. Agent Activation (Chat Trigger): The second part of the n8n workflow is initiated via a dedicated Chat Trigger webhook, serving as the user interface.

  6. AI Querying: The Workflow Credentials Helper Agent uses the OpenAI Chat Model and Window Buffer Memory to process user input. When a user asks about which n8n templates use certain services, the agent utilizes its tool.

  7. Tool Execution: The agent calls the Query Workflow Credentials Database tool, which executes a SQL SELECT query against the local database to find matching n8n workflow credential dependencies.

Installation Guide


  1. Import the n8n Workflow: Copy the provided JSON code and paste it into your n8n instance using the 'Import from JSON' feature.

  2. API Key Setup (Internal n8n Node): You must set up an n8n API credential and connect it to the 'n8n' node. This API key must have the necessary scope to read workflow definitions. This is crucial for the n8n node to function.

  3. OpenAI Credential: Connect an OpenAI API credential to the 'OpenAI Chat Model' n8n node. This powers the underlying AI model for the agent.

  4. Run Step 1 (Indexing): Click the 'Test workflow' button on the starting n8n trigger to execute the first chain. This populates the temporary database with metadata from your existing n8n templates. You must re-run this when your n8n workflow definitions change.

  5. Run Step 2 (Querying): Activate the Chat Trigger. You can now use the resulting webhook URL to start interacting with your AI SQL agent and query your n8n node usage.

Node Details

When clicking "Test workflow" (Manual Trigger): The initial n8n trigger used to manually start the data indexing process for all n8n workflow templates.
n8n (n8n node): Fetches comprehensive JSON definitions for all configured n8n workflows from the internal n8n API, authenticated via an API key.
Map Workflows & Credentials (Set node): A vital data transformation n8n node. It flattens and maps the complex nested credential structure found within each n8n node into a simple array, making it indexable.
Save to Database (Code node - Python): This custom code n8n node creates and populates the n8nworkflowcredentials.db SQLite database, establishing the index for all n8n templates.
Chat Trigger (Langchain Node): Serves as the interactive HTTP endpoint, acting as the primary n8n trigger for conversational queries.
Workflow Credentials Helper Agent (Langchain Agent node): The core intelligence, responsible for receiving user requests, deciding when to use the SQL tool, and formulating human-readable responses based on the database output.


  • Query Workflow Credentials Database (Tool Code node - Python): The specific n8n tool available to the AI agent. It is configured to execute SQL SELECT queries against the indexed credential database, allowing the agent to determine which n8n node credentials are in use.

Related n8n Workflows

Free

Nodes: 10 Nodes
Updated: December 26 2025
View all
Created by
Jimleuk
Jimleuk

Freelance consultant based in the UK specialising in AI-powered automations. I work with select clients tackling their most challenging projects. For business enquiries, send me an email at [email protected] LinkedIn: https://www.linkedin.com/in/jimleuk/ X/Twitter: https://x.com/jimle_uk

Featured*