AI-Driven PostgreSQL Diagnostics in Teams

An n8n diagnostics agent that reasons first, runs live PostgreSQL checks when needed, and talks to operators inside Microsoft Teams.

By Ramakrishnan Ayyappan · · PostgreSQL · AI · n8n · MCP · Microsoft Teams · Automation

View on LinkedIn →

The problem

Monitoring tells you something is wrong. Operators still open sessions, locks, and query lists by hand. The context lives in dashboards, not in the chat where the team already works.

Approach

A PostgreSQL diagnostics agent sits behind Microsoft Teams (via a Copilot agent) and n8n. It is not a generic chatbot. It investigates instance health through MCP tools and explicit agent loops:

  • Think loop — reason first, decide whether live data is required
  • SQL loop — call MCP execute-query for one probe or several in parallel
  • Error loop — retry and correct failed diagnostic SQL
  • Feedback loop — keep session context for follow-up questions

Model calls go through an AI proxy so the workflow stays separate from any one vendor.

Architecture

n8n owns orchestration. MCP tools run the read-only SQL. The planner may return no SQL, one query, or several probes in parallel. Results go back to a synthesizer turn, then to the operator in Teams.

The built-in n8n AI Agent node was skipped because this design needed a custom proxy, explicit retries, and Teams Copilot integration.

Lessons

  • Put diagnostics where the team already talks
  • Keep the first version read-only
  • Schema and process context beat a raw slow-query string
  • Host metrics (CPU, memory, I/O) are the next signal to add

The LinkedIn post has the original write-up and discussion.