Content
# MY-MCPSV-POSTGRES
## Description
Sample source for MCP Server that accesses PostgreSQL using FastAPI and FastMCP.
Provides sample source for developers new to MCP Server.
## Usage
### Prepare Tables and Data
* Create `inventory` table in PostgreSQL using `create_inventory.sql`
* Load `sample_data.csv`
### Prepare API
* Install uv
```
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
```
* Create project folder and create python virtual environment
```
cd MY-MCPSV-POSTGRES
uv init API-SERVER
```
* Install packages
```
cd API-SERVER
uv add fastapi uvicorn
uv add "psycopg[binary]"
```
* Place `main.py` in `API-SERVER` folder and update connection string according to your environment. The connection string is set in the `DB_PATH` variable in `main.py`.
* Start FastAPI
```
uv run uvicorn main:app --reload
```
### Prepare MCP Server
* Create project folder and create python virtual environment
```
cd MY-MCPSV-POSTGRES
uv init MCP-SERVER
```
* Install packages
```
uv add "mcp[cli]"
uv add httpx
```
* Place `server.py` in `MCP-SERVER` folder
* Start MCP Server
```
uv run mcp dev server.py
```
### Configure MCP Server on MCP Client
* Add to `mcp.json`. For Claude Desktop, use `claude_desktop_config.json`
```
"mcpServers": {
"INVENTORY": {
"command": "uv",
"args": [
"run",
"--directory",
"C:\\MY-MCPSV-POSTGRES\\MCP-SERVER",
"python",
"server.py"
]
}
},
```
### Usage from MCP Client
```
Check the inventory of fruits in the inventory management system,
and search for products with an inventory of 10 or less.
```