test-lnar-hosting-python-postgres

test-lnar-hosting-python-postgres

Enables CRUD operations on notes stored in PostgreSQL, with tools to list, create, update, delete notes and tags. The server provides both REST API and MCP endpoints via a single FastAPI process.

Category
Visit Server

README

test-lnar-hosting-python-postgres

Notes の CRUD を提供する FastAPI サーバーと、それを MCP ツールとして公開する MCP サーバーのサンプルです。

test-lnar-hosting-python の PostgreSQL 版です。元のサンプルがデータをプロセス内メモリ(dict)に 持っていたのに対し、本リポジトリは PostgreSQL にデータを永続化 します。プロセスを再起動・ 再デプロイしてもノートは消えません。

FastAPI の /mcp に MCP Streamable HTTP エンドポイントをマウントしているため、1プロセス・1ポートで REST API と MCP の両方を提供します

データストア

  • ノートは PostgreSQL の notes テーブルに保存されます(起動時に自動作成)。
  • 接続先は環境変数 DATABASE_URL から読み込みます(例: postgresql://user:pass@host:5432/dbname)。
    • lnar 上では、設置したマネージドDB(または接続した外部DB)の接続文字列が DATABASE_URL として自動注入されます。
    • ローカル開発では未設定時に postgresql://postgres:postgres@localhost:5432/postgres を使います。
CREATE TABLE notes (
    id      UUID PRIMARY KEY,
    title   TEXT NOT NULL,
    content TEXT NOT NULL,
    tags    TEXT[] NOT NULL DEFAULT '{}'
);

起動方法

1. 依存関係のインストール

uv sync

2. PostgreSQL を用意(ローカル例)

docker run --rm -e POSTGRES_PASSWORD=postgres -p 5432:5432 postgres:16

3. サーバーを起動

# 既定以外の DB に繋ぐ場合は DATABASE_URL を設定
export DATABASE_URL="postgresql://postgres:postgres@localhost:5432/postgres"
uvicorn api:app --reload
  • REST API ドキュメント: http://localhost:8000/docs
  • MCP エンドポイント: http://localhost:8000/mcp

エンドポイント一覧

Method Path 説明
GET /health ヘルスチェック
GET /version API のバージョン情報を取得
GET /notes ノートの一覧を取得
GET /notes/count ノートの件数を取得
GET /notes/tags タグ一覧を取得
POST /notes ノートを作成
DELETE /notes すべてのノートを削除(0件のときは 204)
GET /notes/{note_id} ノートを ID で取得
PUT /notes/{note_id} ノートを更新
DELETE /notes/{note_id} ノートを削除
GET /stream ログストリーミング検証用

MCP ツール一覧

ツール名 説明
list_notes すべてのノートの一覧を取得
count_notes ノートの件数を取得
list_tags タグ一覧を取得
get_note ID を指定してノートを取得
create_note 新しいノートを作成
update_note ノートのタイトル/本文/タグを更新
delete_note ノートを ID で削除
delete_all_notes すべてのノートを一括削除

curl での動作確認

# ノート作成
curl -s -X POST http://localhost:8000/notes \
  -H 'Content-Type: application/json' \
  -d '{"title": "memo", "content": "hello", "tags": ["a"]}'

# 一覧取得
curl -s http://localhost:8000/notes

# 件数取得
curl -s http://localhost:8000/notes/count

# 永続化の確認: サーバーを再起動してもノートが残る

MCP クライアントからの接続

supergateway 経由で Streamable HTTP に接続する場合(lnar ダッシュボードで表示される設定):

{
  "mcpServers": {
    "test-lnar-hosting-python-postgres": {
      "command": "npx",
      "args": ["-y", "supergateway", "--streamableHttp", "http://localhost:8000/mcp"]
    }
  }
}

stdio transport(Claude Desktop / MCP Inspector 直接接続)を使う場合:

python mcp_server.py

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured