plintho-mcp 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- plintho_mcp-0.1.0/PKG-INFO +119 -0
- plintho_mcp-0.1.0/README.md +103 -0
- plintho_mcp-0.1.0/plintho_mcp/__init__.py +3 -0
- plintho_mcp-0.1.0/plintho_mcp/__main__.py +3 -0
- plintho_mcp-0.1.0/plintho_mcp/api_client.py +32 -0
- plintho_mcp-0.1.0/plintho_mcp/auth.py +130 -0
- plintho_mcp-0.1.0/plintho_mcp/cli.py +87 -0
- plintho_mcp-0.1.0/plintho_mcp/config.py +16 -0
- plintho_mcp-0.1.0/plintho_mcp/server.py +122 -0
- plintho_mcp-0.1.0/plintho_mcp/tools.py +138 -0
- plintho_mcp-0.1.0/plintho_mcp.egg-info/PKG-INFO +119 -0
- plintho_mcp-0.1.0/plintho_mcp.egg-info/SOURCES.txt +16 -0
- plintho_mcp-0.1.0/plintho_mcp.egg-info/dependency_links.txt +1 -0
- plintho_mcp-0.1.0/plintho_mcp.egg-info/entry_points.txt +2 -0
- plintho_mcp-0.1.0/plintho_mcp.egg-info/requires.txt +2 -0
- plintho_mcp-0.1.0/plintho_mcp.egg-info/top_level.txt +1 -0
- plintho_mcp-0.1.0/pyproject.toml +31 -0
- plintho_mcp-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: plintho-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP server + CLI for the plintho voice journal
|
|
5
|
+
Author: vtech-ai
|
|
6
|
+
License: Proprietary
|
|
7
|
+
Project-URL: Homepage, https://plintho.app
|
|
8
|
+
Keywords: mcp,voice-journal,plintho
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Requires-Python: >=3.11
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
Requires-Dist: mcp>=1.0
|
|
15
|
+
Requires-Dist: httpx>=0.27
|
|
16
|
+
|
|
17
|
+
# plintho-mcp
|
|
18
|
+
|
|
19
|
+
A small CLI + [MCP](https://modelcontextprotocol.io) server that lets any
|
|
20
|
+
MCP-capable client (Claude Desktop, Cursor, Cline, Zed, …) query the
|
|
21
|
+
plintho voice-journal backend on behalf of a single user.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
Direct from GitHub (no PyPI release yet):
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pipx install 'git+https://github.com/vtech-ai/plintho-mcp.git'
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Or with pip:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install 'git+https://github.com/vtech-ai/plintho-mcp.git'
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Local checkout while developing:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
git clone https://github.com/vtech-ai/plintho-mcp.git
|
|
41
|
+
cd plintho-mcp
|
|
42
|
+
pipx install -e .
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Requires Python 3.11+. Runtime deps: `mcp`, `httpx`. The package does
|
|
46
|
+
**not** pull in any of the plintho backend's heavy dependencies.
|
|
47
|
+
|
|
48
|
+
## Pair this device with your account
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
$ plintho-mcp login --name "MacBook Cursor"
|
|
52
|
+
配对码: WXYZ-2345
|
|
53
|
+
请在 plintho iOS app → Settings → MCP Access 输入此码
|
|
54
|
+
等待中...
|
|
55
|
+
✓ 已登录为 user-abc
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The token is saved to `~/.plintho/mcp_token` (mode 600). The plaintext
|
|
59
|
+
exists only on this machine; the server stores only its sha256 hash.
|
|
60
|
+
|
|
61
|
+
## Wire into your MCP client
|
|
62
|
+
|
|
63
|
+
### Claude Desktop — `claude_desktop_config.json`
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"mcpServers": {
|
|
68
|
+
"plintho": { "command": "plintho-mcp" }
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Claude Code
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
claude mcp add plintho -- plintho-mcp
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Cursor — `~/.cursor/mcp.json`
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"mcpServers": {
|
|
84
|
+
"plintho": { "command": "plintho-mcp" }
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Same `command` key works for Cline / Zed / Continue / any stdio-MCP client.
|
|
90
|
+
|
|
91
|
+
## Tools exposed
|
|
92
|
+
|
|
93
|
+
| Tool | What it does |
|
|
94
|
+
| ---------------------- | ----------------------------------------------------------------------- |
|
|
95
|
+
| `list_events_by_date` | All events on a given date (YYYY-MM-DD or `today`/`yesterday`). |
|
|
96
|
+
| `get_event_detail` | One event's note (Markdown) + raw utterances. |
|
|
97
|
+
| `search_events` | Free-text search across event titles/summaries/notes, optional date. |
|
|
98
|
+
| `search_utterances` | Substring search across raw transcribed utterances. |
|
|
99
|
+
| `get_daily_summary` | Daily summary (日报) for a given date. |
|
|
100
|
+
|
|
101
|
+
All tools are scoped to the user the token was issued to — there is no
|
|
102
|
+
`user_id` parameter and the server enforces ownership on every call.
|
|
103
|
+
|
|
104
|
+
## Other commands
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
plintho-mcp whoami # show current user_id / token name
|
|
108
|
+
plintho-mcp logout # delete the local token file
|
|
109
|
+
plintho-mcp login --force # re-pair (replaces existing token locally)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
To revoke a token server-side, use the iOS app → Settings → MCP Access.
|
|
113
|
+
|
|
114
|
+
## Environment variables
|
|
115
|
+
|
|
116
|
+
| Var | Default | Purpose |
|
|
117
|
+
| ------------------ | ----------------------------- | -------------------------------- |
|
|
118
|
+
| `PLINTHO_API_BASE` | `https://api.plintho.app` | Backend URL. |
|
|
119
|
+
| `PLINTHO_HOME` | `~/.plintho` | Token + config directory. |
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# plintho-mcp
|
|
2
|
+
|
|
3
|
+
A small CLI + [MCP](https://modelcontextprotocol.io) server that lets any
|
|
4
|
+
MCP-capable client (Claude Desktop, Cursor, Cline, Zed, …) query the
|
|
5
|
+
plintho voice-journal backend on behalf of a single user.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Direct from GitHub (no PyPI release yet):
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pipx install 'git+https://github.com/vtech-ai/plintho-mcp.git'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Or with pip:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install 'git+https://github.com/vtech-ai/plintho-mcp.git'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Local checkout while developing:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
git clone https://github.com/vtech-ai/plintho-mcp.git
|
|
25
|
+
cd plintho-mcp
|
|
26
|
+
pipx install -e .
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Requires Python 3.11+. Runtime deps: `mcp`, `httpx`. The package does
|
|
30
|
+
**not** pull in any of the plintho backend's heavy dependencies.
|
|
31
|
+
|
|
32
|
+
## Pair this device with your account
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
$ plintho-mcp login --name "MacBook Cursor"
|
|
36
|
+
配对码: WXYZ-2345
|
|
37
|
+
请在 plintho iOS app → Settings → MCP Access 输入此码
|
|
38
|
+
等待中...
|
|
39
|
+
✓ 已登录为 user-abc
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The token is saved to `~/.plintho/mcp_token` (mode 600). The plaintext
|
|
43
|
+
exists only on this machine; the server stores only its sha256 hash.
|
|
44
|
+
|
|
45
|
+
## Wire into your MCP client
|
|
46
|
+
|
|
47
|
+
### Claude Desktop — `claude_desktop_config.json`
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{
|
|
51
|
+
"mcpServers": {
|
|
52
|
+
"plintho": { "command": "plintho-mcp" }
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Claude Code
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
claude mcp add plintho -- plintho-mcp
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Cursor — `~/.cursor/mcp.json`
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"mcpServers": {
|
|
68
|
+
"plintho": { "command": "plintho-mcp" }
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Same `command` key works for Cline / Zed / Continue / any stdio-MCP client.
|
|
74
|
+
|
|
75
|
+
## Tools exposed
|
|
76
|
+
|
|
77
|
+
| Tool | What it does |
|
|
78
|
+
| ---------------------- | ----------------------------------------------------------------------- |
|
|
79
|
+
| `list_events_by_date` | All events on a given date (YYYY-MM-DD or `today`/`yesterday`). |
|
|
80
|
+
| `get_event_detail` | One event's note (Markdown) + raw utterances. |
|
|
81
|
+
| `search_events` | Free-text search across event titles/summaries/notes, optional date. |
|
|
82
|
+
| `search_utterances` | Substring search across raw transcribed utterances. |
|
|
83
|
+
| `get_daily_summary` | Daily summary (日报) for a given date. |
|
|
84
|
+
|
|
85
|
+
All tools are scoped to the user the token was issued to — there is no
|
|
86
|
+
`user_id` parameter and the server enforces ownership on every call.
|
|
87
|
+
|
|
88
|
+
## Other commands
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
plintho-mcp whoami # show current user_id / token name
|
|
92
|
+
plintho-mcp logout # delete the local token file
|
|
93
|
+
plintho-mcp login --force # re-pair (replaces existing token locally)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
To revoke a token server-side, use the iOS app → Settings → MCP Access.
|
|
97
|
+
|
|
98
|
+
## Environment variables
|
|
99
|
+
|
|
100
|
+
| Var | Default | Purpose |
|
|
101
|
+
| ------------------ | ----------------------------- | -------------------------------- |
|
|
102
|
+
| `PLINTHO_API_BASE` | `https://api.plintho.app` | Backend URL. |
|
|
103
|
+
| `PLINTHO_HOME` | `~/.plintho` | Token + config directory. |
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Thin httpx wrapper that injects the stored MCP token."""
|
|
2
|
+
from typing import Any, Optional
|
|
3
|
+
|
|
4
|
+
import httpx
|
|
5
|
+
|
|
6
|
+
from plintho_mcp.auth import load_token
|
|
7
|
+
from plintho_mcp.config import API_BASE_URL, REQUEST_TIMEOUT_SECONDS
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class NotAuthenticated(Exception):
|
|
11
|
+
pass
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _headers() -> dict:
|
|
15
|
+
stored = load_token()
|
|
16
|
+
if not stored:
|
|
17
|
+
raise NotAuthenticated("Run `plintho-mcp login` first")
|
|
18
|
+
return {"Authorization": f"Bearer {stored.token}"}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def get(path: str, params: Optional[dict] = None) -> Any:
|
|
22
|
+
with httpx.Client(base_url=API_BASE_URL, timeout=REQUEST_TIMEOUT_SECONDS) as c:
|
|
23
|
+
r = c.get(path, params=params, headers=_headers())
|
|
24
|
+
r.raise_for_status()
|
|
25
|
+
return r.json()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def post(path: str, json_body: Optional[dict] = None) -> Any:
|
|
29
|
+
with httpx.Client(base_url=API_BASE_URL, timeout=REQUEST_TIMEOUT_SECONDS) as c:
|
|
30
|
+
r = c.post(path, json=json_body, headers=_headers())
|
|
31
|
+
r.raise_for_status()
|
|
32
|
+
return r.json()
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""Device-code pairing flow and local token storage for plintho-mcp.
|
|
2
|
+
|
|
3
|
+
The CLI never receives plaintext from anywhere except the device-code
|
|
4
|
+
poll response, and stores it under ~/.plintho/mcp_token with mode 600.
|
|
5
|
+
"""
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import sys
|
|
9
|
+
import time
|
|
10
|
+
from dataclasses import dataclass
|
|
11
|
+
from typing import Optional
|
|
12
|
+
|
|
13
|
+
import httpx
|
|
14
|
+
|
|
15
|
+
from plintho_mcp.config import (
|
|
16
|
+
API_BASE_URL,
|
|
17
|
+
CONFIG_DIR,
|
|
18
|
+
REQUEST_TIMEOUT_SECONDS,
|
|
19
|
+
TOKEN_PATH,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class AuthError(Exception):
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass
|
|
28
|
+
class StoredToken:
|
|
29
|
+
token: str
|
|
30
|
+
user_id: Optional[str] = None
|
|
31
|
+
name: Optional[str] = None
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def load_token() -> Optional[StoredToken]:
|
|
35
|
+
if not TOKEN_PATH.exists():
|
|
36
|
+
return None
|
|
37
|
+
try:
|
|
38
|
+
data = json.loads(TOKEN_PATH.read_text())
|
|
39
|
+
except (OSError, json.JSONDecodeError):
|
|
40
|
+
return None
|
|
41
|
+
tok = data.get("token")
|
|
42
|
+
if not tok:
|
|
43
|
+
return None
|
|
44
|
+
return StoredToken(token=tok, user_id=data.get("user_id"), name=data.get("name"))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def save_token(stored: StoredToken) -> None:
|
|
48
|
+
CONFIG_DIR.mkdir(parents=True, exist_ok=True)
|
|
49
|
+
TOKEN_PATH.write_text(json.dumps({
|
|
50
|
+
"token": stored.token,
|
|
51
|
+
"user_id": stored.user_id,
|
|
52
|
+
"name": stored.name,
|
|
53
|
+
}))
|
|
54
|
+
try:
|
|
55
|
+
os.chmod(TOKEN_PATH, 0o600)
|
|
56
|
+
except OSError:
|
|
57
|
+
pass
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def delete_token() -> None:
|
|
61
|
+
try:
|
|
62
|
+
TOKEN_PATH.unlink()
|
|
63
|
+
except FileNotFoundError:
|
|
64
|
+
pass
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _client() -> httpx.Client:
|
|
68
|
+
return httpx.Client(base_url=API_BASE_URL, timeout=REQUEST_TIMEOUT_SECONDS)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def start_device_flow(name: Optional[str]) -> dict:
|
|
72
|
+
with _client() as c:
|
|
73
|
+
r = c.post("/api/auth/device_code", json={"name": name})
|
|
74
|
+
r.raise_for_status()
|
|
75
|
+
return r.json()
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def poll_device_flow(device_code: str, interval: int, expires_in: int) -> dict:
|
|
79
|
+
deadline = time.time() + expires_in
|
|
80
|
+
with _client() as c:
|
|
81
|
+
while time.time() < deadline:
|
|
82
|
+
r = c.post("/api/auth/device_token", json={"device_code": device_code})
|
|
83
|
+
if r.status_code != 200:
|
|
84
|
+
raise AuthError(f"poll failed: {r.status_code} {r.text}")
|
|
85
|
+
data = r.json()
|
|
86
|
+
status = data.get("status")
|
|
87
|
+
if status == "approved":
|
|
88
|
+
return data
|
|
89
|
+
if status in ("denied", "expired"):
|
|
90
|
+
raise AuthError(f"pairing {status}")
|
|
91
|
+
time.sleep(interval)
|
|
92
|
+
raise AuthError("pairing timed out")
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def revoke_remote(token: str) -> None:
|
|
96
|
+
"""Best-effort: ask the backend to revoke this token."""
|
|
97
|
+
# Use the regular token-listing flow once it's exposed via mcp auth.
|
|
98
|
+
# For now we rely on a /api/auth/mcp_self_revoke equivalent: the
|
|
99
|
+
# token revoke endpoint takes its id, which the CLI does not store,
|
|
100
|
+
# so we just delete the local file. Server-side cleanup is the iOS
|
|
101
|
+
# app's job (token list page).
|
|
102
|
+
return
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def login(name: Optional[str]) -> StoredToken:
|
|
106
|
+
info = start_device_flow(name)
|
|
107
|
+
user_code = info["user_code"]
|
|
108
|
+
device_code = info["device_code"]
|
|
109
|
+
interval = info.get("interval", 3)
|
|
110
|
+
expires_in = info.get("expires_in", 600)
|
|
111
|
+
|
|
112
|
+
print(f"配对码: {user_code}", file=sys.stderr)
|
|
113
|
+
print(
|
|
114
|
+
"请在 plintho iOS app → Settings → MCP Access 输入此码",
|
|
115
|
+
file=sys.stderr,
|
|
116
|
+
)
|
|
117
|
+
print("等待中...", file=sys.stderr)
|
|
118
|
+
|
|
119
|
+
result = poll_device_flow(device_code, interval, expires_in)
|
|
120
|
+
token = result.get("access_token")
|
|
121
|
+
if not token:
|
|
122
|
+
raise AuthError("server returned no token")
|
|
123
|
+
|
|
124
|
+
stored = StoredToken(
|
|
125
|
+
token=token,
|
|
126
|
+
user_id=result.get("user_id"),
|
|
127
|
+
name=result.get("name") or name,
|
|
128
|
+
)
|
|
129
|
+
save_token(stored)
|
|
130
|
+
return stored
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""plintho-mcp CLI entrypoint.
|
|
2
|
+
|
|
3
|
+
Subcommands:
|
|
4
|
+
login [--name NAME] [--force]
|
|
5
|
+
logout
|
|
6
|
+
whoami
|
|
7
|
+
serve (default; what MCP clients invoke)
|
|
8
|
+
"""
|
|
9
|
+
import argparse
|
|
10
|
+
import sys
|
|
11
|
+
|
|
12
|
+
from plintho_mcp import auth, server
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _cmd_login(args: argparse.Namespace) -> int:
|
|
16
|
+
if auth.load_token() and not args.force:
|
|
17
|
+
print("已登录。使用 --force 重新配对。", file=sys.stderr)
|
|
18
|
+
return 0
|
|
19
|
+
try:
|
|
20
|
+
stored = auth.login(name=args.name)
|
|
21
|
+
except auth.AuthError as e:
|
|
22
|
+
print(f"登录失败: {e}", file=sys.stderr)
|
|
23
|
+
return 1
|
|
24
|
+
label = stored.user_id or "unknown user"
|
|
25
|
+
print(f"✓ 已登录为 {label}", file=sys.stderr)
|
|
26
|
+
return 0
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _cmd_logout(_args: argparse.Namespace) -> int:
|
|
30
|
+
stored = auth.load_token()
|
|
31
|
+
if stored:
|
|
32
|
+
auth.revoke_remote(stored.token)
|
|
33
|
+
auth.delete_token()
|
|
34
|
+
print("已删除本地 token。如需服务端吊销,请在 iOS app MCP Access 页面操作。",
|
|
35
|
+
file=sys.stderr)
|
|
36
|
+
return 0
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _cmd_whoami(_args: argparse.Namespace) -> int:
|
|
40
|
+
stored = auth.load_token()
|
|
41
|
+
if not stored:
|
|
42
|
+
print("未登录", file=sys.stderr)
|
|
43
|
+
return 1
|
|
44
|
+
print(f"user_id: {stored.user_id}")
|
|
45
|
+
if stored.name:
|
|
46
|
+
print(f"name: {stored.name}")
|
|
47
|
+
return 0
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _cmd_serve(_args: argparse.Namespace) -> int:
|
|
51
|
+
server.run()
|
|
52
|
+
return 0
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
56
|
+
p = argparse.ArgumentParser(prog="plintho-mcp")
|
|
57
|
+
sub = p.add_subparsers(dest="cmd")
|
|
58
|
+
|
|
59
|
+
p_login = sub.add_parser("login", help="Pair this device with your plintho account")
|
|
60
|
+
p_login.add_argument("--name", help="Token label, e.g. 'MacBook Cursor'")
|
|
61
|
+
p_login.add_argument("--force", action="store_true",
|
|
62
|
+
help="Re-pair even if a token already exists")
|
|
63
|
+
p_login.set_defaults(func=_cmd_login)
|
|
64
|
+
|
|
65
|
+
p_logout = sub.add_parser("logout")
|
|
66
|
+
p_logout.set_defaults(func=_cmd_logout)
|
|
67
|
+
|
|
68
|
+
p_whoami = sub.add_parser("whoami")
|
|
69
|
+
p_whoami.set_defaults(func=_cmd_whoami)
|
|
70
|
+
|
|
71
|
+
p_serve = sub.add_parser("serve", help="Run the stdio MCP server (default)")
|
|
72
|
+
p_serve.set_defaults(func=_cmd_serve)
|
|
73
|
+
|
|
74
|
+
return p
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def main(argv: list[str] | None = None) -> int:
|
|
78
|
+
parser = build_parser()
|
|
79
|
+
args = parser.parse_args(argv)
|
|
80
|
+
if not getattr(args, "func", None):
|
|
81
|
+
# Default action when invoked with no args (how MCP clients call us).
|
|
82
|
+
return _cmd_serve(args)
|
|
83
|
+
return args.func(args)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if __name__ == "__main__":
|
|
87
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Runtime config for the plintho MCP CLI / server.
|
|
2
|
+
|
|
3
|
+
All settings are environment-driven so the same binary works against
|
|
4
|
+
local dev, the staging server, and prod without rebuilding.
|
|
5
|
+
"""
|
|
6
|
+
import os
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
DEFAULT_API_BASE = "https://api.plintho.app"
|
|
10
|
+
|
|
11
|
+
API_BASE_URL = os.environ.get("PLINTHO_API_BASE", DEFAULT_API_BASE).rstrip("/")
|
|
12
|
+
|
|
13
|
+
CONFIG_DIR = Path(os.environ.get("PLINTHO_HOME", str(Path.home() / ".plintho")))
|
|
14
|
+
TOKEN_PATH = CONFIG_DIR / "mcp_token"
|
|
15
|
+
|
|
16
|
+
REQUEST_TIMEOUT_SECONDS = 30
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""stdio MCP server exposing plintho tools.
|
|
2
|
+
|
|
3
|
+
Built on the official `mcp` Python SDK. Each tool in `tools.TOOL_REGISTRY`
|
|
4
|
+
is registered with a hand-written JSON schema; we keep schemas in this
|
|
5
|
+
file (rather than introspecting) so the model sees clean, stable param
|
|
6
|
+
descriptions.
|
|
7
|
+
"""
|
|
8
|
+
import asyncio
|
|
9
|
+
import json
|
|
10
|
+
import logging
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from mcp.server import Server
|
|
14
|
+
from mcp.server.stdio import stdio_server
|
|
15
|
+
from mcp.types import TextContent, Tool
|
|
16
|
+
|
|
17
|
+
from plintho_mcp import tools
|
|
18
|
+
|
|
19
|
+
logger = logging.getLogger("plintho_mcp.server")
|
|
20
|
+
|
|
21
|
+
TOOL_SCHEMAS: list[Tool] = [
|
|
22
|
+
Tool(
|
|
23
|
+
name="list_events_by_date",
|
|
24
|
+
description="List all of the user's events on a given date.",
|
|
25
|
+
inputSchema={
|
|
26
|
+
"type": "object",
|
|
27
|
+
"properties": {
|
|
28
|
+
"date": {
|
|
29
|
+
"type": "string",
|
|
30
|
+
"description": "YYYY-MM-DD, or 'today' / 'yesterday'.",
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"required": ["date"],
|
|
34
|
+
},
|
|
35
|
+
),
|
|
36
|
+
Tool(
|
|
37
|
+
name="get_event_detail",
|
|
38
|
+
description="Fetch a single event's note (Markdown) and raw utterances.",
|
|
39
|
+
inputSchema={
|
|
40
|
+
"type": "object",
|
|
41
|
+
"properties": {
|
|
42
|
+
"event_id": {"type": "string"},
|
|
43
|
+
"max_utterances": {"type": "integer", "default": 200},
|
|
44
|
+
},
|
|
45
|
+
"required": ["event_id"],
|
|
46
|
+
},
|
|
47
|
+
),
|
|
48
|
+
Tool(
|
|
49
|
+
name="search_events",
|
|
50
|
+
description=(
|
|
51
|
+
"Search the user's events by free-text query. Optionally restrict "
|
|
52
|
+
"to a single date. Use this to answer questions like '昨天下午是否 "
|
|
53
|
+
"有关于 X 的事件'."
|
|
54
|
+
),
|
|
55
|
+
inputSchema={
|
|
56
|
+
"type": "object",
|
|
57
|
+
"properties": {
|
|
58
|
+
"query": {"type": "string"},
|
|
59
|
+
"date": {
|
|
60
|
+
"type": "string",
|
|
61
|
+
"description": "Optional YYYY-MM-DD or 'today'/'yesterday'.",
|
|
62
|
+
},
|
|
63
|
+
"limit": {"type": "integer", "default": 20},
|
|
64
|
+
},
|
|
65
|
+
"required": ["query"],
|
|
66
|
+
},
|
|
67
|
+
),
|
|
68
|
+
Tool(
|
|
69
|
+
name="search_utterances",
|
|
70
|
+
description="Search raw utterances (transcribed speech) by substring.",
|
|
71
|
+
inputSchema={
|
|
72
|
+
"type": "object",
|
|
73
|
+
"properties": {
|
|
74
|
+
"query": {"type": "string"},
|
|
75
|
+
"date": {"type": "string"},
|
|
76
|
+
"limit": {"type": "integer", "default": 50},
|
|
77
|
+
},
|
|
78
|
+
"required": ["query"],
|
|
79
|
+
},
|
|
80
|
+
),
|
|
81
|
+
Tool(
|
|
82
|
+
name="get_daily_summary",
|
|
83
|
+
description="Fetch the user's daily summary (日报) for a given date.",
|
|
84
|
+
inputSchema={
|
|
85
|
+
"type": "object",
|
|
86
|
+
"properties": {"date": {"type": "string"}},
|
|
87
|
+
"required": ["date"],
|
|
88
|
+
},
|
|
89
|
+
),
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def build_server() -> Server:
|
|
94
|
+
server = Server("plintho")
|
|
95
|
+
|
|
96
|
+
@server.list_tools()
|
|
97
|
+
async def _list_tools() -> list[Tool]:
|
|
98
|
+
return TOOL_SCHEMAS
|
|
99
|
+
|
|
100
|
+
@server.call_tool()
|
|
101
|
+
async def _call_tool(name: str, arguments: dict[str, Any]) -> list[TextContent]:
|
|
102
|
+
fn = tools.TOOL_REGISTRY.get(name)
|
|
103
|
+
if not fn:
|
|
104
|
+
return [TextContent(type="text", text=f"Unknown tool: {name}")]
|
|
105
|
+
try:
|
|
106
|
+
result = fn(**(arguments or {}))
|
|
107
|
+
except Exception as e:
|
|
108
|
+
logger.exception("tool %s failed", name)
|
|
109
|
+
return [TextContent(type="text", text=f"Error: {e}")]
|
|
110
|
+
return [TextContent(type="text", text=json.dumps(result, ensure_ascii=False))]
|
|
111
|
+
|
|
112
|
+
return server
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
async def _run() -> None:
|
|
116
|
+
server = build_server()
|
|
117
|
+
async with stdio_server() as (read, write):
|
|
118
|
+
await server.run(read, write, server.create_initialization_options())
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def run() -> None:
|
|
122
|
+
asyncio.run(_run())
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""MCP tool implementations.
|
|
2
|
+
|
|
3
|
+
Each tool proxies an existing plintho HTTP endpoint and never trusts
|
|
4
|
+
its caller for the user_id — that's resolved server-side from the MCP
|
|
5
|
+
token. Tools should keep responses small and structured.
|
|
6
|
+
"""
|
|
7
|
+
from datetime import date, datetime, timedelta
|
|
8
|
+
from typing import Optional
|
|
9
|
+
|
|
10
|
+
from plintho_mcp import api_client
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# ── helpers ────────────────────────────────────────────────────────
|
|
14
|
+
|
|
15
|
+
def _parse_date(s: Optional[str]) -> Optional[str]:
|
|
16
|
+
"""Accept YYYY-MM-DD or relative tokens 'today'/'yesterday'."""
|
|
17
|
+
if not s:
|
|
18
|
+
return None
|
|
19
|
+
s = s.strip().lower()
|
|
20
|
+
if s == "today":
|
|
21
|
+
return date.today().isoformat()
|
|
22
|
+
if s == "yesterday":
|
|
23
|
+
return (date.today() - timedelta(days=1)).isoformat()
|
|
24
|
+
# Validate ISO date.
|
|
25
|
+
datetime.strptime(s, "%Y-%m-%d")
|
|
26
|
+
return s
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _trim_event(ev: dict) -> dict:
|
|
30
|
+
"""Strip vector / verbose fields before returning to the model."""
|
|
31
|
+
keep = {
|
|
32
|
+
"event_id", "title", "summary", "notes",
|
|
33
|
+
"start_time_absolute", "end_time_absolute",
|
|
34
|
+
"participants", "category", "channel",
|
|
35
|
+
}
|
|
36
|
+
return {k: ev.get(k) for k in keep if k in ev}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# ── tools ──────────────────────────────────────────────────────────
|
|
40
|
+
|
|
41
|
+
def list_events_by_date(date: str) -> dict:
|
|
42
|
+
"""List all events on a given date.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
date: YYYY-MM-DD, or 'today' / 'yesterday'.
|
|
46
|
+
"""
|
|
47
|
+
iso = _parse_date(date)
|
|
48
|
+
events = api_client.get("/api/events", params={"date": iso})
|
|
49
|
+
return {"date": iso, "events": [_trim_event(e) for e in events]}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def get_event_detail(event_id: str, max_utterances: int = 200) -> dict:
|
|
53
|
+
"""Fetch a single event's note + raw utterances.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
event_id: ID returned from list_events_by_date or search_events.
|
|
57
|
+
max_utterances: cap on returned utterances (default 200).
|
|
58
|
+
"""
|
|
59
|
+
data = api_client.get(
|
|
60
|
+
f"/api/events/{event_id}",
|
|
61
|
+
params={"page": 1, "size": max_utterances},
|
|
62
|
+
)
|
|
63
|
+
ev = _trim_event(data.get("event", {}))
|
|
64
|
+
utts = data.get("utterances", {}).get("items", [])
|
|
65
|
+
trimmed_utts = [
|
|
66
|
+
{
|
|
67
|
+
"speaker": u.get("speaker_name") or u.get("speaker"),
|
|
68
|
+
"text": u.get("text"),
|
|
69
|
+
"start_time": u.get("start_time_absolute"),
|
|
70
|
+
}
|
|
71
|
+
for u in utts
|
|
72
|
+
]
|
|
73
|
+
return {"event": ev, "utterances": trimmed_utts}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def search_events(query: str, date: Optional[str] = None, limit: int = 20) -> dict:
|
|
77
|
+
"""Search events by free-text query, optionally restricted to a date.
|
|
78
|
+
|
|
79
|
+
Args:
|
|
80
|
+
query: natural-language query string.
|
|
81
|
+
date: optional YYYY-MM-DD or 'today'/'yesterday'.
|
|
82
|
+
limit: max events returned (default 20).
|
|
83
|
+
"""
|
|
84
|
+
iso = _parse_date(date)
|
|
85
|
+
params = {}
|
|
86
|
+
if iso:
|
|
87
|
+
params["date"] = iso
|
|
88
|
+
events = api_client.get("/api/events", params=params)
|
|
89
|
+
q = query.lower()
|
|
90
|
+
hits = []
|
|
91
|
+
for e in events:
|
|
92
|
+
blob = " ".join(
|
|
93
|
+
str(e.get(k) or "")
|
|
94
|
+
for k in ("title", "summary", "notes", "participants")
|
|
95
|
+
).lower()
|
|
96
|
+
if q in blob:
|
|
97
|
+
hits.append(_trim_event(e))
|
|
98
|
+
if len(hits) >= limit:
|
|
99
|
+
break
|
|
100
|
+
return {"query": query, "date": iso, "events": hits}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def search_utterances(query: str, date: Optional[str] = None, limit: int = 50) -> dict:
|
|
104
|
+
"""Search raw utterances containing a substring, optionally on a date."""
|
|
105
|
+
iso = _parse_date(date)
|
|
106
|
+
params = {"page": 1, "size": 500}
|
|
107
|
+
if iso:
|
|
108
|
+
params["date"] = iso
|
|
109
|
+
data = api_client.get("/api/utterances", params=params)
|
|
110
|
+
items = data.get("items", []) if isinstance(data, dict) else data
|
|
111
|
+
q = query.lower()
|
|
112
|
+
hits = [
|
|
113
|
+
{
|
|
114
|
+
"text": u.get("text"),
|
|
115
|
+
"speaker": u.get("speaker_name") or u.get("speaker"),
|
|
116
|
+
"start_time": u.get("start_time_absolute"),
|
|
117
|
+
"event_id": u.get("event_id"),
|
|
118
|
+
}
|
|
119
|
+
for u in items
|
|
120
|
+
if q in (u.get("text") or "").lower()
|
|
121
|
+
][:limit]
|
|
122
|
+
return {"query": query, "date": iso, "utterances": hits}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def get_daily_summary(date: str) -> dict:
|
|
126
|
+
"""Fetch the daily summary (日报) for a given date."""
|
|
127
|
+
iso = _parse_date(date)
|
|
128
|
+
data = api_client.get("/api/daily_summaries", params={"date": iso})
|
|
129
|
+
return {"date": iso, "summary": data}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
TOOL_REGISTRY = {
|
|
133
|
+
"list_events_by_date": list_events_by_date,
|
|
134
|
+
"get_event_detail": get_event_detail,
|
|
135
|
+
"search_events": search_events,
|
|
136
|
+
"search_utterances": search_utterances,
|
|
137
|
+
"get_daily_summary": get_daily_summary,
|
|
138
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: plintho-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP server + CLI for the plintho voice journal
|
|
5
|
+
Author: vtech-ai
|
|
6
|
+
License: Proprietary
|
|
7
|
+
Project-URL: Homepage, https://plintho.app
|
|
8
|
+
Keywords: mcp,voice-journal,plintho
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Requires-Python: >=3.11
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
Requires-Dist: mcp>=1.0
|
|
15
|
+
Requires-Dist: httpx>=0.27
|
|
16
|
+
|
|
17
|
+
# plintho-mcp
|
|
18
|
+
|
|
19
|
+
A small CLI + [MCP](https://modelcontextprotocol.io) server that lets any
|
|
20
|
+
MCP-capable client (Claude Desktop, Cursor, Cline, Zed, …) query the
|
|
21
|
+
plintho voice-journal backend on behalf of a single user.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
Direct from GitHub (no PyPI release yet):
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pipx install 'git+https://github.com/vtech-ai/plintho-mcp.git'
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Or with pip:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install 'git+https://github.com/vtech-ai/plintho-mcp.git'
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Local checkout while developing:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
git clone https://github.com/vtech-ai/plintho-mcp.git
|
|
41
|
+
cd plintho-mcp
|
|
42
|
+
pipx install -e .
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Requires Python 3.11+. Runtime deps: `mcp`, `httpx`. The package does
|
|
46
|
+
**not** pull in any of the plintho backend's heavy dependencies.
|
|
47
|
+
|
|
48
|
+
## Pair this device with your account
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
$ plintho-mcp login --name "MacBook Cursor"
|
|
52
|
+
配对码: WXYZ-2345
|
|
53
|
+
请在 plintho iOS app → Settings → MCP Access 输入此码
|
|
54
|
+
等待中...
|
|
55
|
+
✓ 已登录为 user-abc
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The token is saved to `~/.plintho/mcp_token` (mode 600). The plaintext
|
|
59
|
+
exists only on this machine; the server stores only its sha256 hash.
|
|
60
|
+
|
|
61
|
+
## Wire into your MCP client
|
|
62
|
+
|
|
63
|
+
### Claude Desktop — `claude_desktop_config.json`
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"mcpServers": {
|
|
68
|
+
"plintho": { "command": "plintho-mcp" }
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Claude Code
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
claude mcp add plintho -- plintho-mcp
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Cursor — `~/.cursor/mcp.json`
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"mcpServers": {
|
|
84
|
+
"plintho": { "command": "plintho-mcp" }
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Same `command` key works for Cline / Zed / Continue / any stdio-MCP client.
|
|
90
|
+
|
|
91
|
+
## Tools exposed
|
|
92
|
+
|
|
93
|
+
| Tool | What it does |
|
|
94
|
+
| ---------------------- | ----------------------------------------------------------------------- |
|
|
95
|
+
| `list_events_by_date` | All events on a given date (YYYY-MM-DD or `today`/`yesterday`). |
|
|
96
|
+
| `get_event_detail` | One event's note (Markdown) + raw utterances. |
|
|
97
|
+
| `search_events` | Free-text search across event titles/summaries/notes, optional date. |
|
|
98
|
+
| `search_utterances` | Substring search across raw transcribed utterances. |
|
|
99
|
+
| `get_daily_summary` | Daily summary (日报) for a given date. |
|
|
100
|
+
|
|
101
|
+
All tools are scoped to the user the token was issued to — there is no
|
|
102
|
+
`user_id` parameter and the server enforces ownership on every call.
|
|
103
|
+
|
|
104
|
+
## Other commands
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
plintho-mcp whoami # show current user_id / token name
|
|
108
|
+
plintho-mcp logout # delete the local token file
|
|
109
|
+
plintho-mcp login --force # re-pair (replaces existing token locally)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
To revoke a token server-side, use the iOS app → Settings → MCP Access.
|
|
113
|
+
|
|
114
|
+
## Environment variables
|
|
115
|
+
|
|
116
|
+
| Var | Default | Purpose |
|
|
117
|
+
| ------------------ | ----------------------------- | -------------------------------- |
|
|
118
|
+
| `PLINTHO_API_BASE` | `https://api.plintho.app` | Backend URL. |
|
|
119
|
+
| `PLINTHO_HOME` | `~/.plintho` | Token + config directory. |
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
plintho_mcp/__init__.py
|
|
4
|
+
plintho_mcp/__main__.py
|
|
5
|
+
plintho_mcp/api_client.py
|
|
6
|
+
plintho_mcp/auth.py
|
|
7
|
+
plintho_mcp/cli.py
|
|
8
|
+
plintho_mcp/config.py
|
|
9
|
+
plintho_mcp/server.py
|
|
10
|
+
plintho_mcp/tools.py
|
|
11
|
+
plintho_mcp.egg-info/PKG-INFO
|
|
12
|
+
plintho_mcp.egg-info/SOURCES.txt
|
|
13
|
+
plintho_mcp.egg-info/dependency_links.txt
|
|
14
|
+
plintho_mcp.egg-info/entry_points.txt
|
|
15
|
+
plintho_mcp.egg-info/requires.txt
|
|
16
|
+
plintho_mcp.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
plintho_mcp
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "plintho-mcp"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "MCP server + CLI for the plintho voice journal"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.11"
|
|
7
|
+
license = { text = "Proprietary" }
|
|
8
|
+
authors = [{ name = "vtech-ai" }]
|
|
9
|
+
keywords = ["mcp", "voice-journal", "plintho"]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Programming Language :: Python :: 3",
|
|
12
|
+
"Programming Language :: Python :: 3.11",
|
|
13
|
+
"Programming Language :: Python :: 3.12",
|
|
14
|
+
]
|
|
15
|
+
dependencies = [
|
|
16
|
+
"mcp>=1.0",
|
|
17
|
+
"httpx>=0.27",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[project.urls]
|
|
21
|
+
Homepage = "https://plintho.app"
|
|
22
|
+
|
|
23
|
+
[project.scripts]
|
|
24
|
+
plintho-mcp = "plintho_mcp.cli:main"
|
|
25
|
+
|
|
26
|
+
[build-system]
|
|
27
|
+
requires = ["setuptools>=64", "wheel"]
|
|
28
|
+
build-backend = "setuptools.build_meta"
|
|
29
|
+
|
|
30
|
+
[tool.setuptools]
|
|
31
|
+
packages = ["plintho_mcp"]
|