Add MCP Analytics support (PostHog\MCP helpers, plus a laravel/mcp integration)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 18/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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 inposthog_mcp_analyticsmakes the calls invisible with no error. - Deriving
$session_idthe 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_intentand error messages with the same rules the other SDKs apply. An agent can paste a credential into a tool argument. - The
contextintent argument: adding it to each advertised tool schema and stripping it before the tool runs. - Sending
$process_person_profile: falsefor 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/mcpintegration inposthog/posthog-laravel(aCallToolmethod subclass or a middleware), so a Laravel server opts in with one line of config.laravel/mcplets a server replace itstools/callhandler ($this->addMethod('tools/call', ...)), which is the natural hook. - A session strategy for stateless servers.
laravel/mcpruns over stateless HTTP with noMcp-Session-Id, which is the gap described in PostHog/posthog#119784. A helper that groups calls by an inactivity window keyed ondistinct_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.
- Lingua principale
- PHP
- Stelle
- 32
- Fork
- 36
- Merge medio
- 1g 18h
- PR unite (30g)
- 44
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di PostHog/posthog-php
-
Symfony SDK supportApertaenhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
PostHog/posthog-php#323 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement team/logs
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
PostHog/posthog-php#179 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 38/100
PostHog/posthog-php#172 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
PostHog/posthog-php#170 ·
I maintainer di solito rispondono entro 1 giorno
-
SDK referencesApertadocumentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 55/100
PostHog/posthog-php#145 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di PostHog/posthog-php
Issue simili
-
bug needs-triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
camunda/orchestration-cluster-api-php#162 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 65/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
TYPO3-Solr/ext-solr#4850 ·
I maintainer di solito rispondono entro 2 giorni
-
Hex viewer drops ASCII '0' after a complete rowForse già presa @palashranka l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 3 giorni
-
[Sync EN] stream: document the errors of the stream_context_*() and stream filter functions (#6091)Apertasync-en
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno