N8n SQL Server Agent
An n8n sql server agent lets a chat model run database queries from plain text prompts. You build it by linking an AI Agent node to a database tool sub-node. This setup helps your team automate data tasks and answer questions fast. Still, you must set up strict rules so the model does not read or change private records. How an n8n sql server agent works in practice The n8n AI Agent node pairs a chat model with one or more tools. The agent decides which tool to call to finish a task. You must
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
An n8n sql server agent lets a chat model run database queries from plain text prompts. You build it by linking an AI Agent node to a database tool sub-node. This setup helps your team automate data tasks and answer questions fast. Still, you must set up strict rules so the model does not read or change private records.
How an n8n sql server agent works in practice
The n8n AI Agent node pairs a chat model with one or more tools. The agent decides which tool to call to finish a task. You must attach at least one tool sub-node to the main agent node. In older versions, n8n offered a separate SQL Agent setting. That legacy agent only worked with MySQL, SQLite, and Postgres data sources. From version 1.82.0 on, that old agent type setting is deprecated. Version 3.0 removes the old node version completely.
Today, every AI Agent node works as a Tools Agent. To query SQL Server, you attach a workflow tool, custom code tool, or MCP server tool. The chat model reads the user prompt and picks the right tool. Next, the tool sends the query to the database and returns the rows. Engineers also run direct queries alongside these automated agent flows. Both humans and bots end up sharing the same network paths to the database.
Database roles and authentication options for SQL Server
Before the agent runs a query, it must log in to SQL Server. A database user is the identity of a login when it connects to a database. If an account needs many databases on one server, teams use a SQL login in master. If an account needs just one or a few databases, a contained database user works well. A contained user has a password and does not tie to a login in master. An admin must first turn on contained databases on the server and the database. SQL Server supports thirteen types of database users in total.
After you create the user, you assign a fixed database role. Every database role, including the public role, has basic permission to connect. The db_datareader role lets a user read all data from all user tables and views. The db_datawriter role lets a user add, delete, or change data in all user tables. To block access, db_denydatareader stops a user from reading any user tables, views, or metadata. Similarly, db_denydatawriter stops a user from adding, changing, or deleting any table data. The db_owner role can run all maintenance tasks and can even drop the database. You cannot change the permissions built into these fixed roles.
Open Policy Agent (OPA) + Kubernetes API Server Access: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Security tradeoffs during active query sessions
Static database roles help, but they leave big security gaps during an active session. A role like db_datareader grants read rights across every user table and view at once. If an agent uses that role, it can read all column in every table by default. A prompt mistake could pull emails, phone numbers, card numbers, or national IDs into the chat.
Shared credentials create another big risk for your team. N8n stores one static login and uses it for every workflow run. When the database logs a query, you only see the shared bot account name. You cannot tell which person or workflow triggered the query. Also, if someone gives the bot write rights for one task, every prompt gets write power. To fix this, teams inspect queries in flight and apply data masking to rewrite matched fields in results.
Check SQL Server batches and results on the wire
SQL Server logins and roles decide who connects. They do not check what each TDS batch does or mask sensitive values in returned rows. With hoop.dev, you run an open-source proxy, a sidecar for your SQL Server, inline in the TDS wire protocol. On every batch an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.
Before a batch hits the server, hoop.dev guardrails refuse disallowed actions with a native TDS error or hold risky statements for approval. On the way back, hoop.dev data masking rewrites sensitive values in supported result columns in memory, and every decision is logged. Explore the MIT-licensed project on GitHub.
Frequently asked questions
Does the legacy n8n SQL Agent support SQL Server directly?
No, the deprecated SQL Agent only supported MySQL, SQLite, and Postgres data sources. You should now use the standard AI Agent node working as a Tools Agent. You can link it to a Call n8n Workflow Tool or an MCP server tool.
How do I limit an n8n agent to read-only queries in SQL Server?
Assign the agent's database user to the db_datareader role and add the db_denydatawriter role. This lets the user read user tables and views while blocking data changes. Keep in mind that db_datareader still allows reading all user tables in that database.
Should an n8n agent use a standard login or a contained user?
Use a contained database user if the agent only needs one database. It keeps the user and password inside that single database without a login in master. Use a standard SQL login if the agent must query many databases on the instance.
Related guides
In this post