PostgreSQL Example (MCP Server)
The PostgreSQL example demonstrates how to use the Model Context Protocol (MCP) to connect ChatFrame to a live database, allowing the Large Language Model (LLM) to query data in natural language.
Overview
A dedicated MCP server is required to bridge the gap between ChatFrame and your PostgreSQL database. This server is responsible for:
- Exposing Tools: Defining functions (tools) like
query_databaseorget_user_datato the LLM. - Executing Commands: Translating the LLM's request into a valid SQL query and executing it against the PostgreSQL instance.
- Returning Results: Sending the query results back to the LLM as context for its final response.
Requirements
- PostgreSQL Instance: A running PostgreSQL database.
- MCP Server: An MCP server implementation designed for PostgreSQL (e.g., a Node.js-based server).
- Runtime: You must have the necessary runtime installed (e.g., Node.js) to run the PostgreSQL MCP server [1].
Workflow in ChatFrame
- Server Running: Ensure the PostgreSQL MCP server is running locally or accessible on your network.
- Server Configuration: Configure the server's connection details in ChatFrame's MCP settings.
- Natural Language Query: In the Chat interface, ask the LLM a question about your data, such as, "What are the top 5 most active users in the last month?"
- LLM Action: The LLM recognizes that it needs to use the
query_databasetool exposed by the MCP server. - Result and Response: The server executes the SQL, returns the data, and the LLM uses that data to provide an accurate, natural language answer.
This example highlights the power of MCP in giving the LLM real, up-to-date context from your private systems.
- Model Context Protocol. Example Servers. https://modelcontextprotocol.io/examples