tvpulse-mcp 1.0.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.
@@ -0,0 +1,11 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ .pytest_cache/
5
+ .mypy_cache/
6
+ .ruff_cache/
7
+ dist/
8
+ dist-bundle/
9
+ *.egg-info/
10
+ *.mcpb
11
+ distribution/skill-build/
@@ -0,0 +1,370 @@
1
+ Metadata-Version: 2.5
2
+ Name: tvpulse-mcp
3
+ Version: 1.0.0
4
+ Summary: Local (stdio) MCP server exposing the TVPulse customer API to MCP clients such as Claude Code.
5
+ Project-URL: Homepage, https://gateway.tvpulse.io/apidocs
6
+ Project-URL: Repository, https://gitlab.imind.dev/tvpulse/tvpulse
7
+ Author-email: InfiniMind <support@infinimind.io>
8
+ License: Proprietary
9
+ Keywords: claude-code,mcp,model-context-protocol,tvpulse
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Requires-Python: >=3.10
18
+ Requires-Dist: mcp<2.0.0,>=1.6.0
19
+ Requires-Dist: tvpulse<2,>=1.0
20
+ Provides-Extra: dev
21
+ Requires-Dist: mypy>=1.10; extra == 'dev'
22
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
23
+ Requires-Dist: pytest>=8.0; extra == 'dev'
24
+ Requires-Dist: respx>=0.20; extra == 'dev'
25
+ Requires-Dist: ruff>=0.5; extra == 'dev'
26
+ Description-Content-Type: text/markdown
27
+
28
+ # tvpulse-mcp
29
+
30
+ TVPulse カスタマーAPI(日本のテレビCM/露出分析SaaS)を Claude Code などの MCP クライアントから
31
+ ローカル(stdio)で使うための MCP サーバーです。
32
+
33
+ ## これは何か
34
+
35
+ `/v1/api/searches`(検索定義+投影)を土台に、1回の課金付き検索作成のあとに無料の集計・証跡取得を
36
+ 組み合わせた12個のツールを公開します。生のOCR/ASR検索を都度課金する方式ではなく、1つの質問に対して
37
+ 1回の検索を作成し、トレンド・内訳・番組・証跡をまとめて返します。支出はすべて人の承認を経てから実行
38
+ されます(下記「承認フローと予算」)。
39
+
40
+ ## インストール
41
+
42
+ 3つの方法があります。迷ったら **Claude Codeプラグイン**(設定不要でAPIキーを安全に保存)を
43
+ おすすめします。
44
+
45
+ ### 方法1: Claude Codeプラグイン(推奨)
46
+
47
+ ```
48
+ /plugin marketplace add https://tvpulse.io/claude/marketplace.json
49
+ /plugin install tvpulse@tvpulse
50
+ ```
51
+
52
+ Claude Code バージョン 2.1.224 以降が必要です。インストール時にAPIキーの入力を求められます
53
+ (安全に保存され、チャット欄には表示されません)。承認しきい値・セッション予算はデフォルト値
54
+ (20クレジット / 200クレジット)のままで構いません。監視スキルも同時にインストールされます。
55
+ 詳細は [distribution/claude-plugin/README.md](distribution/claude-plugin/README.md) を
56
+ 参照してください。
57
+
58
+ 前提条件: [uv](https://docs.astral.sh/uv/) がインストールされていること(`uvx` を使用します)。
59
+
60
+ ### 方法2: Claude Desktop拡張機能(.mcpbバンドル)
61
+
62
+ [https://tvpulse.io/claude/tvpulse.mcpb](https://tvpulse.io/claude/tvpulse.mcpb) から
63
+ `tvpulse.mcpb` をダウンロードし、ダブルクリックするか Claude Desktop の
64
+ 「設定 > 拡張機能 > ローカルにインストール」から追加してください。初回起動時にAPIキーの入力を
65
+ 求められます。前提条件は方法1と同じく `uv`/`uvx` です。
66
+
67
+ ### 方法3: 手動セットアップ(Claude Code、バージョン固定インストール)
68
+
69
+ ```bash
70
+ uvx tvpulse-mcp==1.0.0
71
+ ```
72
+
73
+ Claude Code に直接登録する場合:
74
+
75
+ ```bash
76
+ claude mcp add tvpulse \
77
+ -e TVPULSE_API_KEY=your-api-key \
78
+ -e TVPULSE_CONFIRM_ABOVE_CREDITS=20 \
79
+ -e TVPULSE_SESSION_BUDGET_CREDITS=200 \
80
+ -- uvx tvpulse-mcp==1.0.0
81
+ ```
82
+
83
+ APIキーは環境変数で渡してください(チャット欄に貼り付けないでください)。開発環境(dev gateway)に
84
+ 向ける場合は `TVPULSE_BASE_URL` を追加します:
85
+
86
+ ```bash
87
+ claude mcp add tvpulse \
88
+ -e TVPULSE_API_KEY=your-dev-api-key \
89
+ -e TVPULSE_BASE_URL=https://gateway.dev.tvpulse.io \
90
+ -e TVPULSE_CONFIRM_ABOVE_CREDITS=20 \
91
+ -e TVPULSE_SESSION_BUDGET_CREDITS=200 \
92
+ -- uvx tvpulse-mcp==1.0.0
93
+ ```
94
+
95
+ `TVPULSE_BASE_URL` を省略した場合は本番 `https://gateway.tvpulse.io` を使います
96
+ (`tvpulse.client.DEFAULT_BASE_URL` と同じ値)。
97
+
98
+ ### APIキーをまだお持ちでない場合
99
+
100
+ いずれの方法でも、APIキー未設定のまま `tvpulse_check_connection` などのツールを呼び出すと、
101
+ 発行手順(https://tvpulse.io/account/api-keys )と、お使いのクライアント別の設定方法を案内する
102
+ 日本語メッセージが返ります。
103
+
104
+ 登録後、最初にこう聞いて接続を確認してください:
105
+
106
+ ```
107
+ TVPulseに接続できているか確認して
108
+ ```
109
+
110
+ これは無料の `tvpulse_check_connection` を呼び出し、APIキーの有効性・接続先・残高・設定済み予算を
111
+ 表示します。
112
+
113
+ ## 承認フローと予算
114
+
115
+ `tvpulse_search_mentions` と課金付き `tvpulse_export_records_create` は次の順で承認を経ます:
116
+
117
+ 1. まず見積もり(無料)を取り、`interpretation`(キーワード/モード、日本語の局名と地域、明示的な
118
+ JST期間、CMポリシー)を必ず提示します。
119
+ 2. 見積額が `TVPULSE_CONFIRM_ABOVE_CREDITS`(既定20クレジット)以下なら、そのまま実行します。
120
+ 3. それを超える場合、MCP elicitation でユーザーに直接確認するか、クライアントが対応していなければ
121
+ `needs_confirmation` と `confirm_token`(10分間有効、1回限り)を返します。ユーザーが承認したら、
122
+ 同じツールを `confirm_token` を添えて再実行してください。
123
+ 4. `TVPULSE_SESSION_BUDGET_CREDITS`(既定200クレジット、このセッション累計の上限)を超える場合は、
124
+ 何を渡しても上書きできない拒否になります。より多く使いたい場合は、より大きな値でセッションを
125
+ 再起動してください。
126
+ 5. `outcome=enterprise_review` は予算の問題ではなく個別見積もりが必要な料金区分です。クレジットを
127
+ 増やしても解決しません。
128
+
129
+ **重要**: どちらの上限もツール引数では絶対に上げられません(環境変数のみ)。1回の呼び出しに渡せる
130
+ 値があるとすれば、それは上限を下げる方向にしか使えない設計です。
131
+
132
+ ## ツール一覧
133
+
134
+ | ツール | 課金 | ゲートウェイルート |
135
+ |---|---|---|
136
+ | `tvpulse_check_connection` | 無料 | `GET /v1/api/credits`(キー検証を兼ねる) |
137
+ | `tvpulse_list_channels` | 無料 | なし(静的カタログ) |
138
+ | `tvpulse_estimate` | 無料 | `POST /v1/api/credits/estimate` |
139
+ | `tvpulse_search_mentions` | 課金あり(承認フロー経由) | `POST /v1/api/searches` + `GET .../trend,breakdown,programs,evidence` |
140
+ | `tvpulse_get_evidence` | 無料 | `GET /v1/api/searches/{id}/evidence` |
141
+ | `tvpulse_get_search_results` | 無料 | `GET /v1/api/searches/{id}/{trend,breakdown,programs,evidence}`(再取得) |
142
+ | `tvpulse_save_evidence_csv` | 無料(ローカルファイル書き込み) | `GET /v1/api/searches/{id}/evidence`(ページング) |
143
+ | `tvpulse_credits_balance` | 無料 | `GET /v1/api/credits` |
144
+ | `tvpulse_export_records_create` | dry_run=falseで課金(承認フロー経由) | `POST /v1alpha1/exports` |
145
+ | `tvpulse_export_records_status` | 課金あり(ポーリング毎、失敗時も返金なし) | `GET /v1alpha1/exports/{export_id}` |
146
+ | `tvpulse_trend_reports_list` | 無料 | `GET /v1alpha1/trend-watch/catalog/reports` |
147
+ | `tvpulse_trend_reports_get` | 無料 | `GET /v1alpha1/trend-watch/catalog/reports/{id}` |
148
+
149
+ ### クレジットと制限に関する注意
150
+
151
+ - OCR(画面内テキスト)とASR(音声)の件数は単位が異なるため、常に別々に返され、合算されません。
152
+ - 対応局は地上波15局(東京7局+大阪8局)のうち、プリセット `tokyo`(7局)または `osaka`
153
+ (`sun` を含む8局)、あるいは最大14局までの明示指定です。15局すべてを一度に指定すると常に
154
+ `custom_pricing_required` エラーになります(自動的に14局へ絞り込まれることはありません)。
155
+ - `sampled_programs` は返された証跡からサンプリングされた番組であり、ランキングでも全放送の
156
+ 網羅的な記録でもありません。
157
+ - 投影(trend/breakdown/sampled_programs/evidence)がまだ計算中の場合は `0` や空配列ではなく
158
+ `{"status": "unavailable", "reason": ...}` として返されます。`tvpulse_get_search_results`
159
+ (無料)で再取得してください。
160
+ - `tvpulse_export_records_status` のポーリングは呼び出すたびに課金され、ジョブが失敗しても
161
+ 返金されません。同じ `export_id` へのポーリングは30秒以上間隔を空ける必要があります
162
+ (それより短い間隔はツール側で拒否します)。
163
+ - 同一セッション内で全く同じ検索条件を再度呼び出した場合、新規課金せずに既存の `search_id` を
164
+ 無料で返します(`refresh=true` で強制的に再見積もり・再実行)。
165
+ - 課金系ツールは自動リトライしません(二重課金防止)。実行ごとに専用の Idempotency-Key を使用します。
166
+
167
+ ### 監視スキルの導入
168
+
169
+ Claude Codeプラグイン(方法1)を使う場合、スキルは自動的にインストールされます。手動セットアップ
170
+ (方法3)の場合は、`skill/tvpulse-tv-monitoring/` を Claude Code がスキルを読み込む場所へコピーして
171
+ ください:
172
+
173
+ ```bash
174
+ cp -r skill/tvpulse-tv-monitoring ~/.claude/skills/tvpulse-tv-monitoring
175
+ # or, project-scoped:
176
+ cp -r skill/tvpulse-tv-monitoring .claude/skills/tvpulse-tv-monitoring
177
+ ```
178
+
179
+ Claude Desktop(方法2)の場合は `sdks/mcp/scripts/sync-distribution.sh` が作成する
180
+ `distribution/skill-build/tvpulse-tv-monitoring.zip` を「設定 > Capabilities > Skills」から
181
+ アップロードしてください。
182
+
183
+ ## トラブルシューティング
184
+
185
+ - **「APIキーが設定されていません」と出る**: いずれかの方法でAPIキーを設定してください
186
+ (プラグイン/拡張機能ならインストール時のプロンプト、手動セットアップなら
187
+ `TVPULSE_API_KEY` 環境変数)。`tvpulse_check_connection` を呼ぶとキーの発行先URLと、
188
+ お使いのクライアント別の設定手順が日本語で表示されます。
189
+ - **「APIキーが無効です」「401」エラー**: キーが失効・削除されている可能性があります。
190
+ https://tvpulse.io/account/api-keys で新しいキーを発行し、設定し直してください。未設定時とは
191
+ 別の、無効キー専用のメッセージが表示されます。
192
+ - **`uv`/`uvx` が見つからない**: https://docs.astral.sh/uv/getting-started/installation/
193
+ の手順でインストールしてください。全3つのインストール方法が `uvx` を前提としています。
194
+ - **承認プロンプトが表示されない / `confirm_token` が使えない**: MCP elicitationに対応していない
195
+ クライアントでは、承認が必要な呼び出しは実行されず `needs_confirmation` と `confirm_token`
196
+ (10分間有効、1回限り)が返るだけです。表示された内容を確認したうえで、同じツールを
197
+ `confirm_token` を添えて再実行してください。トークンが期限切れの場合は見積もりからやり直します。
198
+
199
+ ---
200
+
201
+ ## English
202
+
203
+ Local (stdio) MCP server exposing the TVPulse customer API to Claude Code and other MCP
204
+ clients, built around `/v1/api/searches`: one billed search-definition create followed
205
+ by free trend/breakdown/programs/evidence projections, so one analyst question costs one
206
+ charge instead of three. Every spend goes through a human-approval gate before it runs
207
+ (see "Approval flow and budgets" below).
208
+
209
+ ### Install
210
+
211
+ There are three ways to install. If unsure, use the **Claude Code plugin** (no manual
212
+ config, API key stored securely).
213
+
214
+ #### Option 1: Claude Code plugin (recommended)
215
+
216
+ ```
217
+ /plugin marketplace add https://tvpulse.io/claude/marketplace.json
218
+ /plugin install tvpulse@tvpulse
219
+ ```
220
+
221
+ Requires Claude Code 2.1.224 or later. You'll be prompted for your API key at install
222
+ time (stored securely, never shown in chat). The confirm-above-credits threshold and
223
+ session budget default to 20 and 200 credits. The monitoring skill installs
224
+ automatically. See
225
+ [distribution/claude-plugin/README.md](distribution/claude-plugin/README.md) for details.
226
+
227
+ Prerequisite: [uv](https://docs.astral.sh/uv/) installed (provides `uvx`).
228
+
229
+ #### Option 2: Claude Desktop extension (.mcpb bundle)
230
+
231
+ Download [tvpulse.mcpb](https://tvpulse.io/claude/tvpulse.mcpb) and double-click
232
+ it, or add it via Claude Desktop's Settings > Extensions > Install from file. You'll be
233
+ prompted for your API key on first launch. Same `uv`/`uvx` prerequisite as Option 1.
234
+
235
+ #### Option 3: Manual setup (Claude Code, pinned version)
236
+
237
+ ```bash
238
+ uvx tvpulse-mcp==1.0.0
239
+ ```
240
+
241
+ ```bash
242
+ claude mcp add tvpulse \
243
+ -e TVPULSE_API_KEY=your-api-key \
244
+ -e TVPULSE_CONFIRM_ABOVE_CREDITS=20 \
245
+ -e TVPULSE_SESSION_BUDGET_CREDITS=200 \
246
+ -- uvx tvpulse-mcp==1.0.0
247
+ ```
248
+
249
+ Set `TVPULSE_API_KEY` via environment, never in chat. For the dev gateway:
250
+
251
+ ```bash
252
+ claude mcp add tvpulse \
253
+ -e TVPULSE_API_KEY=your-dev-api-key \
254
+ -e TVPULSE_BASE_URL=https://gateway.dev.tvpulse.io \
255
+ -e TVPULSE_CONFIRM_ABOVE_CREDITS=20 \
256
+ -e TVPULSE_SESSION_BUDGET_CREDITS=200 \
257
+ -- uvx tvpulse-mcp==1.0.0
258
+ ```
259
+
260
+ `TVPULSE_BASE_URL` defaults to production (`https://gateway.tvpulse.io`) if unset.
261
+
262
+ ### No API key yet?
263
+
264
+ With any install method, calling a tool such as `tvpulse_check_connection` without a key
265
+ returns a message (Japanese first, then English) with the issuance URL
266
+ (https://tvpulse.io/account/api-keys) and per-client setup instructions.
267
+
268
+ After registering, confirm the connection first by asking:
269
+
270
+ ```
271
+ TVPulseに接続できているか確認して
272
+ ```
273
+
274
+ (or in English, "check whether TVPulse is connected") -- this calls the free
275
+ `tvpulse_check_connection` tool, which validates the API key and shows the base URL,
276
+ balance, and configured budgets.
277
+
278
+ ### Approval flow and budgets
279
+
280
+ `tvpulse_search_mentions` and a non-dry-run `tvpulse_export_records_create` both go
281
+ through the same approval gate:
282
+
283
+ 1. Estimate first (free) and always show the `interpretation` block (keyword/mode,
284
+ Japanese station names + region, explicit JST window, CM policy) before spending.
285
+ 2. At or under `TVPULSE_CONFIRM_ABOVE_CREDITS` (default 20 credits), the call just runs.
286
+ 3. Above that threshold, the server asks a human directly via MCP elicitation, or -- if
287
+ the connected client doesn't support elicitation -- returns `needs_confirmation` with
288
+ a `confirm_token` (single-use, 10-minute TTL). Once the user approves, re-call the
289
+ same tool with that `confirm_token`.
290
+ 4. Exceeding `TVPULSE_SESSION_BUDGET_CREDITS` (default 200 credits, cumulative for this
291
+ session) is a hard refusal that no argument can override; restart the session with a
292
+ higher value if more spend is genuinely needed.
293
+ 5. `outcome=enterprise_review` is a pricing-tier issue, not a budget issue -- raising
294
+ credits will not fix it; the request needs a custom sales quote or a narrower scope.
295
+
296
+ **Important**: neither ceiling can ever be raised by a tool argument (env vars only). If
297
+ a per-call value is ever accepted, it can only lower a ceiling for that call, never
298
+ raise it.
299
+
300
+ ### Tools
301
+
302
+ See the table above (same tools, same routes). Highlights:
303
+
304
+ - `tvpulse_search_mentions` is the main tool: keyword + JST window + station preset/list
305
+ -> one billed search (after approval), returning separate OCR-observation and
306
+ ASR-segment counts by day and by station, `sampled_programs` (programs seen in the
307
+ sampled evidence, not a ranking), and a capped page of evidence, all timestamps
308
+ normalized to explicit `+09:00` JST strings. Unavailable projections are returned as
309
+ `{"status": "unavailable", "reason": ...}`, never as 0 or an empty list.
310
+ - `tvpulse_get_search_results` (free) re-fetches projections for an existing `search_id`
311
+ with bounded backoff, useful when some projections came back unavailable initially.
312
+ - `tvpulse_save_evidence_csv` (free, local write) pages already-paid evidence for a
313
+ `search_id` into an Excel-ready CSV: UTF-8 with BOM, JST timestamps, full untruncated
314
+ text, Japanese station names. Refuses to overwrite an existing file unless
315
+ `overwrite=true`.
316
+ - `tvpulse_export_records_create` / `tvpulse_export_records_status` are a *different*,
317
+ unfiltered bulk export over `/v1alpha1/exports`: gzip NDJSON, filtered only by
318
+ streams/window/program_title/commercial, with **no keyword filter**. Status polling is
319
+ billed every call and is **not refunded** on failure -- budget accordingly. Use
320
+ `tvpulse_save_evidence_csv` instead if you want a keyword-scoped CSV.
321
+ - `visual` search is never exposed by these tools (separate pilot modality/pricing);
322
+ `sources` is limited to `ocr`/`asr`.
323
+ - Raw text/voice/combined search and watches (X/news trend-card subscriptions, not TV
324
+ monitoring) are intentionally not exposed in this MCP server -- use the `tvpulse` SDK
325
+ directly if you need them.
326
+
327
+ ### Development
328
+
329
+ ```bash
330
+ uv venv --python 3.12 .venv
331
+ uv pip install -p .venv/bin/python -e ".[dev]"
332
+ .venv/bin/python -m pytest tests/ -q
333
+ .venv/bin/python -m ruff check src/ tests/
334
+ .venv/bin/python -m mypy src/
335
+ ```
336
+
337
+ The `tvpulse` SDK dependency resolves to the local `../python` package during
338
+ development via `[tool.uv.sources]` in `pyproject.toml`; the published package requires
339
+ `tvpulse>=1.0,<2`.
340
+
341
+ ### Skill install
342
+
343
+ With the Claude Code plugin (Option 1), the skill installs automatically. For manual
344
+ setup (Option 3), bilingual TV-monitoring workflow guidance (cost rules, unit warnings,
345
+ coverage limits, JST date-resolution examples) lives in
346
+ `skill/tvpulse-tv-monitoring/SKILL.md`. Install it into
347
+ `~/.claude/skills/tvpulse-tv-monitoring/` (user-wide) or
348
+ `.claude/skills/tvpulse-tv-monitoring/` (project-scoped) to have Claude load it
349
+ automatically for TV-monitoring questions.
350
+
351
+ For Claude Desktop (Option 2), upload the zip produced by
352
+ `sdks/mcp/scripts/sync-distribution.sh` at
353
+ `distribution/skill-build/tvpulse-tv-monitoring.zip` via Settings > Capabilities > Skills.
354
+
355
+ ## Troubleshooting
356
+
357
+ - **"No API key configured"**: set one via any install method (the plugin/extension
358
+ prompt at install time, or the `TVPULSE_API_KEY` env var for manual setup). Calling
359
+ `tvpulse_check_connection` shows the issuance URL and per-client setup steps.
360
+ - **"Invalid API key" / 401**: the key may be revoked or deleted. Issue a new one at
361
+ https://tvpulse.io/account/api-keys and reconfigure it. This is a distinct message from
362
+ the missing-key case.
363
+ - **`uv`/`uvx` not found**: install it from
364
+ https://docs.astral.sh/uv/getting-started/installation/. All three install methods
365
+ require `uvx`.
366
+ - **No approval prompt shown / `confirm_token` not accepted**: clients without MCP
367
+ elicitation support won't auto-prompt; a call needing approval returns
368
+ `needs_confirmation` with a `confirm_token` (single-use, 10-minute TTL) instead of
369
+ running. Review what was shown, then re-call the same tool with that `confirm_token`.
370
+ If it has expired, re-estimate and try again.