From b44f19669156eae40815265331f52731bfa457bb Mon Sep 17 00:00:00 2001
From: kaii9 <107882135+kaii9@users.noreply.github.com>
Date: Fri, 9 Oct 2026 02:37:12 +0800
Subject: [PATCH 1/3] feat: list user activity events
---
README.md | 6 +
.../__toolsnaps__/list_user_events.snap | 32 ++
.../list_user_events_output.snap | 45 +++
pkg/github/tools.go | 1 +
pkg/github/users.go | 150 +++++++++
pkg/github/users_test.go | 293 ++++++++++++++++++
6 files changed, 527 insertions(+)
create mode 100644 pkg/github/__toolsnaps__/list_user_events.snap
create mode 100644 pkg/github/__toolsnaps__/list_user_events_output.snap
create mode 100644 pkg/github/users.go
create mode 100644 pkg/github/users_test.go
diff --git a/README.md b/README.md
index 6413b58760..d14f633996 100644
--- a/README.md
+++ b/README.md
@@ -1628,6 +1628,12 @@ For negotiated supported protocol versions `2026-07-28` or newer, the consolidat
Users
+- **list_user_events** - List user activity
+ - **OAuth Challenge Scopes**: `repo`
+ - `page`: Page number for pagination (min 1) (integer, optional)
+ - `perPage`: Results per page for pagination (min 1, max 100) (integer, optional)
+ - `username`: GitHub username whose activity to list (string, required)
+
- **search_users** - Search users
- **OAuth Challenge Scopes**: `repo`
- `order`: Sort order (string, optional)
diff --git a/pkg/github/__toolsnaps__/list_user_events.snap b/pkg/github/__toolsnaps__/list_user_events.snap
new file mode 100644
index 0000000000..7f7ae0c704
--- /dev/null
+++ b/pkg/github/__toolsnaps__/list_user_events.snap
@@ -0,0 +1,32 @@
+{
+ "annotations": {
+ "idempotentHint": false,
+ "readOnlyHint": true,
+ "title": "List user activity"
+ },
+ "description": "List recent GitHub activity performed by a user, such as pushes, pull requests, issues, and stars. GitHub returns public events for other users and may include private events when querying the authenticated user's own activity, subject to token permissions. Returns event metadata, visibility, and event-specific payloads. GitHub limits the feed to up to 300 events from the past 30 days; events may be delayed from 30 seconds to 6 hours. This is not a complete or real-time contribution history.",
+ "inputSchema": {
+ "properties": {
+ "page": {
+ "description": "Page number for pagination (min 1)",
+ "minimum": 1,
+ "type": "integer"
+ },
+ "perPage": {
+ "description": "Results per page for pagination (min 1, max 100)",
+ "maximum": 100,
+ "minimum": 1,
+ "type": "integer"
+ },
+ "username": {
+ "description": "GitHub username whose activity to list",
+ "type": "string"
+ }
+ },
+ "required": [
+ "username"
+ ],
+ "type": "object"
+ },
+ "name": "list_user_events"
+}
\ No newline at end of file
diff --git a/pkg/github/__toolsnaps__/list_user_events_output.snap b/pkg/github/__toolsnaps__/list_user_events_output.snap
new file mode 100644
index 0000000000..0627aa0fa6
--- /dev/null
+++ b/pkg/github/__toolsnaps__/list_user_events_output.snap
@@ -0,0 +1,45 @@
+{
+ "inputSchema": null,
+ "name": "list_user_events",
+ "outputSchema": {
+ "items": {
+ "additionalProperties": false,
+ "properties": {
+ "actor": {
+ "type": "string"
+ },
+ "created_at": {
+ "type": [
+ "null",
+ "string"
+ ]
+ },
+ "id": {
+ "type": "string"
+ },
+ "payload": true,
+ "public": {
+ "type": [
+ "null",
+ "boolean"
+ ]
+ },
+ "repo": {
+ "type": "string"
+ },
+ "type": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "id",
+ "type"
+ ],
+ "type": "object"
+ },
+ "type": [
+ "null",
+ "array"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/pkg/github/tools.go b/pkg/github/tools.go
index 53503f68fe..dff7c92d1b 100644
--- a/pkg/github/tools.go
+++ b/pkg/github/tools.go
@@ -267,6 +267,7 @@ func AllTools(t translations.TranslationHelperFunc, opts ...ToolOption) []invent
// User tools
SearchUsers(t),
+ ListUserEvents(t),
// Organization tools
SearchOrgs(t),
diff --git a/pkg/github/users.go b/pkg/github/users.go
new file mode 100644
index 0000000000..8ed4308250
--- /dev/null
+++ b/pkg/github/users.go
@@ -0,0 +1,150 @@
+package github
+
+import (
+ "bytes"
+ "context"
+ "encoding/json"
+ "net/url"
+ "time"
+
+ ghErrors "github.com/github/github-mcp-server/v2/pkg/errors"
+ "github.com/github/github-mcp-server/v2/pkg/ifc"
+ "github.com/github/github-mcp-server/v2/pkg/inventory"
+ "github.com/github/github-mcp-server/v2/pkg/sanitize"
+ "github.com/github/github-mcp-server/v2/pkg/scopes"
+ "github.com/github/github-mcp-server/v2/pkg/translations"
+ "github.com/github/github-mcp-server/v2/pkg/utils"
+ "github.com/google/go-github/v92/github"
+ "github.com/google/jsonschema-go/jsonschema"
+ "github.com/modelcontextprotocol/go-sdk/mcp"
+)
+
+// MinimalUserEvent retains event-specific data without repeated user and repository metadata.
+type MinimalUserEvent struct {
+ ID string `json:"id"`
+ Type string `json:"type"`
+ Public *bool `json:"public,omitempty"`
+ Actor string `json:"actor,omitempty"`
+ Repo string `json:"repo,omitempty"`
+ CreatedAt *time.Time `json:"created_at,omitempty"`
+ Payload any `json:"payload,omitempty"`
+}
+
+type ListUserEventsInput struct {
+ Username string `json:"username"`
+ Page *int `json:"page,omitempty"`
+ PerPage *int `json:"perPage,omitempty"`
+}
+
+// ListUserEvents creates a read-only tool for activity visible to the current GitHub credentials.
+func ListUserEvents(t translations.TranslationHelperFunc) inventory.ServerTool {
+ schema := WithPagination(&jsonschema.Schema{
+ Type: "object",
+ Properties: map[string]*jsonschema.Schema{
+ "username": {
+ Type: "string",
+ Description: "GitHub username whose activity to list",
+ },
+ },
+ Required: []string{"username"},
+ })
+ schema.Properties["page"].Type = "integer"
+ schema.Properties["perPage"].Type = "integer"
+ return NewTool[ListUserEventsInput, []MinimalUserEvent](
+ ToolsetMetadataUsers,
+ mcp.Tool{
+ Name: "list_user_events",
+ Description: t("TOOL_LIST_USER_EVENTS_DESCRIPTION", "List recent GitHub activity performed by a user, such as pushes, pull requests, issues, and stars. GitHub returns public events for other users and may include private events when querying the authenticated user's own activity, subject to token permissions. Returns event metadata, visibility, and event-specific payloads. GitHub limits the feed to up to 300 events from the past 30 days; events may be delayed from 30 seconds to 6 hours. This is not a complete or real-time contribution history."),
+ Annotations: &mcp.ToolAnnotations{
+ Title: t("TOOL_LIST_USER_EVENTS_USER_TITLE", "List user activity"),
+ ReadOnlyHint: true,
+ },
+ InputSchema: schema,
+ },
+ scopes.PublicRead(scopes.Repo),
+ func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, input ListUserEventsInput) (*mcp.CallToolResult, []MinimalUserEvent, error) {
+ if input.Username == "" {
+ return utils.NewToolResultError("missing required parameter: username"), nil, nil
+ }
+ page, perPage := 1, 30
+ if input.Page != nil {
+ page = *input.Page
+ }
+ if input.PerPage != nil {
+ perPage = *input.PerPage
+ }
+ if page < 1 {
+ return utils.NewToolResultError("page must be at least 1"), nil, nil
+ }
+ if perPage < 1 || perPage > 100 {
+ return utils.NewToolResultError("perPage must be between 1 and 100"), nil, nil
+ }
+
+ client, err := deps.GetClient(ctx)
+ if err != nil {
+ return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil, nil
+ }
+ events, resp, err := client.Activity.ListEventsPerformedByUser(ctx, url.PathEscape(input.Username), false, &github.ListOptions{
+ Page: page, PerPage: perPage,
+ })
+ if err != nil {
+ return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to list user events", resp, err), nil, nil
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ minimalEvents := make([]MinimalUserEvent, 0, len(events))
+ label := ifc.PublicUntrusted()
+ for _, event := range events {
+ if event == nil {
+ continue
+ }
+ // Missing visibility is conservatively private. A mixed page may
+ // also contain untrusted public content, so integrity stays untrusted.
+ if !event.GetPublic() {
+ label = ifc.PrivateUntrusted()
+ }
+ var payload any
+ if raw := event.GetRawPayload(); len(raw) > 0 {
+ decoder := json.NewDecoder(bytes.NewReader(raw))
+ // Event payloads can contain IDs larger than float64's exact integer range.
+ decoder.UseNumber()
+ if err := decoder.Decode(&payload); err != nil {
+ return utils.NewToolResultErrorFromErr("failed to decode event payload", err), nil, nil
+ }
+ payload = sanitizeUserEventPayload(payload)
+ }
+ var createdAt *time.Time
+ if event.CreatedAt != nil {
+ createdAt = &event.CreatedAt.Time
+ }
+ minimalEvents = append(minimalEvents, MinimalUserEvent{
+ ID: event.GetID(), Type: event.GetType(), Public: event.Public,
+ Actor: event.Actor.GetLogin(), Repo: event.Repo.GetName(),
+ CreatedAt: createdAt, Payload: payload,
+ })
+ }
+ result := MarshalledTextResult(minimalEvents)
+ return attachStaticIFCLabel(ctx, deps, result, label), minimalEvents, nil
+ },
+ )
+}
+
+// Payloads vary by event type. Preserve unknown fields while filtering user-authored text.
+func sanitizeUserEventPayload(value any) any {
+ switch value := value.(type) {
+ case string:
+ return sanitize.Content(value)
+ case map[string]any:
+ for key, item := range value {
+ value[key] = sanitizeUserEventPayload(item)
+ }
+ return value
+ case []any:
+ for i, item := range value {
+ value[i] = sanitizeUserEventPayload(item)
+ }
+ return value
+ default:
+ return value
+ }
+}
diff --git a/pkg/github/users_test.go b/pkg/github/users_test.go
new file mode 100644
index 0000000000..b3c01b7403
--- /dev/null
+++ b/pkg/github/users_test.go
@@ -0,0 +1,293 @@
+package github
+
+import (
+ "context"
+ "encoding/json"
+ "net/http"
+ "testing"
+
+ "github.com/github/github-mcp-server/v2/internal/toolsnaps"
+ "github.com/github/github-mcp-server/v2/pkg/inventory"
+ "github.com/github/github-mcp-server/v2/pkg/translations"
+ "github.com/google/jsonschema-go/jsonschema"
+ "github.com/modelcontextprotocol/go-sdk/mcp"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+func userEventsTool(t *testing.T) inventory.ServerTool {
+ t.Helper()
+ for _, tool := range AllTools(translations.NullTranslationHelper) {
+ if tool.Tool.Name == "list_user_events" {
+ return tool
+ }
+ }
+ t.Fatal("list_user_events is missing from the tool inventory")
+ return inventory.ServerTool{}
+}
+
+func Test_ListUserEvents(t *testing.T) {
+ t.Parallel()
+ tool := userEventsTool(t)
+ require.Equal(t, ToolsetMetadataUsers.ID, tool.Toolset.ID)
+ require.True(t, tool.IsReadOnly())
+ require.NoError(t, toolsnaps.Test(tool.Tool.Name, tool.Tool))
+
+ tests := []struct {
+ name string
+ args map[string]any
+ page string
+ perPage string
+ status int
+ response string
+ want string
+ wantErr string
+ }{
+ {
+ name: "public events retain payloads and exact IDs with minimal metadata",
+ args: map[string]any{"username": "octocat"}, page: "1", perPage: "30", status: http.StatusOK,
+ response: `[{"id":"1","type":"PushEvent","public":true,"actor":{"login":"octocat","avatar_url":"https://example.com/avatar"},"repo":{"name":"octo-org/demo","url":"https://api.github.com/repos/octo-org/demo"},"created_at":"2026-10-01T12:00:00Z","payload":{"ref":"refs/heads/main","head":"abc123","push_id":9007199254740993}}, {"id":"2","type":"FutureEvent","public":true,"actor":{"login":"octocat"},"repo":{"name":"octo-org/demo"},"payload":{"comment":{"body":"Hello\u202e world"},"items":[{"text":"a\u200bb"}]}}]`,
+ want: `[{"id":"1","type":"PushEvent","public":true,"actor":"octocat","repo":"octo-org/demo","created_at":"2026-10-01T12:00:00Z","payload":{"ref":"refs/heads/main","head":"abc123","push_id":9007199254740993}}, {"id":"2","type":"FutureEvent","public":true,"actor":"octocat","repo":"octo-org/demo","payload":{"comment":{"body":"Hello world"},"items":[{"text":"ab"}]}}]`,
+ },
+ {
+ name: "private events returned by GitHub are retained",
+ args: map[string]any{"username": "octocat"}, page: "1", perPage: "30", status: http.StatusOK,
+ response: `[{"id":"4","type":"PushEvent","public":false,"actor":{"login":"octocat"},"repo":{"name":"octo-org/private"},"payload":{"ref":"refs/heads/main"}}]`,
+ want: `[{"id":"4","type":"PushEvent","public":false,"actor":"octocat","repo":"octo-org/private","payload":{"ref":"refs/heads/main"}}]`,
+ },
+ {
+ name: "explicit pagination reaches GitHub",
+ args: map[string]any{"username": "octocat", "page": 3, "perPage": 100}, page: "3", perPage: "100", status: http.StatusOK,
+ response: `[]`, want: `[]`,
+ },
+ {
+ name: "empty feed returns an array",
+ args: map[string]any{"username": "octocat"}, page: "1", perPage: "30", status: http.StatusOK,
+ response: `[]`, want: `[]`,
+ },
+ {
+ name: "optional event fields may be absent",
+ args: map[string]any{"username": "octocat"}, page: "1", perPage: "30", status: http.StatusOK,
+ response: `[{"id":"3","type":"WatchEvent","payload":null}]`, want: `[{"id":"3","type":"WatchEvent"}]`,
+ },
+ {
+ name: "unknown user surfaces API error",
+ args: map[string]any{"username": "octocat"}, page: "1", perPage: "30", status: http.StatusNotFound,
+ response: `{"message":"Not Found"}`, wantErr: "Not Found",
+ },
+ {
+ name: "rate limit surfaces API error",
+ args: map[string]any{"username": "octocat"}, page: "1", perPage: "30", status: http.StatusForbidden,
+ response: `{"message":"API rate limit exceeded"}`, wantErr: "API rate limit exceeded",
+ },
+ }
+ for _, tc := range tests {
+ t.Run(tc.name, func(t *testing.T) {
+ client := MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
+ "GET /users/octocat/events": func(w http.ResponseWriter, r *http.Request) {
+ assert.Equal(t, tc.page, r.URL.Query().Get("page"))
+ assert.Equal(t, tc.perPage, r.URL.Query().Get("per_page"))
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(tc.status)
+ _, _ = w.Write([]byte(tc.response))
+ },
+ })
+ deps := BaseDeps{Client: mustNewGHClient(t, client), Obsv: stubExporters()}
+ request := createMCPRequest(tc.args)
+ result, err := tool.Handler(deps)(ContextWithDeps(t.Context(), deps), &request)
+ require.NoError(t, err)
+ if tc.wantErr != "" {
+ require.True(t, result.IsError)
+ assert.Contains(t, getErrorResult(t, result).Text, tc.wantErr)
+ return
+ }
+ require.False(t, result.IsError)
+ text := getTextResult(t, result).Text
+ assert.JSONEq(t, tc.want, text)
+ if tc.name == "public events retain payloads and exact IDs with minimal metadata" {
+ // JSONEq decodes numbers as float64, so also check the large ID literally.
+ assert.Contains(t, text, `9007199254740993`)
+ }
+ })
+ }
+}
+
+func Test_ListUserEvents_InvalidArguments(t *testing.T) {
+ t.Parallel()
+ tool := userEventsTool(t)
+ tests := []struct {
+ name string
+ args map[string]any
+ want string
+ }{
+ {"missing username", map[string]any{}, "username"},
+ {"empty username", map[string]any{"username": ""}, "username"},
+ {"wrong username type", map[string]any{"username": 42}, "username"},
+ {"page below minimum", map[string]any{"username": "octocat", "page": 0}, "page"},
+ {"perPage below minimum", map[string]any{"username": "octocat", "perPage": 0}, "perPage"},
+ {"perPage above maximum", map[string]any{"username": "octocat", "perPage": 101}, "perPage"},
+ {"fractional page", map[string]any{"username": "octocat", "page": 1.5}, "page"},
+ }
+ for _, tc := range tests {
+ t.Run(tc.name, func(t *testing.T) {
+ client := MockHTTPClientWithHandler(func(_ http.ResponseWriter, _ *http.Request) {
+ t.Fatal("invalid arguments must not send an API request")
+ })
+ deps := BaseDeps{Client: mustNewGHClient(t, client), Obsv: stubExporters()}
+ request := createMCPRequest(tc.args)
+ result, err := tool.Handler(deps)(ContextWithDeps(t.Context(), deps), &request)
+ require.NoError(t, err)
+ require.True(t, result.IsError)
+ assert.Contains(t, getErrorResult(t, result).Text, tc.want)
+ })
+ }
+}
+
+func Test_ListUserEvents_ClientError(t *testing.T) {
+ t.Parallel()
+ tool := userEventsTool(t)
+ deps := stubDeps{clientFn: stubClientFnErr("client unavailable"), obsv: stubExporters()}
+ request := createMCPRequest(map[string]any{"username": "octocat"})
+ result, err := tool.Handler(deps)(ContextWithDeps(t.Context(), deps), &request)
+ require.NoError(t, err)
+ require.True(t, result.IsError)
+ assert.Contains(t, getErrorResult(t, result).Text, "client unavailable")
+}
+
+func Test_ListUserEvents_AdvertisedPagination(t *testing.T) {
+ t.Parallel()
+ tool := userEventsTool(t)
+ var schema jsonschema.Schema
+ require.NoError(t, json.Unmarshal([]byte(mustMarshalJSON(t, tool.Tool.InputSchema)), &schema))
+ resolved, err := schema.Resolve(nil)
+ require.NoError(t, err)
+ require.NoError(t, resolved.Validate(map[string]any{"username": "octocat", "page": 2, "perPage": 5}))
+ for _, args := range []map[string]any{
+ {"username": "octocat", "page": 1.5},
+ {"username": "octocat", "perPage": 2.5},
+ } {
+ require.Error(t, resolved.Validate(args), "advertised schema must reject fractional pagination")
+ }
+}
+
+func Test_ListUserEvents_IFC(t *testing.T) {
+ t.Parallel()
+ tool := userEventsTool(t)
+ for _, tc := range []struct{ name, response, confidentiality string }{
+ {"empty feed", `[]`, "public"},
+ {"public feed", `[{"id":"1","type":"WatchEvent","public":true}]`, "public"},
+ {"private feed", `[{"id":"2","type":"PushEvent","public":false}]`, "private"},
+ {"mixed feed", `[{"id":"1","type":"WatchEvent","public":true},{"id":"2","type":"PushEvent","public":false}]`, "private"},
+ {"missing visibility", `[{"id":"3","type":"FutureEvent"}]`, "private"},
+ {"null visibility", `[{"id":"3","type":"FutureEvent","public":null}]`, "private"},
+ {"null event", `[null,{"id":"1","type":"WatchEvent","public":true}]`, "public"},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ client := MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
+ "GET /users/octocat/events": func(w http.ResponseWriter, _ *http.Request) {
+ _, _ = w.Write([]byte(tc.response))
+ },
+ })
+ deps := NewBaseDeps(mustNewGHClient(t, client), nil, nil, nil,
+ translations.NullTranslationHelper, FeatureFlags{}, 0,
+ func(_ context.Context, flag string) (bool, error) {
+ return flag == FeatureFlagIFCLabels, nil
+ }, stubExporters())
+ request := createMCPRequest(map[string]any{"username": "octocat"})
+ result, err := tool.Handler(deps)(ContextWithDeps(t.Context(), deps), &request)
+ require.NoError(t, err)
+ require.False(t, result.IsError, result)
+ label, err := json.Marshal(result.Meta["ifc"])
+ require.NoError(t, err)
+ assert.JSONEq(t, `{"integrity":"untrusted","confidentiality":"`+tc.confidentiality+`"}`, string(label))
+ })
+ }
+}
+
+func Test_ListUserEvents_Protocols(t *testing.T) {
+ t.Parallel()
+ for _, protocol := range []string{"2025-11-25", inventory.ProtocolVersionMultiRoundTrip} {
+ t.Run(protocol, func(t *testing.T) {
+ tool := userEventsTool(t)
+ response := `[{"id":"1","type":"FutureEvent","public":true,"actor":{"login":"octocat"},"repo":{"name":"octo-org/demo"},"created_at":"2026-10-01T12:00:00Z","payload":{"id":9007199254740993,"text":"a\u200bb"}}]`
+ status := http.StatusOK
+ calls := 0
+ client := MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
+ "GET /users/octocat/events": func(w http.ResponseWriter, r *http.Request) {
+ calls++
+ assert.Equal(t, "1", r.URL.Query().Get("page"))
+ assert.Equal(t, "30", r.URL.Query().Get("per_page"))
+ w.WriteHeader(status)
+ _, _ = w.Write([]byte(response))
+ },
+ })
+ deps := BaseDeps{Client: mustNewGHClient(t, client), Obsv: stubExporters()}
+ session := connectTypedSearchClient(t, tool, deps, protocol)
+ listed, err := session.ListTools(t.Context(), nil)
+ require.NoError(t, err)
+ require.Len(t, listed.Tools, 1)
+ var outputSchema *jsonschema.Resolved
+ if protocol == inventory.ProtocolVersionMultiRoundTrip {
+ require.NotNil(t, listed.Tools[0].OutputSchema, "modern clients need a typed output schema")
+ require.NoError(t, toolsnaps.Test(tool.Tool.Name+"_output", mcp.Tool{
+ Name: tool.Tool.Name, OutputSchema: listed.Tools[0].OutputSchema,
+ }))
+ var schema jsonschema.Schema
+ require.NoError(t, json.Unmarshal([]byte(mustMarshalJSON(t, listed.Tools[0].OutputSchema)), &schema))
+ outputSchema, err = schema.Resolve(nil)
+ require.NoError(t, err)
+ } else {
+ assert.Nil(t, listed.Tools[0].OutputSchema)
+ }
+ args := &mcp.CallToolParams{Name: tool.Tool.Name, Arguments: map[string]any{"username": "octocat"}}
+ result, err := session.CallTool(t.Context(), args)
+ require.NoError(t, err)
+ require.False(t, result.IsError, result)
+ text := getTextResult(t, result).Text
+ assert.JSONEq(t, `[{"id":"1","type":"FutureEvent","public":true,"actor":"octocat","repo":"octo-org/demo","created_at":"2026-10-01T12:00:00Z","payload":{"id":9007199254740993,"text":"ab"}}]`, text)
+ assert.Contains(t, text, `9007199254740993`)
+ if outputSchema != nil {
+ require.NotNil(t, result.StructuredContent)
+ assert.JSONEq(t, text, mustMarshalJSON(t, result.StructuredContent))
+ require.NoError(t, outputSchema.Validate(result.StructuredContent))
+ } else {
+ assert.Nil(t, result.StructuredContent)
+ }
+ assert.Equal(t, 1, calls)
+
+ response = `[{"id":"2","type":"PushEvent","public":false,"repo":{"name":"octo-org/private"},"payload":{"ref":"refs/heads/main"}}]`
+ private, err := session.CallTool(t.Context(), args)
+ require.NoError(t, err)
+ require.False(t, private.IsError)
+ privateText := getTextResult(t, private).Text
+ assert.JSONEq(t, `[{"id":"2","type":"PushEvent","public":false,"repo":"octo-org/private","payload":{"ref":"refs/heads/main"}}]`, privateText)
+ if outputSchema != nil {
+ assert.JSONEq(t, privateText, mustMarshalJSON(t, private.StructuredContent))
+ require.NoError(t, outputSchema.Validate(private.StructuredContent))
+ }
+
+ response = `[]`
+ empty, err := session.CallTool(t.Context(), args)
+ require.NoError(t, err)
+ require.False(t, empty.IsError)
+ assert.Equal(t, `[]`, getTextResult(t, empty).Text)
+ if outputSchema != nil {
+ assert.JSONEq(t, `[]`, mustMarshalJSON(t, empty.StructuredContent))
+ }
+
+ status, response = http.StatusNotFound, `{"message":"Not Found"}`
+ failed, err := session.CallTool(t.Context(), args)
+ require.NoError(t, err)
+ require.True(t, failed.IsError)
+ assert.Contains(t, getErrorResult(t, failed).Text, "Not Found")
+ assert.Nil(t, failed.StructuredContent)
+
+ invalid, err := session.CallTool(t.Context(), &mcp.CallToolParams{
+ Name: tool.Tool.Name, Arguments: map[string]any{"username": "octocat", "perPage": 0},
+ })
+ require.NoError(t, err)
+ require.True(t, invalid.IsError)
+ assert.Equal(t, 4, calls, "invalid pagination must not reach GitHub")
+ })
+ }
+}
From 26280f8946eaca1892348c4f024bd995aa7f2e04 Mon Sep 17 00:00:00 2001
From: kaii9 <107882135+kaii9@users.noreply.github.com>
Date: Wed, 18 Nov 2026 11:48:44 +0800
Subject: [PATCH 2/3] test(skills): record user activity tool coverage
exemption
---
pkg/skills/catalog/availability_test.go | 1 +
1 file changed, 1 insertion(+)
diff --git a/pkg/skills/catalog/availability_test.go b/pkg/skills/catalog/availability_test.go
index 4e60f3561d..81dbe09094 100644
--- a/pkg/skills/catalog/availability_test.go
+++ b/pkg/skills/catalog/availability_test.go
@@ -32,6 +32,7 @@ var toolCoverageExemptions = map[string]string{
"issue_dependency_read": "Issue dependency graph management is distinct from the current backlog triage workflow.",
"issue_dependency_write": "Issue dependency graph management is distinct from the current backlog triage workflow.",
"list_gists": "Gist lifecycle is separate from the repository workflows covered by the current catalog.",
+ "list_user_events": "User activity history is outside the account identity and team membership workflow.",
"remove_issue_comment_reaction": "Reactions are optional social signals, not a workflow in the current skills.",
"remove_issue_reaction": "Reactions are optional social signals, not a workflow in the current skills.",
"remove_pull_request_review_comment_reaction": "Reactions are optional social signals, not a workflow in the current skills.",
From f6abc1b82acc90c19d078293ac26b0c66537e90a Mon Sep 17 00:00:00 2001
From: kaii9 <107882135+kaii9@users.noreply.github.com>
Date: Wed, 18 Nov 2026 12:09:42 +0800
Subject: [PATCH 3/3] fix: validate and filter user activity results
---
README.md | 4 ++
.../__toolsnaps__/list_user_events.snap | 2 +-
pkg/github/users.go | 16 +++++--
pkg/github/users_test.go | 47 +++++++++++++++++--
4 files changed, 61 insertions(+), 8 deletions(-)
diff --git a/README.md b/README.md
index 04e325212b..8a26037e6c 100644
--- a/README.md
+++ b/README.md
@@ -1778,6 +1778,10 @@ Following tools will filter out content from users lacking the push access:
- `pull_request_read:get_review_comments`
- `pull_request_read:get_reviews`
+`list_user_events` returns event metadata and visibility in lockdown mode. It
+omits event payloads because embedded content can come from multiple authors
+and repositories, and the activity feed cannot verify the origin of every field.
+
## i18n / Overriding Descriptions
The descriptions of the tools can be overridden by creating a
diff --git a/pkg/github/__toolsnaps__/list_user_events.snap b/pkg/github/__toolsnaps__/list_user_events.snap
index 7f7ae0c704..de45615979 100644
--- a/pkg/github/__toolsnaps__/list_user_events.snap
+++ b/pkg/github/__toolsnaps__/list_user_events.snap
@@ -4,7 +4,7 @@
"readOnlyHint": true,
"title": "List user activity"
},
- "description": "List recent GitHub activity performed by a user, such as pushes, pull requests, issues, and stars. GitHub returns public events for other users and may include private events when querying the authenticated user's own activity, subject to token permissions. Returns event metadata, visibility, and event-specific payloads. GitHub limits the feed to up to 300 events from the past 30 days; events may be delayed from 30 seconds to 6 hours. This is not a complete or real-time contribution history.",
+ "description": "List recent GitHub activity performed by a user, such as pushes, pull requests, issues, and stars. GitHub returns public events for other users and may include private events when querying the authenticated user's own activity, subject to token permissions. Returns event metadata, visibility, and event-specific payloads. In lockdown mode, only event metadata and visibility are returned. GitHub limits the feed to up to 300 events from the past 30 days; events may be delayed from 30 seconds to 6 hours. This is not a complete or real-time contribution history.",
"inputSchema": {
"properties": {
"page": {
diff --git a/pkg/github/users.go b/pkg/github/users.go
index 8ed4308250..b3eaf974aa 100644
--- a/pkg/github/users.go
+++ b/pkg/github/users.go
@@ -54,7 +54,7 @@ func ListUserEvents(t translations.TranslationHelperFunc) inventory.ServerTool {
ToolsetMetadataUsers,
mcp.Tool{
Name: "list_user_events",
- Description: t("TOOL_LIST_USER_EVENTS_DESCRIPTION", "List recent GitHub activity performed by a user, such as pushes, pull requests, issues, and stars. GitHub returns public events for other users and may include private events when querying the authenticated user's own activity, subject to token permissions. Returns event metadata, visibility, and event-specific payloads. GitHub limits the feed to up to 300 events from the past 30 days; events may be delayed from 30 seconds to 6 hours. This is not a complete or real-time contribution history."),
+ Description: t("TOOL_LIST_USER_EVENTS_DESCRIPTION", "List recent GitHub activity performed by a user, such as pushes, pull requests, issues, and stars. GitHub returns public events for other users and may include private events when querying the authenticated user's own activity, subject to token permissions. Returns event metadata, visibility, and event-specific payloads. In lockdown mode, only event metadata and visibility are returned. GitHub limits the feed to up to 300 events from the past 30 days; events may be delayed from 30 seconds to 6 hours. This is not a complete or real-time contribution history."),
Annotations: &mcp.ToolAnnotations{
Title: t("TOOL_LIST_USER_EVENTS_USER_TITLE", "List user activity"),
ReadOnlyHint: true,
@@ -63,8 +63,11 @@ func ListUserEvents(t translations.TranslationHelperFunc) inventory.ServerTool {
},
scopes.PublicRead(scopes.Repo),
func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, input ListUserEventsInput) (*mcp.CallToolResult, []MinimalUserEvent, error) {
- if input.Username == "" {
+ switch input.Username {
+ case "":
return utils.NewToolResultError("missing required parameter: username"), nil, nil
+ case ".", "..":
+ return utils.NewToolResultError("username cannot be a dot path segment"), nil, nil
}
page, perPage := 1, 30
if input.Page != nil {
@@ -94,6 +97,9 @@ func ListUserEvents(t translations.TranslationHelperFunc) inventory.ServerTool {
minimalEvents := make([]MinimalUserEvent, 0, len(events))
label := ifc.PublicUntrusted()
+ // Embedded payload data can come from other authors or repositories.
+ // The event actor and repository cannot establish trust for that data.
+ lockdownMode := deps.GetFlags(ctx).LockdownMode
for _, event := range events {
if event == nil {
continue
@@ -104,7 +110,7 @@ func ListUserEvents(t translations.TranslationHelperFunc) inventory.ServerTool {
label = ifc.PrivateUntrusted()
}
var payload any
- if raw := event.GetRawPayload(); len(raw) > 0 {
+ if raw := event.GetRawPayload(); !lockdownMode && len(raw) > 0 {
decoder := json.NewDecoder(bytes.NewReader(raw))
// Event payloads can contain IDs larger than float64's exact integer range.
decoder.UseNumber()
@@ -136,6 +142,10 @@ func sanitizeUserEventPayload(value any) any {
return sanitize.Content(value)
case map[string]any:
for key, item := range value {
+ if text, ok := item.(string); ok && (key == "title" || key == "name") {
+ value[key] = sanitize.PlainText(text)
+ continue
+ }
value[key] = sanitizeUserEventPayload(item)
}
return value
diff --git a/pkg/github/users_test.go b/pkg/github/users_test.go
index b3c01b7403..862d41f829 100644
--- a/pkg/github/users_test.go
+++ b/pkg/github/users_test.go
@@ -55,6 +55,12 @@ func Test_ListUserEvents(t *testing.T) {
response: `[{"id":"4","type":"PushEvent","public":false,"actor":{"login":"octocat"},"repo":{"name":"octo-org/private"},"payload":{"ref":"refs/heads/main"}}]`,
want: `[{"id":"4","type":"PushEvent","public":false,"actor":"octocat","repo":"octo-org/private","payload":{"ref":"refs/heads/main"}}]`,
},
+ {
+ name: "embedded titles and names are plain text while bodies retain formatting",
+ args: map[string]any{"username": "octocat"}, page: "1", perPage: "30", status: http.StatusOK,
+ response: `[{"id":"5","type":"IssuesEvent","public":true,"payload":{"issue":{"title":"Issue title","body":"Keep formatting"}}},{"id":"6","type":"ReleaseEvent","public":true,"payload":{"release":{"name":"Release name","tag_name":"v1.0.0"}}}]`,
+ want: `[{"id":"5","type":"IssuesEvent","public":true,"payload":{"issue":{"title":"Issue title","body":"Keep formatting"}}},{"id":"6","type":"ReleaseEvent","public":true,"payload":{"release":{"name":"Release name","tag_name":"v1.0.0"}}}]`,
+ },
{
name: "explicit pagination reaches GitHub",
args: map[string]any{"username": "octocat", "page": 3, "perPage": 100}, page: "3", perPage: "100", status: http.StatusOK,
@@ -123,6 +129,8 @@ func Test_ListUserEvents_InvalidArguments(t *testing.T) {
{"missing username", map[string]any{}, "username"},
{"empty username", map[string]any{"username": ""}, "username"},
{"wrong username type", map[string]any{"username": 42}, "username"},
+ {"current-directory username", map[string]any{"username": "."}, "username cannot be a dot path segment"},
+ {"parent-directory username", map[string]any{"username": ".."}, "username cannot be a dot path segment"},
{"page below minimum", map[string]any{"username": "octocat", "page": 0}, "page"},
{"perPage below minimum", map[string]any{"username": "octocat", "perPage": 0}, "perPage"},
{"perPage above maximum", map[string]any{"username": "octocat", "perPage": 101}, "perPage"},
@@ -130,15 +138,46 @@ func Test_ListUserEvents_InvalidArguments(t *testing.T) {
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
- client := MockHTTPClientWithHandler(func(_ http.ResponseWriter, _ *http.Request) {
- t.Fatal("invalid arguments must not send an API request")
- })
- deps := BaseDeps{Client: mustNewGHClient(t, client), Obsv: stubExporters()}
+ deps := stubDeps{clientFn: stubClientFnErr("unexpected GitHub client acquisition"), obsv: stubExporters()}
request := createMCPRequest(tc.args)
result, err := tool.Handler(deps)(ContextWithDeps(t.Context(), deps), &request)
require.NoError(t, err)
require.True(t, result.IsError)
assert.Contains(t, getErrorResult(t, result).Text, tc.want)
+ assert.NotContains(t, getErrorResult(t, result).Text, "unexpected GitHub client acquisition")
+ })
+ }
+}
+
+func Test_ListUserEvents_LockdownMode(t *testing.T) {
+ t.Parallel()
+ const response = `[{"id":"1","type":"IssueCommentEvent","public":true,"actor":{"login":"octocat"},"repo":{"name":"octo-org/demo"},"created_at":"2026-10-01T12:00:00Z","payload":{"issue":{"title":"Issue title","body":"Issue body"},"comment":{"body":"Comment body"}}},{"id":"2","type":"FutureEvent","public":false,"payload":{"nested":{"summary":"Unknown payload"}}}]`
+ const want = `[{"id":"1","type":"IssueCommentEvent","public":true,"actor":"octocat","repo":"octo-org/demo","created_at":"2026-10-01T12:00:00Z"},{"id":"2","type":"FutureEvent","public":false}]`
+ for _, protocol := range []string{"2025-11-25", inventory.ProtocolVersionMultiRoundTrip} {
+ t.Run(protocol, func(t *testing.T) {
+ client := MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
+ "GET /users/octocat/events": func(w http.ResponseWriter, _ *http.Request) {
+ _, _ = w.Write([]byte(response))
+ },
+ })
+ deps := BaseDeps{
+ Client: mustNewGHClient(t, client),
+ Flags: FeatureFlags{LockdownMode: true},
+ Obsv: stubExporters(),
+ }
+ tool := userEventsTool(t)
+ session := connectTypedSearchClient(t, tool, deps, protocol)
+ result, err := session.CallTool(t.Context(), &mcp.CallToolParams{
+ Name: tool.Tool.Name, Arguments: map[string]any{"username": "octocat"},
+ })
+ require.NoError(t, err)
+ require.False(t, result.IsError, result)
+ assert.JSONEq(t, want, getTextResult(t, result).Text)
+ if protocol == inventory.ProtocolVersionMultiRoundTrip {
+ assert.JSONEq(t, want, mustMarshalJSON(t, result.StructuredContent))
+ } else {
+ assert.Nil(t, result.StructuredContent)
+ }
})
}
}