Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(persons): link persons-retrieve MCP results to the person uuid (#117923)

posthog[bot]cc8a4174cfc8
diff --git a/products/persons/mcp/tools.yaml b/products/persons/mcp/tools.yaml
index 8f2bb18c35d9..b10b256360a0 100644
--- a/products/persons/mcp/tools.yaml
+++ b/products/persons/mcp/tools.yaml
@@ -114,7 +114,7 @@ tools:
readOnly: true
destructive: false
idempotent: true
- enrich_url: '{id}'
+ enrich_url: '{uuid}'
title: Get person
description: |
Retrieve a single person by numeric ID or UUID. Returns the person's properties, distinct IDs, and metadata.
diff --git a/services/mcp/src/tools/generated/persons.ts b/services/mcp/src/tools/generated/persons.ts
index c832d9a32885..b346229dbc7a 100644
--- a/services/mcp/src/tools/generated/persons.ts
+++ b/services/mcp/src/tools/generated/persons.ts
@@ -194,7 +194,7 @@ const personsRetrieve = (): ToolBase<
'created_at',
'last_seen_at',
]) as typeof result
- return await withPostHogUrl(context, filtered, `/persons/${filtered.id}`)
+ return await withPostHogUrl(context, filtered, `/persons/${filtered.uuid}`)
},
})
diff --git a/services/mcp/tests/tools/persons.integration.test.ts b/services/mcp/tests/tools/persons.integration.test.ts
index 348a5f84bf25..291a219ab6c1 100644
--- a/services/mcp/tests/tools/persons.integration.test.ts
+++ b/services/mcp/tests/tools/persons.integration.test.ts
@@ -96,7 +96,7 @@ describe('Persons', { concurrent: false }, () => {
expect(retrieved.uuid).toBe(person.uuid)
expect(retrieved.distinct_ids).toBeTruthy()
expect(retrieved.properties).toBeTruthy()
- expect(retrieved._posthogUrl).toContain('/persons/')
+ expect(retrieved._posthogUrl).toMatch(new RegExp(`/persons/${person.uuid}$`))
})
})
diff --git a/services/mcp/tests/unit/persons-retrieve.test.ts b/services/mcp/tests/unit/persons-retrieve.test.ts
new file mode 100644
index 000000000000..8c3c4b41f227
--- /dev/null
+++ b/services/mcp/tests/unit/persons-retrieve.test.ts
@@ -0,0 +1,35 @@
+import { describe, expect, it, vi } from 'vitest'
+
+import { GENERATED_TOOLS } from '@/tools/generated/persons'
+import type { Context } from '@/tools/types'
+
+const PERSON_UUID = '0190a5b2-7c3d-7e4f-8a9b-0c1d2e3f4a5b'
+
+function createContext(request: ReturnType<typeof vi.fn>): Context {
+ return {
+ api: {
+ request,
+ getProjectBaseUrl: () => 'https://us.posthog.com/project/42',
+ },
+ stateManager: { getProjectId: vi.fn().mockResolvedValue('42') },
+ } as unknown as Context
+}
+
+describe('persons-retrieve', () => {
+ const tool = GENERATED_TOOLS['persons-retrieve']!()
+
+ it.each([
+ ['numeric id', '12345'],
+ ['uuid', PERSON_UUID],
+ ])('links to the person UUID route when looked up by %s', async (_label, id) => {
+ const request = vi.fn().mockResolvedValue({ id: 12345, uuid: PERSON_UUID, distinct_ids: ['user-1'] })
+
+ await expect(tool.handler(createContext(request), { id })).resolves.toMatchObject({
+ _posthogUrl: `https://us.posthog.com/project/42/persons/${PERSON_UUID}`,
+ })
+ expect(request).toHaveBeenCalledWith({
+ method: 'GET',
+ path: `/api/projects/42/persons/${id}/`,
+ })
+ })
+})