This repository implements a server for the Model Context Protocol (MCP), which facilitates communication between models and clients while tracking and managing context efficiently. The server is designed to work with PostgreSQL for storing model states and context data.
To install the MCP server, you'll need to follow these steps:
git clone https://github.com/stuzero/pg-mcp-server.git
cd pg-mcp-server
npm install
.env
file in the root directory with the following variables:DATABASE_URL=postgresql://username:password@localhost:5432/mcp_database
PORT=3000
npm run db:init
To start the MCP server in development mode:
npm run dev
For production deployment:
npm run build
npm start
Clients can connect to the MCP server using a compatible client library. The official client can be found at https://github.com/stuzero/pg-mcp-client.
The server exposes several endpoints for client-model interaction:
POST /context/create
GET /context/:id
PUT /context/:id
DELETE /context/:id
POST /model/query
POST /model/stream
You can customize the server behavior by modifying the following environment variables:
PORT
: The port on which the server listens (default: 3000)DATABASE_URL
: PostgreSQL connection stringLOG_LEVEL
: Logging verbosity (debug, info, warn, error)MAX_CONTEXT_SIZE
: Maximum size of stored context in tokensMODEL_TIMEOUT
: Timeout for model requests in millisecondsHere's a basic example of using the MCP server with curl:
# Create a new context
curl -X POST http://localhost:3000/context/create \
-H "Content-Type: application/json" \
-d '{"modelId": "gpt-4", "systemPrompt": "You are a helpful assistant."}'
# Query the model with context
curl -X POST http://localhost:3000/model/query \
-H "Content-Type: application/json" \
-d '{
"contextId": "your-context-id",
"message": "What is the capital of France?",
"options": {"temperature": 0.7}
}'
.env
file and database accessPORT
in your .env
file if the default port is already occupiedIf you encounter issues, check the server logs for more detailed information about the error.
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "pg-mcp-server" '{"command":"npx","args":["pg-mcp-server"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"pg-mcp-server": {
"command": "npx",
"args": [
"pg-mcp-server"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"pg-mcp-server": {
"command": "npx",
"args": [
"pg-mcp-server"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect