: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(platform): add org-member-get-github-login mcp tool (#66579)
Andrew Maguirea16039e794c5
diff --git a/posthog/api/organization_member.py b/posthog/api/organization_member.pyindex 847803d2c593..930ceb3cc15a 100644--- a/posthog/api/organization_member.py+++ b/posthog/api/organization_member.py@@ -130,6 +130,16 @@ class OrganizationMemberSerializer(SearchMatchTypeSerializerMixin, serializers.Mreturn updated_membership+class OrganizationMemberGithubLoginSerializer(serializers.Serializer):+ github_login = serializers.CharField(+ allow_null=True,+ help_text=(+ "The member's GitHub username (login), resolved from their linked GitHub integration or OAuth "+ "identity. Null when the member has no GitHub identity linked."+ ),+ )++@extend_schema(extensions={"x-product": "platform_features"})@extend_schema_view(list=extend_schema(@@ -263,6 +273,12 @@ class OrganizationMemberViewSet(instance.user.leave(organization=instance.organization)+ @extend_schema(responses=OrganizationMemberGithubLoginSerializer)+ @action(detail=True, methods=["get"], url_path="github_login", required_scopes=["organization_member:read"])+ def github_login(self, request: Request, *args: Any, **kwargs: Any) -> Response:+ instance = cast(OrganizationMembership, self.get_object())+ return Response({"github_login": instance.user.get_github_login()})+@action(detail=True, methods=["get"])def scoped_api_keys(self, request, *args, **kwargs):instance = self.get_object()diff --git a/posthog/api/test/test_organization_members.py b/posthog/api/test/test_organization_members.pyindex 8022e4756db7..ce49f912541b 100644--- a/posthog/api/test/test_organization_members.py+++ b/posthog/api/test/test_organization_members.py@@ -8,6 +8,7 @@ from django.test import override_settingsfrom django_otp.plugins.otp_totp.models import TOTPDevicefrom parameterized import parameterizedfrom rest_framework import status+from social_django.models import UserSocialAuthfrom posthog.models.organization import Organization, OrganizationMembershipfrom posthog.models.user import User@@ -93,6 +94,27 @@ class TestOrganizationMembersAPI(APIBaseTest, QueryMatchingTest):)mock_sync_delay.assert_called_once_with(str(self.organization.id))+ def test_github_login_endpoint(self):+ # A different member than the requester — proves the lookup is org-scoped, not self-only+ member = User.objects.create_and_join(self.organization, "[email protected]", None, "X")++ response = self.client.get(f"/api/organizations/@current/members/{member.uuid}/github_login/")+ self.assertEqual(response.status_code, status.HTTP_200_OK)+ self.assertEqual(response.json(), {"github_login": None})++ UserSocialAuth.objects.create(user=member, provider="github", uid="123", extra_data={"login": "octocat"})++ response = self.client.get(f"/api/organizations/@current/members/{member.uuid}/github_login/")+ self.assertEqual(response.status_code, status.HTTP_200_OK)+ self.assertEqual(response.json(), {"github_login": "octocat"})++ # `@me` resolves the requesting user via a separate branch in safely_get_object+ UserSocialAuth.objects.create(user=self.user, provider="github", uid="456", extra_data={"login": "hedgehog"})++ response = self.client.get("/api/organizations/@current/members/@me/github_login/")+ self.assertEqual(response.status_code, status.HTTP_200_OK)+ self.assertEqual(response.json(), {"github_login": "hedgehog"})+def test_scoped_api_keys_endpoint(self):# Create a user who is a member of the organizationuser = User.objects.create_and_join(self.organization, "[email protected]", None, "X")diff --git a/products/platform_features/frontend/generated/api.schemas.ts b/products/platform_features/frontend/generated/api.schemas.tsindex 6b4397178188..f72f7ab0c220 100644--- a/products/platform_features/frontend/generated/api.schemas.ts+++ b/products/platform_features/frontend/generated/api.schemas.ts@@ -342,6 +342,14 @@ export interface PatchedOrganizationMemberApi {readonly search_match_type?: SearchMatchTypeEnumApi | null}+export interface OrganizationMemberGithubLoginApi {+ /**+ * The member's GitHub username (login), resolved from their linked GitHub integration or OAuth identity. Null when the member has no GitHub identity linked.+ * @nullable+ */+ github_login: string | null+}+export interface OrganizationPersonalAPIKeyOwnerApi {/** First name of the key's owner. */readonly first_name: stringdiff --git a/products/platform_features/frontend/generated/api.ts b/products/platform_features/frontend/generated/api.tsindex 1f42ce7e4ca9..4d06bc6364ea 100644--- a/products/platform_features/frontend/generated/api.ts+++ b/products/platform_features/frontend/generated/api.ts@@ -24,6 +24,7 @@ import type {OrganizationAIAccessRequestResponseApi,OrganizationApi,OrganizationMemberApi,+ OrganizationMemberGithubLoginApi,PaginatedActivityLogListApi,PaginatedApprovalPolicyListApi,PaginatedChangeRequestListApi,@@ -253,6 +254,21 @@ export const membersDestroy = async (})}+export const getMembersGithubLoginRetrieveUrl = (organizationId: string, userUuid: string) => {+ return `/api/organizations/${organizationId}/members/${userUuid}/github_login/`+}++export const membersGithubLoginRetrieve = async (+ organizationId: string,+ userUuid: string,+ options?: RequestInit+): Promise<OrganizationMemberGithubLoginApi> => {+ return apiMutator<OrganizationMemberGithubLoginApi>(getMembersGithubLoginRetrieveUrl(organizationId, userUuid), {+ ...options,+ method: 'GET',+ })+}+export const getMembersScopedApiKeysRetrieveUrl = (organizationId: string, userUuid: string) => {return `/api/organizations/${organizationId}/members/${userUuid}/scoped_api_keys/`}diff --git a/products/platform_features/mcp/tools.yaml b/products/platform_features/mcp/tools.yamlindex a3d6e36b891b..1438063d76c1 100644--- a/products/platform_features/mcp/tools.yaml+++ b/products/platform_features/mcp/tools.yaml@@ -247,6 +247,26 @@ tools:members-update:operation: members_updateenabled: false+ org-member-get-github-login:+ operation: members_github_login_retrieve+ enabled: true+ scopes:+ - organization_member:read+ annotations:+ readOnly: true+ destructive: false+ idempotent: true+ title: Get an organization member's GitHub username.+ description: >+ Resolve the GitHub username (login) for a single organization member, given their PostHog user UUID+ (obtainable from org-members-list, or "@me" for the current user). Returns null if the member has no GitHub+ identity linked. Use this when you know which member you want and need their GitHub handle — for example to+ set suggested reviewers.+ param_overrides:+ user__uuid:+ description: |+ The PostHog user UUID of the organization member, as returned by org-members-list. Pass "@me"+ for the current user.org-members-list:operation: members_listenabled: truediff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex ea2239095d43..ea46ea3f4186 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -5383,6 +5383,20 @@"readOnlyHint": true}},+ "org-member-get-github-login": {+ "description": "Resolve the GitHub username (login) for a single organization member, given their PostHog user UUID (obtainable from org-members-list, or \"@me\" for the current user). Returns null if the member has no GitHub identity linked. Use this when you know which member you want and need their GitHub handle — for example to set suggested reviewers.",+ "category": "Platform Features",+ "feature": "platform_features",+ "summary": "Get an organization member's GitHub username.",+ "title": "Get an organization member's GitHub username.",+ "required_scopes": ["organization_member:read"],+ "annotations": {+ "destructiveHint": false,+ "idempotentHint": true,+ "openWorldHint": true,+ "readOnlyHint": true+ }+ },"org-members-list": {"description": "List all members of the current organization with their names, emails, membership levels (member, admin, owner), and last login times.","category": "Platform Features",diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex 55b98adc14ef..a7f7bef696b2 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -5834,6 +5834,20 @@"readOnlyHint": true}},+ "org-member-get-github-login": {+ "description": "Resolve the GitHub username (login) for a single organization member, given their PostHog user UUID (obtainable from org-members-list, or \"@me\" for the current user). Returns null if the member has no GitHub identity linked. Use this when you know which member you want and need their GitHub handle — for example to set suggested reviewers.",+ "category": "Platform Features",+ "feature": "platform_features",+ "summary": "Get an organization member's GitHub username.",+ "title": "Get an organization member's GitHub username.",+ "required_scopes": ["organization_member:read"],+ "annotations": {+ "destructiveHint": false,+ "idempotentHint": true,+ "openWorldHint": true,+ "readOnlyHint": true+ }+ },"org-members-list": {"description": "List all members of the current organization with their names, emails, membership levels (member, admin, owner), and last login times.","category": "Platform Features",diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 4d0d0d910616..72850411d28a 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -30439,6 +30439,14 @@ export namespace Schemas {readonly search_match_type: SearchMatchTypeEnum | null;}+ export interface OrganizationMemberGithubLogin {+ /**+ * The member's GitHub username (login), resolved from their linked GitHub integration or OAuth identity. Null when the member has no GitHub identity linked.+ * @nullable+ */+ github_login: string | null;+ }+/*** Serializer for organization-scoped OAuth applications (read-only).*/diff --git a/services/mcp/src/generated/platform_features/api.ts b/services/mcp/src/generated/platform_features/api.tsindex 047915c0927a..c9460d753f81 100644--- a/services/mcp/src/generated/platform_features/api.ts+++ b/services/mcp/src/generated/platform_features/api.ts@@ -3,7 +3,7 @@* MCP service uses these Zod schemas for generated tool handlers.* To regenerate: hogli build:openapi*- * PostHog API - MCP 19 enabled ops+ * PostHog API - MCP 20 enabled ops* OpenAPI spec version: 1.0.0*/import * as zod from 'zod'@@ -37,6 +37,15 @@ export const MembersListQueryParams = /* @__PURE__ */ zod.object({),})+export const MembersGithubLoginRetrieveParams = /* @__PURE__ */ zod.object({+ organization_id: zod+ .string()+ .describe(+ "ID of the organization you're trying to access. To find the ID of the organization, make a call to /api/organizations/."+ ),+ user__uuid: zod.string(),+})+export const RolesListParams = /* @__PURE__ */ zod.object({organization_id: zod.string()diff --git a/services/mcp/src/tools/generated/platform_features.ts b/services/mcp/src/tools/generated/platform_features.tsindex b2566883e971..c24b9ce8e1db 100644--- a/services/mcp/src/tools/generated/platform_features.ts+++ b/services/mcp/src/tools/generated/platform_features.ts@@ -13,6 +13,7 @@ import {CommentsRetrieveParams,CommentsThreadRetrieveParams,ListQueryParams,+ MembersGithubLoginRetrieveParams,MembersListQueryParams,RetrieveParams,RolesListQueryParams,@@ -297,6 +298,28 @@ const commentsList = (): ToolBase<typeof CommentsListSchema, Schemas.PaginatedCo},})+const OrgMemberGetGithubLoginSchema = MembersGithubLoginRetrieveParams.omit({ organization_id: true }).extend({+ user__uuid: MembersGithubLoginRetrieveParams.shape['user__uuid'].describe(+ 'The PostHog user UUID of the organization member, as returned by org-members-list. Pass "@me" for the current user.'+ ),+})++const orgMemberGetGithubLogin = (): ToolBase<+ typeof OrgMemberGetGithubLoginSchema,+ Schemas.OrganizationMemberGithubLogin+> => ({+ name: 'org-member-get-github-login',+ schema: OrgMemberGetGithubLoginSchema,+ handler: async (context: Context, params: z.infer<typeof OrgMemberGetGithubLoginSchema>) => {+ const orgId = await context.stateManager.getOrgID()+ const result = await context.api.request<Schemas.OrganizationMemberGithubLogin>({+ method: 'GET',+ path: `/api/organizations/${encodeURIComponent(String(orgId))}/members/${encodeURIComponent(String(params.user__uuid))}/github_login/`,+ })+ return result+ },+})+const OrgMembersListSchema = MembersListQueryParamsconst orgMembersList = (): ToolBase<typeof OrgMembersListSchema, Schemas.PaginatedOrganizationMemberList> => ({@@ -492,6 +515,7 @@ export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {'comment-get': commentGet,'comment-thread': commentThread,'comments-list': commentsList,+ 'org-member-get-github-login': orgMemberGetGithubLogin,'org-members-list': orgMembersList,'organization-get': organizationGet,'organizations-list': organizationsList,diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/org-member-get-github-login.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/org-member-get-github-login.jsonnew file mode 100644index 000000000000..81f58c62b81e--- /dev/null+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/org-member-get-github-login.json@@ -0,0 +1,11 @@+{+ "$schema": "https://json-schema.org/draft/2020-12/schema",+ "properties": {+ "user__uuid": {+ "description": "The PostHog user UUID of the organization member, as returned by org-members-list. Pass \"@me\" for the current user.",+ "type": "string"+ }+ },+ "required": ["user__uuid"],+ "type": "object"+}