Skip to content

Commit 9384b82

Browse files
committed
feat(github): enhance user activity query documentation for authenticated user access
1 parent ce79d53 commit 9384b82

File tree

1 file changed

+88
-4
lines changed

1 file changed

+88
-4
lines changed

src/mcp_github/github_integration.py

Lines changed: 88 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -668,12 +668,96 @@ def create_release(self, repo_owner: str, repo_name: str, tag_name: str, release
668668

669669
def user_activity_query(self, variables: dict[str, Any], query: str) -> Dict[str, Any]:
670670
"""
671-
Performs a user activity query using GitHub's GraphQL API across all repositories and organisations.
671+
Performs a user activity query using GitHub's GraphQL API for the authenticated user (token owner).
672+
673+
**Important**: To query private organization activities, the query MUST use the `viewer` field
674+
instead of `user(login:)`. The `viewer` field returns data for the authenticated user (token owner)
675+
and includes all private contributions and organization activities.
676+
677+
**Query Requirements**:
678+
- Use `viewer { ... }` to query the authenticated user's activity
679+
- Do NOT use `user(login: "username") { ... }` as it only shows public contributions
680+
- The `viewer` query automatically includes private repositories and organizations
681+
682+
**Example Query Structure**:
683+
```graphql
684+
query($from: DateTime!, $to: DateTime!) {
685+
viewer {
686+
login
687+
contributionsCollection(from: $from, to: $to) {
688+
commitContributionsByRepository(maxRepositories: 100) {
689+
repository {
690+
name
691+
isPrivate
692+
owner {
693+
login
694+
... on Organization {
695+
login
696+
}
697+
}
698+
}
699+
contributions {
700+
totalCount
701+
}
702+
}
703+
pullRequestContributionsByRepository(maxRepositories: 100) {
704+
repository {
705+
name
706+
isPrivate
707+
owner {
708+
login
709+
}
710+
}
711+
contributions {
712+
totalCount
713+
}
714+
}
715+
issueContributionsByRepository(maxRepositories: 100) {
716+
repository {
717+
name
718+
isPrivate
719+
owner {
720+
login
721+
}
722+
}
723+
contributions {
724+
totalCount
725+
}
726+
}
727+
pullRequestReviewContributionsByRepository(maxRepositories: 100) {
728+
repository {
729+
name
730+
isPrivate
731+
owner {
732+
login
733+
}
734+
}
735+
contributions {
736+
totalCount
737+
}
738+
}
739+
}
740+
organizations(first: 100) {
741+
nodes {
742+
login
743+
viewerCanAdminister
744+
}
745+
}
746+
}
747+
}
748+
```
749+
672750
Args:
673-
variables (dict[str, Any]): The variables to include in the query i.e. {"login": "username", "from": "2023-01-01", "to": "2023-12-31"}.
674-
query (str): The search query string. GitHub GraphQL query summary collection that includes all activity across all orgs, public and private.
751+
variables (dict[str, Any]): Query variables. For authenticated user queries, only include:
752+
- "from": Start date in ISO 8601 format (e.g., "2024-10-01T00:00:00Z")
753+
- "to": End date in ISO 8601 format (e.g., "2024-10-31T23:59:59Z")
754+
Do NOT include "login" variable when using `viewer`.
755+
query (str): GraphQL query string. Must use `viewer` field to access authenticated user's
756+
private activities across all organizations.
757+
675758
Returns:
676-
Dict[str, Any]: The JSON response from the GitHub API containing search results if successful.
759+
Dict[str, Any]: The JSON response from GitHub's GraphQL API containing the authenticated
760+
user's activity data, including private repositories and organizations.
677761
"""
678762
logging.info("Performing user query on GitHub")
679763

0 commit comments

Comments
 (0)