Skip to main content
Glama
mcp-thread-persistence-demo

mcp-thread-persistence-demo

by BenzyTAi

MCP Thread Persistence Demo

SQLite にチャットスレッドのメモを永続化する最小限の MCP (Model Context Protocol) サーバーで、実際の stdio トランスポート経由でそれを実行する本物のクライアントを備えています(基盤となる関数を直接呼び出すだけではありません)。

実際のフリーランス案件のパターンを反映した学習用の演習として構築されています。「チャットスレッドの状態をデータベースに永続化する MCP ツール呼び出しを修正・実装する。upsert セマンティクス(新規なら作成、既存なら更新、スレッドごとに重複行なし)を備える」

内容

  • server.py — 3つのツールを公開する MCP サーバー:

    • save_note(user_id, thread_id, content) — SQLite に upsert し、(user_id, thread_id) をキーとします。同じスレッドへの2回目の呼び出しは、重複を作成せず既存の行を更新します。

    • get_note(user_id, thread_id) — 保存されたメモを読み戻します。

    • list_threads(user_id) — ユーザーのすべてのスレッドを一覧表示します。

  • test_client.py — stdio 経由で server.py に接続し、list_tools を呼び出してから、3つのツールすべてを順番に実行する本物の MCP クライアントです(同じスレッドで save_note を2回呼び出して、upsert が重複行を作成しないことを検証する処理を含みます)。

Related MCP server: teamshare-server

実行方法

python3.12 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

python test_client.py

注記

意図的に mcp<2 に固定しています。mcp SDK の 2.x リリースでは FastMCP が MCPServer に改名され、他の API も変更されました。世の中の既存のチュートリアルやコードベースのほとんどは今でも 1.x の FastMCP API を対象としているため、これもそれを対象としています。

Maintenance

ActivityStale
ResponsivenessNo recent community issues

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    B
    maintenance
    Enables coding agents on a team to publish short context notes that are automatically surfaced at the start of every teammate's next session, with read receipts and SQLite-backed persistent storage over MCP.
    -
  • A
    license
    A
    quality
    B
    maintenance
    Enables MCP-compatible agents to remember, recall, link, and forget durable notes across devices, with local SQLite storage and optional libSQL/Turso sync.
    4
    1
    MIT