Discuter avec les données (serveur MCP + LLM) #61
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Voir https://github.com/punkpeye/awesome-mcp-servers
Turn Natural Language into SQL Queries! PostgreSQL MCP Server + AI Chatbot Tutorial
https://www.youtube.com/watch?v=Xj29pDlF4QI
Question to Gemini: I have a dataset stored in Parquet (but could be PosgreSQL) about public procurement contracts and I currently let my users explore this data through a Plotly Dash Web application.
The data is produced thanks to a data pipeline made of Prefect and Polars.
The data is not big (the parquet file weighs 300 MB).
What would be a straighforward approach to enable my users to ask questions to the data in natural language? For instance: "what are the to 10 suppliers of city XYZ in value?" (and more complex questions of that style).
Would using an MCP server help (in a Posgre scenario)? I heard of FastMCP.
Yes, a FastMCP server can definitely help in a PostgreSQL scenario, especially if you plan to integrate with advanced AI agents or LLM platforms that support the Model Context Protocol (MCP).
While the previous approach of using an LLM to generate a basic SQL query is effective, an MCP server provides a more structured, secure, and standardized bridge between your LLM and your PostgreSQL database.
💡 What a FastMCP Server Does for Natural Language Querying
FastMCP is a Python framework that simplifies building an MCP server. The Model Context Protocol (MCP) is a standardized way for an LLM to interact with external systems, like your database, using defined "Tools" and "Resources."
1. Structured Interaction (Tools & Resources)
Instead of giving the LLM the entire schema and asking it to write an arbitrary SQL query, you expose specific, safe actions via the MCP server:
execute_read_only_query(sql_query: str)tool.2. Enhanced Safety and Control
A dedicated PostgreSQL MCP server (like the ones built with FastMCP) offers critical security advantages:
execute_querytool to only acceptSELECTstatements, preventing accidental or malicious data modification (UPDATE,DELETE,DROP TABLE).3. Seamless LLM Integration
MCP is designed specifically for LLM communication. Once your server is running, any LLM client that supports the MCP standard (e.g., certain AI assistants, IDEs, or custom agents) can automatically discover the database schema and the available query tools.
4. Workflow in a PostgreSQL/FastMCP Scenario
SELECT supplier_name, SUM(contract_value) AS total_value FROM contracts WHERE city_name = %s GROUP BY 1 ORDER BY 2 DESC LIMIT 10;).✅ Recommendation
If you decide to migrate from Parquet/Polars to PostgreSQL for your data store, then using a FastMCP server is a highly recommended way to implement NLQ.
It provides a more robust, secure, and enterprise-friendly version of the basic Text-to-SQL approach, especially because you are already familiar with Prefect (a company that has supported the FastMCP/MCP ecosystem).
The video below offers a tutorial on using a PostgreSQL MCP server to turn natural language into SQL queries for a chatbot. [Turn Natural Language into SQL Queries! PostgreSQL MCP Server + AI Chatbot Tutorial](https://www.youtube.com/watch?v=Xj29pDlF4QI)
MCP in ChatGPT : https://platform.openai.com/docs/mcp
Frontier tech club case study (thanks @jpmckinney):
https://docs.supavec.com
Voir https://vanna.ai
Ajouter un llms.txt à la racine qui explique comment utiliser l'API.
Finalement je me suis branché sur la solution de dash #111.