Logo

dev-resources.site

for different kinds of informations.

Integrating Locally running Postgres with Claude Desktop

Published at
1/2/2025
Categories
mcp
ai
claude
postgres
Author
ajeetraina
Categories
4 categories in total
mcp
open
ai
open
claude
open
postgres
open
Author
10 person written this
ajeetraina
open
Integrating Locally running Postgres with Claude Desktop

Just as USB-C provides a standardized way to connect your devices to various peripherals and accessories, MCP provides a standardized way to connect AI models to different data sources and tools.

MCP is an open protocol that standardizes how applications provide context to LLMs. MCP helps you build agents and complex workflows on top of LLMs. LLMs frequently need to integrate with data and tools, and MCP provides:

Image33

  • A growing list of pre-built integrations that your LLM can directly plug into
  • The flexibility to switch between LLM providers and vendors
  • Best practices for securing your data within your infrastructure

This guide walks you through setting up PostgreSQL locally on a MacBook, configuring a database, and integrating it with Claude Desktop for efficient data querying and management. Follow along to get started!

Refer this GitHub Repository for MCP Postgres

Getting Started

Prereq

  • MacBook
  • Install Claude Desktop
  • Install Postgres

Setting up Postgres locally

Install Postgres locally

To install PostgreSQL on your MacBook, use the following Homebrew command:

brew install postgresql
Enter fullscreen mode Exit fullscreen mode

Start Postgres Service

After installation, start the PostgreSQL service:

brew services start postgresql
Enter fullscreen mode Exit fullscreen mode

Result:

 brew services start postgresql
==> Successfully started `postgresql@14` (lab
Enter fullscreen mode Exit fullscreen mode

Create database

Create a sample database using the command:

createdb sampledb
Enter fullscreen mode Exit fullscreen mode

Connect to the database

Run this command to connect to the database you just created.

psql sampledb
psql (15.10 (Homebrew), server 14.15 (Homebrew))
Type "help" for help.

sampledb=#
Enter fullscreen mode Exit fullscreen mode

Create Table

Once connected, create a table in your database:

sampledb=# CREATE TABLE users (
    user_id SERIAL PRIMARY KEY,
    username VARCHAR(50) NOT NULL,
    email VARCHAR(100) UNIQUE NOT NULL,
    password_hash TEXT NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Enter fullscreen mode Exit fullscreen mode

Installing Claude Desktop

Claude Desktop is a desktop application developed by Anthropic that brings the capabilities of their AI chatbot, Claude, directly to your computer. Available for both macOS and Windows, the app offers a seamless integration of Claude's features into your daily workflow, enhancing productivity and accessibility.
CLAUDE

Key Features:

  • Instant Access: Launch Claude directly from your desktop without the need to navigate to a web browser, streamlining your workflow.

  • Enhanced Performance: Designed for deep work, the desktop app provides a faster and more focused experience compared to the web interface.

  • Voice Interaction: Anthropic has introduced dictation support in its mobile apps, allowing users to interact with Claude using voice commands. This feature enhances accessibility and user experience.

  • Cross-Platform Availability: Claude Desktop is available for both macOS and Windows, ensuring compatibility with a wide range of systems.

Download and install Claude Desktop using this link

Image1

Configure Claude Desktop Configuration

Once installed, follow these steps to configure Claude Desktop for PostgreSQL.

  • Open Applications > Claude Desktop.
  • Click on "Edit" Config.
  • Add the following entry for PostgreSQL in the configuration:

Image5

Once downloaded, open Applications > Claude Desktop

Click "Edit Config" and add the following entry for Postgres

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "postgresql://localhost/sampledb"
      ]
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Restart the Claude Desktop and click on Hammer sign shown under the UI.

Image9

Image1

Querying the Database

With the setup complete, you can now start querying your PostgreSQL database directly through Claude Desktop. Use the interface to execute SQL commands and manage your data effectively.

With these steps, your PostgreSQL database and Claude Desktop are ready to handle your projects seamlessly. Happy coding!

claude Article's
29 articles in total
Favicon
Integrating Locally running Postgres with Claude Desktop
Favicon
Write tools for LLMs with go - mcp-golang
Favicon
MCP using node on asdf
Favicon
Modify the local bolt.new interface to allow input of the API key
Favicon
Enabling Application Downloads in Local bolt.new
Favicon
Running bolt.new Locally
Favicon
In the Beginning...
Favicon
Dario Amodei: Anthropic CEO on Claude, AGI & the Future of AI & Humanity | Podcast Summary
Favicon
Certainly! Absolutely! I apologize!
Favicon
Claude prompting guide - General tips for effective prompting
Favicon
How I used ChatGPT o1 and Claude for generating a SQL RBAC report and was surprised by the results
Favicon
How to use AI for coding the right way
Favicon
Using Cursor + Claude to Make Full-Stack SaaS Apps
Favicon
Exploring Anthropic Claude: A Safe and Ethical AI Assistant
Favicon
Claude 3.5 API Introductory Tutorial
Favicon
Unlocking Rapid Data Extraction: Groq + OCR and Claude Vision
Favicon
Free AI Chat and AI Art
Favicon
Optimising Function Calling (GPT4 vs Opus vs Haiku vs Sonnet)
Favicon
DEMO - Voice to PDF - Complete PDF documents with voice commands using the Claude 3 Opus API
Favicon
Claude LLM - Pros and Cons Compared with Other LLMs
Favicon
Is Claude Self Aware
Favicon
Guide to Effective Prompt Engineering for ChatGPT and LLM Responses
Favicon
AI powered video summarizer with Amazon Bedrock and Anthropic’s Claude
Favicon
Claude 2.1 Unleashed: The AI Revolution That's Outshining GPT-4
Favicon
AWS Bedrock Claude 2.1 - Return only JSON
Favicon
Claude: 10 Minute Docs Audit
Favicon
New Discoveries in No-Code AI App Building with ChatGPT
Favicon
Meet Claude - The AI Assistant That Understands The World Like You Do
Favicon
La IA de Anthropic, Claude, Supera a ChatGPT

Featured ones: