Add MCP Analytics support (PostHog\MCP helpers, plus a laravel/mcp integration)

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

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

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

評価

難易度
4/5
見積もり時間
1週間以上
初心者へのやさしさ
18/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
laravel, php
領域
analytics, backend

調査の方向性

This is a design proposal for a new PostHog\MCP namespace in the PHP SDK, not a scoped change. Start from the existing capture client in the package and the proposed MCP::captureToolCall signature, then decide the sessionId and redaction rules against the other SDKs. Done would need agreement from maintainers on the API surface and a first version covering only $mcp_tool_call.

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

説明

enhancement feature/mcp-analytics
Problem Statement

We run TryPost, an open-source social media scheduler built on Laravel. It exposes an MCP server with about 100 tools through the official laravel/mcp package, used daily from ChatGPT, Claude and Codex. We'd like to use MCP Analytics, but there is no PHP SDK for it: the install guide lists TypeScript, Python, Go, Ruby and Rust, and PHP only appears on the other languages page as "send the events yourself".

The product works the same whatever sends the events (it reads the event name and $mcp_source), so a manual capture('$mcp_tool_call', [...]) does work. What's missing is the part the other SDKs handle for you, and where mistakes are easy and silent:

  • Building the $mcp_* properties on every call ($mcp_source, $mcp_tool_name, $mcp_is_error, $mcp_error_type, $mcp_duration_ms, $mcp_server_name, client name and version, protocol version, …). A typo in posthog_mcp_analytics makes the calls invisible with no error.
  • Deriving $session_id the same way the other SDKs do (ses_ + the first 32 hex characters of a SHA-256), consistent across replicas.
  • Redacting and truncating $mcp_parameters, $mcp_response, $mcp_intent and error messages with the same rules the other SDKs apply. An agent can paste a credential into a tool argument.
  • The context intent argument: adding it to each advertised tool schema and stripping it before the tool runs.
  • Sending $process_person_profile: false for anonymous calls.

PHP is a big share of MCP servers today (Laravel ships laravel/mcp officially, and there's the official modelcontextprotocol/php-sdk for Symfony and plain PHP), so we probably aren't the only ones who read the install page and assumed the product isn't for them.

Solution Brainstorm

A PostHog\MCP namespace in this package (no new dependencies), with framework-agnostic per-call helpers, since PHP MCP servers don't share one server object to wrap. Roughly:

use PostHog\MCP;

// tools/list: optionally add the `context` intent argument (and get_more_tools)
$tools = MCP::prepareToolList($tools, context: true, reportMissing: false);

// tools/call: strip the injected argument before the tool runs
$prepared = MCP::prepareToolCall($name, $arguments);

MCP::captureToolCall(
    distinctId: $userId,
    tool: $name,
    durationMs: $durationMs,
    isError: $isError,
    errorType: 'validation',
    sessionId: MCP::sessionId($transportSessionId),
    intent: $prepared->intent,
    client: ['name' => 'claude-ai', 'version' => '1.0', 'user_agent' => $ua],
    server: ['name' => 'TryPost', 'version' => '1.0.0'],
    parameters: null, // opt-in, sanitised like the other SDKs
    groups: ['account' => $accountId],
);

Then, as follow-ups:

  • A laravel/mcp integration in posthog/posthog-laravel (a CallTool method subclass or a middleware), so a Laravel server opts in with one line of config. laravel/mcp lets a server replace its tools/call handler ($this->addMethod('tools/call', ...)), which is the natural hook.
  • A session strategy for stateless servers. laravel/mcp runs over stateless HTTP with no Mcp-Session-Id, which is the gap described in PostHog/posthog#119784. A helper that groups calls by an inactivity window keyed on distinct_id + client, without changing tool schemas or results, would cover it (the ChatGPT and Claude directories discourage telemetry ids in tool results).

A first version with $mcp_tool_call only would already unlock the dashboards, tool quality and sessions views; $mcp_tools_list, $mcp_initialize and $mcp_missing_capability could follow.

Related: PostHog/posthog-elixir#209 asks for the same helper in Elixir, and PostHog/posthog#119784 covers stateless sessions.

Happy to test a pre-release against our server.

主要言語
PHP
スター
32
フォーク
36
平均マージ
1日 18時間
マージ済み PR(30日)
44

環境構築

はじめの一歩

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

PostHog/posthog-php のほかの issue

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

似ている issue

PHP の issue をもっと見る

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

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