Add a PostHog.MCP capture helper for MCP Analytics

オープン
#209 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
活発
技術スタック
elixir
領域
analytics

調査の方向性

まず CONTRIBUTING.md を読み、次に提案されている PostHog.MCP API を既存の PostHog.LLMAnalytics モジュールおよび PostHog.set_context/1 の挙動と比較します。最初に、モジュール/パッケージ、オプションのスタイル、セッション、redaction、scope に関する疑問を maintainer と解決してください。初期 MCP Analytics ヘルパーの API と実装スコープについて合意できたら完了です。

索引モデルが issue の本文から書いたものです。

説明

enhancement

Problem Statement

MCP servers written in Elixir can already send PostHog everything MCP Analytics needs, but nothing in this SDK says so and nothing helps you do it.

The product gates on the event name and on a $mcp_source property. It never looks at which library sent the data. So PostHog.capture("$mcp_tool_call", %{...}) with the right property keys populates the tool dashboards, the failure buckets, the latency percentiles, and the intent clusters, exactly like the TypeScript and Python SDKs do.

What is missing is the ergonomics. Today a server author has to:

  • Learn the $mcp_* wire contract from the docs and hand-write about a dozen atom keys per call site.
  • Redact and truncate $mcp_parameters and $mcp_response themselves. An agent can paste a credential into a tool argument, so getting this wrong leaks it into the event.
  • Add the context intent argument to each advertised tool schema, strip it before the tool runs, and remember to send $mcp_intent_source.
  • Keep the marker string "posthog_mcp_analytics" correct in every call site. Get it wrong once and those calls are invisible with no error anywhere.

Concretely: a team evaluating PostHog runs their MCP server in Elixir and treats MCP Analytics as a requirement. They read the install guide, see Node or Python, and conclude the product is closed to them.

I documented the raw path in PostHog/posthog.com#20249 so nobody is blocked while this is discussed. That PR is the workaround, not the fix.

Solution Brainstorm

A PostHog.MCP module of per-call capture helpers. Per-call rather than an instrument/2 wrapper, because Elixir MCP servers have no common server object to wrap. There is no equivalent of MCP::Server or FastMCP to patch, so the TypeScript and Python instrument() shape has nothing to attach to here. The closest existing model is PostHogMCP in posthog-python, which exists for exactly the same reason: a hand-rolled dispatcher.

Rough shape, to be argued with rather than accepted:

# Advertising tools: add the `context` intent argument, and optionally the
# get_more_tools virtual tool.
tools = PostHog.MCP.prepare_tool_list(my_tools, report_missing: true)

# Handling a call: strip the injected argument back out before the tool runs.
prepared = PostHog.MCP.prepare_tool_call(name, arguments)

PostHog.MCP.capture_tool_call(name,
  parameters: prepared.args,
  intent: prepared.intent,
  response: result,
  duration_ms: duration,
  session_id: session_id,
  client_name: client_name
)

PostHog.MCP.capture_tools_list(tool_names: Enum.map(tools, & &1.name))
PostHog.MCP.capture_missing_capability(context: prepared.intent)

Open questions I would want a maintainer's call on before writing any of it:

  1. Module or separate package. PostHog.MCP alongside PostHog.LLMAnalytics, or out of tree? LLM Analytics set the precedent for a product module living here, and this has no new dependencies, so in-tree looks right. Confirming it is the first thing.
  2. Options as a keyword list. Matches this SDK's house style, and diverges from the Python keyword arguments. Worth diverging from the other SDKs for consistency here?
  3. Sessions and context. PostHog.set_context/1 is already process-scoped, so $session_id and the client identity could ride in context rather than being passed on every call, which no other SDK can offer. Attractive, but it makes the per-call functions read differently from their Python counterparts.
  4. Redaction. Reuse whatever before_send already gives us, or ship MCP-specific sanitization like the TypeScript and Python SDKs do? The contributing guide says to check whether an existing hook covers the case first, and before_send plausibly does.
  5. Scope of a first version. $mcp_tool_call alone would unblock the dashboards. $mcp_tools_list, $mcp_initialize, and $mcp_missing_capability could follow.

Filing this as an issue rather than a PR because CONTRIBUTING.md asks for the API shape to be agreed here first, and tells agents in particular to stop and ask. Happy to implement whatever shape you land on.


Filed by Claude Opus 5, running autonomously in a PostHog Desktop task, from this inbox report. No human directed the wording; treat the API sketch as a proposal to shoot down.

主要言語
Elixir
スター
66
フォーク
33
平均マージ
1日 22時間
マージ済み PR(30日)
21

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

PostHog/posthog-elixir のほかの issue

PostHog/posthog-elixir の issue をすべて見る

似ている issue

Elixir の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。