From c7a5fc0afb920d7bc82bd74a7c8c24fc87aa0dab Mon Sep 17 00:00:00 2001 From: Garrett Bjerkhoel Date: Thu, 12 Nov 2026 11:38:04 -0800 Subject: [PATCH 1/4] Extract ownerAccountType from detectOwnerType Pull the Users.Get account type lookup out of detectOwnerType so issue metadata can reuse it to tell a user owner from an organization. The project probe fallback is unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 48ff87e1-24bb-49f1-887f-9f2576ab0c2d --- pkg/github/projects.go | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/pkg/github/projects.go b/pkg/github/projects.go index e55b2a29d6..7d3d9df043 100644 --- a/pkg/github/projects.go +++ b/pkg/github/projects.go @@ -2861,25 +2861,32 @@ type ProjectV2IterationFieldIterationInput struct { Title githubv4.String `json:"title"` } +// ownerAccountType reports whether a login is a "user" or an "org", or "" for +// any other account type. +func ownerAccountType(ctx context.Context, client *github.Client, owner string) (string, *github.Response, error) { + account, resp, err := client.Users.Get(ctx, owner) + if err != nil { + return "", resp, err + } + switch account.GetType() { + case "User": + return "user", resp, nil + case "Organization": + return "org", resp, nil + } + return "", resp, nil +} + // detectOwnerType attempts to detect whether the project owner is a user or org. // It first asks GitHub for the account type, then falls back to project probes // for older or mocked clients where the account type is unavailable. func detectOwnerType(ctx context.Context, client *github.Client, owner string, projectNumber int) (string, error) { - user, resp, err := client.Users.Get(ctx, owner) - if resp != nil && resp.Body != nil { - _ = resp.Body.Close() - } - if err == nil && resp != nil && resp.StatusCode == http.StatusOK { - switch user.GetType() { - case "User": - return "user", nil - case "Organization": - return "org", nil - } + if ownerType, _, err := ownerAccountType(ctx, client, owner); err == nil && ownerType != "" { + return ownerType, nil } // Try user first (more common for personal projects) - _, resp, err = client.Projects.GetUserProject(ctx, owner, projectNumber) + _, resp, err := client.Projects.GetUserProject(ctx, owner, projectNumber) if err == nil && resp.StatusCode == http.StatusOK { _ = resp.Body.Close() return "user", nil From f726c7bbf92f79376103862f1a5cc3d744f64653 Mon Sep 17 00:00:00 2001 From: Garrett Bjerkhoel Date: Thu, 12 Nov 2026 11:38:52 -0800 Subject: [PATCH 2/4] Resolve issue types and fields for user-owned repositories Issue types and issue fields are available on user accounts as well as organizations. list_issue_types, list_issue_fields, and the ui_get issue_types method assumed the owner was an organization when repo was omitted, so they failed or came back empty for user-owned repositories. Introduce issueMetadataScope (repository, organization, or the authenticated user) and resolve it once per call. With repo, the repository path is unchanged. Without repo, the owner's account type picks the organization endpoints or, when the owner is the authenticated user, GET /user/issue-types and GraphQL user(login:).issueFields. GitHub lists a user's definitions only to that user, so any other user owner gets a tool error asking for repo instead of a raw FORBIDDEN. The issue-write app now passes repo to ui_get issue_types, which reads the repository endpoint. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 48ff87e1-24bb-49f1-887f-9f2576ab0c2d --- pkg/github/issue_fields.go | 67 +++++++++++------ pkg/github/issue_fields_test.go | 62 ++++++++++++++- pkg/github/issue_metadata_scope.go | 83 +++++++++++++++++++++ pkg/github/issues.go | 63 ++++------------ pkg/github/issues_test.go | 56 +++++++++++++- pkg/github/tool_scopes.go | 3 + pkg/github/tool_scopes_test.go | 7 ++ pkg/github/typed_copilot_ui_outputs_test.go | 2 + pkg/github/typed_issue_outputs_test.go | 6 +- pkg/github/ui_tools.go | 29 ++++--- pkg/github/ui_tools_test.go | 20 +++++ ui/src/apps/issue-write/App.tsx | 2 +- 12 files changed, 307 insertions(+), 93 deletions(-) create mode 100644 pkg/github/issue_metadata_scope.go diff --git a/pkg/github/issue_fields.go b/pkg/github/issue_fields.go index 93a2a04a48..56c79bbaf9 100644 --- a/pkg/github/issue_fields.go +++ b/pkg/github/issue_fields.go @@ -101,7 +101,16 @@ type issueFieldsOrgQuery struct { } `graphql:"organization(login: $login)"` } -// ListIssueFields creates a tool to list issue field definitions for a repository or organization. +// issueFieldsUserQuery is the GraphQL query for listing issue fields on a user account. +type issueFieldsUserQuery struct { + User struct { + IssueFields struct { + Nodes []issueFieldNode + } `graphql:"issueFields(first: 100)"` + } `graphql:"user(login: $login)"` +} + +// ListIssueFields creates a tool to list issue field definitions for a repository or its owner. func ListIssueFields(t translations.TranslationHelperFunc) inventory.ServerTool { st := NewToolWithSchemaOptions[IssueMetadataInput, []IssueFieldOutput]( ToolsetMetadataIssues, @@ -136,12 +145,21 @@ func ListIssueFields(t translations.TranslationHelperFunc) inventory.ServerTool return utils.NewToolResultError("missing required parameter: owner"), nil, nil } + client, err := deps.GetClient(ctx) + if err != nil { + return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil, nil + } + scope, errResult := resolveIssueMetadataScope(ctx, client, owner, repo) + if errResult != nil { + return errResult, nil, nil + } + gqlClient, err := deps.GetGQLClient(ctx) if err != nil { return utils.NewToolResultErrorFromErr("failed to get GitHub GraphQL client", err), nil, nil } - fields, err := fetchIssueFields(ctx, gqlClient, owner, repo) + fields, err := fetchIssueFields(ctx, gqlClient, scope) if err != nil { return ghErrors.NewGitHubGraphQLErrorResponse(ctx, "failed to list issue fields", err), nil, nil } @@ -152,44 +170,47 @@ func ListIssueFields(t translations.TranslationHelperFunc) inventory.ServerTool } result := utils.NewToolResultText(string(r)) - // Issue field definitions are repo/org structural metadata + // Issue field definitions are repo/owner structural metadata // (trusted). When scoped to a specific repo, confidentiality - // follows that repo's visibility; for an org-level lookup (no + // follows that repo's visibility; for an owner-level lookup (no // repo) it is conservatively treated as private. - if repo == "" { - result = attachStaticIFCLabel(ctx, deps, result, ifc.LabelRepoMetadata(true)) - } else { + if scope.Kind == issueMetadataRepo { result = attachRepoVisibilityIFCLabelLazy(ctx, deps, owner, repo, result, ifc.LabelRepoMetadata) + } else { + result = attachStaticIFCLabel(ctx, deps, result, ifc.LabelRepoMetadata(true)) } return result, issueFieldOutputs(fields), nil }, normalizeIssueStrings([]string{"owner"}, []string{"repo"})) return st } -// fetchIssueFields returns the issue field definitions for the given owner. -// If repo is provided, fields are scoped to that repository (inherited from its -// organization); otherwise fields are returned directly from the organization. -func fetchIssueFields(ctx context.Context, gqlClient *githubv4.Client, owner, repo string) ([]IssueField, error) { - if repo != "" { +// fetchIssueFields returns the issue field definitions for scope. A repository +// returns the fields it inherits from its owner. +func fetchIssueFields(ctx context.Context, gqlClient *githubv4.Client, scope issueMetadataScope) ([]IssueField, error) { + switch scope.Kind { + case issueMetadataOrg: + var query issueFieldsOrgQuery + if err := gqlClient.Query(ctx, &query, map[string]any{"login": githubv4.String(scope.Owner)}); err != nil { + return nil, err + } + return issueFieldsFromNodes(query.Organization.IssueFields.Nodes), nil + case issueMetadataViewer: + var query issueFieldsUserQuery + if err := gqlClient.Query(ctx, &query, map[string]any{"login": githubv4.String(scope.Owner)}); err != nil { + return nil, err + } + return issueFieldsFromNodes(query.User.IssueFields.Nodes), nil + default: var query issueFieldsRepoQuery vars := map[string]any{ - "owner": githubv4.String(owner), - "name": githubv4.String(repo), + "owner": githubv4.String(scope.Owner), + "name": githubv4.String(scope.Repo), } if err := gqlClient.Query(ctx, &query, vars); err != nil { return nil, err } return issueFieldsFromNodes(query.Repository.IssueFields.Nodes), nil } - - var query issueFieldsOrgQuery - vars := map[string]any{ - "login": githubv4.String(owner), - } - if err := gqlClient.Query(ctx, &query, vars); err != nil { - return nil, err - } - return issueFieldsFromNodes(query.Organization.IssueFields.Nodes), nil } // issueFieldsFromNodes converts GraphQL issue field union nodes into IssueField values. diff --git a/pkg/github/issue_fields_test.go b/pkg/github/issue_fields_test.go index f30cdab256..39e1806448 100644 --- a/pkg/github/issue_fields_test.go +++ b/pkg/github/issue_fields_test.go @@ -3,11 +3,13 @@ package github import ( "context" "encoding/json" + "net/http" "testing" "github.com/github/github-mcp-server/v2/internal/githubv4mock" "github.com/github/github-mcp-server/v2/internal/toolsnaps" "github.com/github/github-mcp-server/v2/pkg/translations" + "github.com/google/go-github/v92/github" "github.com/google/jsonschema-go/jsonschema" "github.com/shurcooL/githubv4" "github.com/stretchr/testify/assert" @@ -39,10 +41,14 @@ func Test_ListIssueFields(t *testing.T) { defaultOrgVars := map[string]any{ "login": githubv4.String("testowner"), } + orgAccount := &github.User{Login: new("testowner"), Type: new("Organization")} + viewerAccount := &github.User{Login: new("testowner"), Type: new("User")} + otherUserAccount := &github.User{Login: new("hubot"), Type: new("User")} tests := []struct { name string requestArgs map[string]any + restHandlers map[string]http.HandlerFunc mockQueryStruct any mockVars map[string]any gqlResponse githubv4mock.GQLResponse @@ -159,10 +165,13 @@ func Test_ListIssueFields(t *testing.T) { expectedErrMsg: "missing required parameter: owner", }, { - name: "no repo returns org-level fields", + name: "organization owner returns organization fields", requestArgs: map[string]any{ "owner": "testowner", }, + restHandlers: map[string]http.HandlerFunc{ + "GET /users/testowner": mockResponse(t, http.StatusOK, orgAccount), + }, mockQueryStruct: orgQueryStruct, mockVars: defaultOrgVars, gqlResponse: githubv4mock.DataResponse(map[string]any{ @@ -185,6 +194,52 @@ func Test_ListIssueFields(t *testing.T) { {ID: "IFT_1", DatabaseID: 77, Name: "DRI", DataType: "TEXT", Visibility: "ORG_ONLY"}, }, }, + { + name: "authenticated user owner returns their own fields", + requestArgs: map[string]any{ + "owner": "testowner", + }, + restHandlers: map[string]http.HandlerFunc{ + "GET /users/testowner": mockResponse(t, http.StatusOK, viewerAccount), + "GET /user": mockResponse(t, http.StatusOK, viewerAccount), + }, + mockQueryStruct: issueFieldsUserQuery{}, + mockVars: defaultOrgVars, + gqlResponse: githubv4mock.DataResponse(map[string]any{ + "user": map[string]any{ + "issueFields": map[string]any{ + "nodes": []any{ + map[string]any{ + "__typename": "IssueFieldDate", + "id": "IFD_9", + "fullDatabaseId": "909", + "name": "Due", + "dataType": "DATE", + "visibility": "ALL", + }, + }, + }, + }, + }), + expectedFields: []IssueField{ + {ID: "IFD_9", DatabaseID: 909, Name: "Due", DataType: "DATE", Visibility: "ALL"}, + }, + }, + { + name: "another user owner asks for repo", + requestArgs: map[string]any{ + "owner": "hubot", + }, + restHandlers: map[string]http.HandlerFunc{ + "GET /users/hubot": mockResponse(t, http.StatusOK, otherUserAccount), + "GET /user": mockResponse(t, http.StatusOK, viewerAccount), + }, + mockQueryStruct: issueFieldsUserQuery{}, + mockVars: map[string]any{"login": githubv4.String("hubot")}, + gqlResponse: githubv4mock.ErrorResponse("FORBIDDEN"), + expectError: true, + expectedErrMsg: "Pass repo to list them for one of hubot's repositories", + }, { name: "number field returned", requestArgs: map[string]any{ @@ -264,6 +319,9 @@ func Test_ListIssueFields(t *testing.T) { ) gqlClient := githubv4.NewClient(mockedHTTPClient) deps := BaseDeps{GQLClient: gqlClient} + if tc.restHandlers != nil { + deps.Client = mustNewGHClient(t, MockHTTPClientWithHandlers(tc.restHandlers)) + } handler := serverTool.Handler(deps) request := createMCPRequest(tc.requestArgs) @@ -289,7 +347,7 @@ func Test_ListIssueFields(t *testing.T) { var returnedFields []IssueField err = json.Unmarshal([]byte(textContent.Text), &returnedFields) require.NoError(t, err) - require.Equal(t, len(tc.expectedFields), len(returnedFields)) + require.Equal(t, len(tc.expectedFields), len(returnedFields), "field count in %s", textContent.Text) for i, expected := range tc.expectedFields { assert.Equal(t, expected.ID, returnedFields[i].ID) assert.Equal(t, expected.DatabaseID, returnedFields[i].DatabaseID) diff --git a/pkg/github/issue_metadata_scope.go b/pkg/github/issue_metadata_scope.go new file mode 100644 index 0000000000..60fd3f8526 --- /dev/null +++ b/pkg/github/issue_metadata_scope.go @@ -0,0 +1,83 @@ +package github + +import ( + "context" + "fmt" + "net/http" + "strings" + + ghErrors "github.com/github/github-mcp-server/v2/pkg/errors" + "github.com/github/github-mcp-server/v2/pkg/utils" + "github.com/google/go-github/v92/github" + "github.com/modelcontextprotocol/go-sdk/mcp" +) + +// issueMetadataScope is the repository or account whose issue types and +// issue fields a lookup lists. +type issueMetadataScope struct { + Kind issueMetadataScopeKind + Owner string + Repo string +} + +type issueMetadataScopeKind int + +const ( + issueMetadataRepo issueMetadataScopeKind = iota + issueMetadataOrg + // issueMetadataViewer is a user account listing its own definitions. + // GitHub lists a user's issue types and fields only to that user. + issueMetadataViewer +) + +// resolveIssueMetadataScope picks where to list issue types and fields. A +// repository always wins. Without one, the owner's account type decides. A +// failed lookup returns a tool error result. +func resolveIssueMetadataScope(ctx context.Context, client *github.Client, owner, repo string) (issueMetadataScope, *mcp.CallToolResult) { + scope := issueMetadataScope{Owner: owner, Repo: repo} + if repo != "" { + return scope, nil + } + + ownerType, resp, err := ownerAccountType(ctx, client, owner) + if err != nil { + return scope, ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to look up owner", resp, err) + } + if ownerType == "org" { + scope.Kind = issueMetadataOrg + return scope, nil + } + + viewer, resp, err := client.Users.Get(ctx, "") + if err != nil { + return scope, ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to get authenticated user", resp, err) + } + if !strings.EqualFold(viewer.GetLogin(), owner) { + return scope, utils.NewToolResultError(fmt.Sprintf( + "%s is a user account, and GitHub lists a user's issue types and fields only to that user. Pass repo to list them for one of %s's repositories.", + owner, owner, + )) + } + scope.Kind = issueMetadataViewer + return scope, nil +} + +func fetchIssueTypes(ctx context.Context, client *github.Client, scope issueMetadataScope) ([]*github.IssueType, *github.Response, error) { + var path string + switch scope.Kind { + case issueMetadataOrg: + path = fmt.Sprintf("orgs/%s/issue-types", scope.Owner) + case issueMetadataViewer: + path = "user/issue-types" + default: + path = fmt.Sprintf("repos/%s/%s/issue-types", scope.Owner, scope.Repo) + } + + req, err := client.NewRequest(ctx, http.MethodGet, path, nil) + if err != nil { + return nil, nil, err + } + var issueTypes []*github.IssueType + resp, err := client.Do(req, &issueTypes) + return issueTypes, resp, err +} diff --git a/pkg/github/issues.go b/pkg/github/issues.go index 5a5932335e..fb3c29e8c1 100644 --- a/pkg/github/issues.go +++ b/pkg/github/issues.go @@ -1291,7 +1291,7 @@ func getIssueLabels(ctx context.Context, client *githubv4.Client, owner string, return utils.NewToolResultText(string(out)), &IssueReadOutput{Method: "get_labels", Labels: &response.Labels, TotalCount: &response.TotalCount}, nil } -// ListIssueTypes creates a tool to list defined issue types for an organization or repository. +// ListIssueTypes creates a tool to list defined issue types for a repository or its owner. // This can be used to understand supported issue type values for creating or updating issues. func ListIssueTypes(t translations.TranslationHelperFunc) inventory.ServerTool { st := NewTool[IssueMetadataInput, []*IssueTypeOutput]( @@ -1331,49 +1331,14 @@ func ListIssueTypes(t translations.TranslationHelperFunc) inventory.ServerTool { return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil, nil } - if repo != "" { - apiURL := fmt.Sprintf("repos/%s/%s/issue-types", owner, repo) - req, err := client.NewRequest(ctx, "GET", apiURL, nil) - if err != nil { - return utils.NewToolResultErrorFromErr("failed to create request", err), nil, nil - } - var issueTypes []*github.IssueType - resp, err := client.Do(req, &issueTypes) - if err != nil { - return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to list issue types", resp, err), nil, nil - } - defer func() { _ = resp.Body.Close() }() - - if resp.StatusCode != http.StatusOK { - body, err := io.ReadAll(resp.Body) - if err != nil { - return utils.NewToolResultErrorFromErr("failed to read response body", err), nil, nil - } - return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to list issue types", resp, body), nil, nil - } - - r, err := json.Marshal(issueTypes) - if err != nil { - return utils.NewToolResultErrorFromErr("failed to marshal issue types", err), nil, nil - } - - result := utils.NewToolResultText(string(r)) - result = attachRepoVisibilityIFCLabelLazy(ctx, deps, owner, repo, result, ifc.LabelRepoMetadata) - return result, issueTypeOutputs(issueTypes), nil + scope, errResult := resolveIssueMetadataScope(ctx, client, owner, repo) + if errResult != nil { + return errResult, nil, nil } - issueTypes, resp, err := client.Organizations.ListIssueTypes(ctx, owner) + issueTypes, resp, err := fetchIssueTypes(ctx, client, scope) if err != nil { - return utils.NewToolResultErrorFromErr("failed to list issue types", err), nil, nil - } - defer func() { _ = resp.Body.Close() }() - - if resp.StatusCode != http.StatusOK { - body, err := io.ReadAll(resp.Body) - if err != nil { - return utils.NewToolResultErrorFromErr("failed to read response body", err), nil, nil - } - return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to list issue types", resp, body), nil, nil + return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to list issue types", resp, err), nil, nil } r, err := json.Marshal(issueTypes) @@ -1382,11 +1347,15 @@ func ListIssueTypes(t translations.TranslationHelperFunc) inventory.ServerTool { } result := utils.NewToolResultText(string(r)) - // Issue types are org-defined structural metadata (trusted, not - // attacker-authored). They are scoped to an organization rather - // than a single repo, so confidentiality is conservatively treated - // as private (restricted to org members). - result = attachStaticIFCLabel(ctx, deps, result, ifc.LabelRepoMetadata(true)) + if scope.Kind == issueMetadataRepo { + result = attachRepoVisibilityIFCLabelLazy(ctx, deps, owner, repo, result, ifc.LabelRepoMetadata) + } else { + // Issue types are owner-defined structural metadata (trusted, + // not attacker-authored). They are scoped to an account rather + // than a single repo, so confidentiality is conservatively + // treated as private. + result = attachStaticIFCLabel(ctx, deps, result, ifc.LabelRepoMetadata(true)) + } return result, issueTypeOutputs(issueTypes), nil }, normalizeIssueStrings([]string{"owner"}, []string{"repo"})) return st @@ -3907,7 +3876,7 @@ func ListIssues(t translations.TranslationHelperFunc) inventory.ServerTool { // coerce each value into the right typed slot on IssueFieldValueFilter. fieldFilters := []IssueFieldValueFilter{} if len(rawFilters) > 0 { - fields, err := fetchIssueFields(ctx, client, owner, repo) + fields, err := fetchIssueFields(ctx, client, issueMetadataScope{Owner: owner, Repo: repo}) if err != nil { return ghErrors.NewGitHubGraphQLErrorResponse(ctx, "failed to look up issue fields for field_filters", err), output, nil } diff --git a/pkg/github/issues_test.go b/pkg/github/issues_test.go index b12782b038..3e3ea056dc 100644 --- a/pkg/github/issues_test.go +++ b/pkg/github/issues_test.go @@ -7321,6 +7321,10 @@ func Test_ListIssueTypes(t *testing.T) { }, } + orgAccount := &github.User{Login: new("testorg"), Type: new("Organization")} + viewerAccount := &github.User{Login: new("octocat"), Type: new("User")} + otherUserAccount := &github.User{Login: new("hubot"), Type: new("User")} + tests := []struct { name string mockedClient *http.Client @@ -7330,8 +7334,9 @@ func Test_ListIssueTypes(t *testing.T) { expectedErrMsg string }{ { - name: "successful issue types retrieval", + name: "organization owner lists organization issue types", mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ + "GET /users/testorg": mockResponse(t, http.StatusOK, orgAccount), "GET /orgs/testorg/issue-types": mockResponse(t, http.StatusOK, mockIssueTypes), }), requestArgs: map[string]any{ @@ -7341,14 +7346,59 @@ func Test_ListIssueTypes(t *testing.T) { expectedIssueTypes: mockIssueTypes, }, { - name: "organization not found", + name: "authenticated user owner lists their own issue types", + mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ + "GET /users/OctoCat": mockResponse(t, http.StatusOK, viewerAccount), + "GET /user": mockResponse(t, http.StatusOK, viewerAccount), + "GET /user/issue-types": mockResponse(t, http.StatusOK, mockIssueTypes), + "GET /orgs/OctoCat/issue-types": func(w http.ResponseWriter, _ *http.Request) { + t.Error("a user owner must not be listed through the organization endpoint") + w.WriteHeader(http.StatusNotFound) + }, + }), + requestArgs: map[string]any{ + "owner": "OctoCat", + }, + expectError: false, + expectedIssueTypes: mockIssueTypes, + }, + { + name: "another user owner asks for repo", + mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ + "GET /users/hubot": mockResponse(t, http.StatusOK, otherUserAccount), + "GET /user": mockResponse(t, http.StatusOK, viewerAccount), + "GET /user/issue-types": func(w http.ResponseWriter, _ *http.Request) { + t.Error("the authenticated user's issue types must not be returned for another user") + w.WriteHeader(http.StatusOK) + }, + }), + requestArgs: map[string]any{ + "owner": "hubot", + }, + expectError: true, + expectedErrMsg: "Pass repo to list them for one of hubot's repositories", + }, + { + name: "owner not found", mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ - "GET /orgs/nonexistent/issue-types": mockResponse(t, http.StatusNotFound, `{"message": "Organization not found"}`), + "GET /users/nonexistent": mockResponse(t, http.StatusNotFound, `{"message": "Not Found"}`), }), requestArgs: map[string]any{ "owner": "nonexistent", }, expectError: true, + expectedErrMsg: "failed to look up owner", + }, + { + name: "organization issue types error", + mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ + "GET /users/testorg": mockResponse(t, http.StatusOK, orgAccount), + "GET /orgs/testorg/issue-types": mockResponse(t, http.StatusForbidden, `{"message": "Forbidden"}`), + }), + requestArgs: map[string]any{ + "owner": "testorg", + }, + expectError: true, expectedErrMsg: "failed to list issue types", }, { diff --git a/pkg/github/tool_scopes.go b/pkg/github/tool_scopes.go index 02b01c7881..baead86f5b 100644 --- a/pkg/github/tool_scopes.go +++ b/pkg/github/tool_scopes.go @@ -51,6 +51,9 @@ func uiGetScopeAccess() inventory.ScopeAccess { return nil } if method == "issue_types" { + if repo, ok := arguments["repo"].(string); ok && repo != "" { + return scopes.ChallengeAll(activeScopes, scopes.Repo) + } return scopes.ChallengeAll(activeScopes, scopes.ReadOrg) } if method == "reviewers" { diff --git a/pkg/github/tool_scopes_test.go b/pkg/github/tool_scopes_test.go index 64b490854d..36be86a55b 100644 --- a/pkg/github/tool_scopes_test.go +++ b/pkg/github/tool_scopes_test.go @@ -52,6 +52,13 @@ func TestConditionalToolScopeChecks(t *testing.T) { allowed: []string{"repo"}, disallowed: []string{"read:org"}, }, + { + name: "ui issue types repository method", + tool: UIGet(translations.NullTranslationHelper), + arguments: map[string]any{"method": "issue_types", "owner": "octo", "repo": "repo"}, + allowed: []string{"repo"}, + disallowed: []string{"read:org"}, + }, { name: "ui organization method", tool: UIGet(translations.NullTranslationHelper), diff --git a/pkg/github/typed_copilot_ui_outputs_test.go b/pkg/github/typed_copilot_ui_outputs_test.go index 6245f783bc..39811e7644 100644 --- a/pkg/github/typed_copilot_ui_outputs_test.go +++ b/pkg/github/typed_copilot_ui_outputs_test.go @@ -71,6 +71,8 @@ func typedCopilotUIClient(t *testing.T, fixture ...string) ToolDependencies { default: return nil, assert.AnError } + case "/users/owner": + body = `{"login":"owner","type":"Organization"}` case "/orgs/owner/issue-types": switch fixtureMode { case "nonempty": diff --git a/pkg/github/typed_issue_outputs_test.go b/pkg/github/typed_issue_outputs_test.go index 698abdf01a..b76a673792 100644 --- a/pkg/github/typed_issue_outputs_test.go +++ b/pkg/github/typed_issue_outputs_test.go @@ -34,6 +34,7 @@ func typedIssueDeps(t *testing.T) BaseDeps { IssueURL: new("https://api.github.com/repos/owner/repo/issues/123"), } handlers := map[string]http.HandlerFunc{ + "GET /users/{owner}": mockResponse(t, http.StatusOK, &github.User{Login: new("owner"), Type: new("Organization")}), "GET /orgs/{owner}/issue-types": mockResponse(t, http.StatusOK, types), "GET /repos/{owner}/{repo}/issue-types": mockResponse(t, http.StatusOK, types), string(endpointGetIssue): mockResponse(t, http.StatusOK, relatedIssue), @@ -232,6 +233,7 @@ func TestTypedIssueNullOutput(t *testing.T) { inv, err := inventory.NewBuilder().SetTools([]inventory.ServerTool{tool}).WithToolsets([]string{"all"}).Build() require.NoError(t, err) deps := BaseDeps{Client: mustNewGHClient(t, MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ + "GET /users/{owner}": mockResponse(t, http.StatusOK, &github.User{Login: new("owner"), Type: new("Organization")}), "GET /orgs/{owner}/issue-types": func(w http.ResponseWriter, _ *http.Request) { _, _ = w.Write([]byte("null")) }, @@ -301,8 +303,8 @@ func TestTypedIssueAPIErrors(t *testing.T) { args map[string]any text string }{ - {ListIssueTypes(translate), map[string]any{"owner": "owner"}, "failed to list issue types"}, - {ListIssueFields(translate), map[string]any{"owner": "owner"}, "failed to list issue fields"}, + {ListIssueTypes(translate), map[string]any{"owner": "owner", "repo": "repo"}, "failed to list issue types"}, + {ListIssueFields(translate), map[string]any{"owner": "owner", "repo": "repo"}, "failed to list issue fields"}, {AddIssueComment(translate), map[string]any{"owner": "owner", "repo": "repo", "issue_number": 123, "body": "Hello"}, "failed to create comment"}, {UpdateIssueComment(translate), map[string]any{"owner": "owner", "repo": "repo", "comment_id": 42, "body": "Hello"}, "failed to update issue comment"}, {IssueDependencyRead(translate), map[string]any{"method": "get_blocked_by", "owner": "owner", "repo": "repo", "issue_number": 123}, "failed to list blocked-by issues"}, diff --git a/pkg/github/ui_tools.go b/pkg/github/ui_tools.go index 03673efd62..21ac969199 100644 --- a/pkg/github/ui_tools.go +++ b/pkg/github/ui_tools.go @@ -4,8 +4,6 @@ import ( "context" "encoding/json" "fmt" - "io" - "net/http" "sort" "strings" @@ -88,7 +86,7 @@ func UIGet(t translations.TranslationHelperFunc) inventory.ServerTool { case "milestones": result, _, err = uiGetMilestones(ctx, deps, args, owner) case "issue_types": - result, _, err = uiGetIssueTypes(ctx, deps, owner) + result, _, err = uiGetIssueTypes(ctx, deps, args, owner) case "branches": result, _, err = uiGetBranches(ctx, deps, args, owner) case "issue_fields": @@ -300,24 +298,25 @@ func uiGetMilestones(ctx context.Context, deps ToolDependencies, args map[string return utils.NewToolResultText(string(out)), nil, nil } -func uiGetIssueTypes(ctx context.Context, deps ToolDependencies, owner string) (*mcp.CallToolResult, any, error) { +func uiGetIssueTypes(ctx context.Context, deps ToolDependencies, args map[string]any, owner string) (*mcp.CallToolResult, any, error) { + repo, err := OptionalParam[string](args, "repo") + if err != nil { + return utils.NewToolResultError(err.Error()), nil, nil + } + client, err := deps.GetClient(ctx) if err != nil { return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil, nil } - issueTypes, resp, err := client.Organizations.ListIssueTypes(ctx, owner) - if err != nil { - return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to list issue types", resp, err), nil, nil + scope, errResult := resolveIssueMetadataScope(ctx, client, owner, repo) + if errResult != nil { + return errResult, nil, nil } - defer func() { _ = resp.Body.Close() }() - if resp.StatusCode != http.StatusOK { - body, err := io.ReadAll(resp.Body) - if err != nil { - return utils.NewToolResultErrorFromErr("failed to read response body", err), nil, nil - } - return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to list issue types", resp, body), nil, nil + issueTypes, resp, err := fetchIssueTypes(ctx, client, scope) + if err != nil { + return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to list issue types", resp, err), nil, nil } r, err := json.Marshal(issueTypes) @@ -392,7 +391,7 @@ func uiGetIssueFields(ctx context.Context, deps ToolDependencies, args map[strin return utils.NewToolResultErrorFromErr("failed to get GitHub GraphQL client", err), nil, nil } - fields, err := fetchIssueFields(ctx, gqlClient, owner, repo) + fields, err := fetchIssueFields(ctx, gqlClient, issueMetadataScope{Owner: owner, Repo: repo}) if err != nil { return ghErrors.NewGitHubGraphQLErrorResponse(ctx, "failed to list issue fields", err), nil, nil } diff --git a/pkg/github/ui_tools_test.go b/pkg/github/ui_tools_test.go index 1a9eaf6a46..c37fa4ca72 100644 --- a/pkg/github/ui_tools_test.go +++ b/pkg/github/ui_tools_test.go @@ -216,9 +216,28 @@ func Test_UIGet(t *testing.T) { assert.Equal(t, "", second["due_on"], "milestone without a due date should be empty, not zero time") }, }, + { + name: "issue_types with repo lists the repository's issue types", + mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ + "GET /repos/octocat/hello-world/issue-types": mockResponse(t, http.StatusOK, mockIssueTypes), + }), + requestArgs: map[string]any{ + "method": "issue_types", + "owner": "octocat", + "repo": "hello-world", + }, + expectError: false, + validateResult: func(t *testing.T, responseText string) { + var issueTypes []map[string]any + require.NoError(t, json.Unmarshal([]byte(responseText), &issueTypes)) + require.Len(t, issueTypes, 2, "repository issue types in %s", responseText) + assert.Equal(t, "Bug", issueTypes[0]["name"]) + }, + }, { name: "successful issue_types fetch", mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ + "GET /users/owner": mockResponse(t, http.StatusOK, &github.User{Login: new("owner"), Type: new("Organization")}), "GET /orgs/owner/issue-types": mockResponse(t, http.StatusOK, mockIssueTypes), }), requestArgs: map[string]any{ @@ -236,6 +255,7 @@ func Test_UIGet(t *testing.T) { { name: "issue_types API error returns response context", mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ + "GET /users/owner": mockResponse(t, http.StatusOK, &github.User{Login: new("owner"), Type: new("Organization")}), "GET /orgs/owner/issue-types": mockResponse(t, http.StatusForbidden, map[string]string{"message": "Forbidden"}), }), requestArgs: map[string]any{ diff --git a/ui/src/apps/issue-write/App.tsx b/ui/src/apps/issue-write/App.tsx index 5cfb5d83a4..7eaec6a1c0 100644 --- a/ui/src/apps/issue-write/App.tsx +++ b/ui/src/apps/issue-write/App.tsx @@ -628,7 +628,7 @@ function CreateIssueApp() { const loadIssueTypes = async () => { setIssueTypesLoading(true); try { - const result = await callTool("ui_get", { method: "issue_types", owner }); + const result = await callTool("ui_get", { method: "issue_types", owner, repo }); if (result && !result.isError && result.content) { const textContent = result.content.find( (c: { type: string }) => c.type === "text" From 9c484399821eb21327309be176f9fdea97b9c6f6 Mon Sep 17 00:00:00 2001 From: Garrett Bjerkhoel Date: Thu, 12 Nov 2026 11:39:24 -0800 Subject: [PATCH 3/4] Describe issue metadata owners as users or organizations Tool descriptions, toolset instructions, the README, and toolsnaps said issue types and fields belong to an organization. Describe the owner as a user or organization, and note that ui_get takes an optional repo for issue_types. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 48ff87e1-24bb-49f1-887f-9f2576ab0c2d --- README.md | 12 ++++++------ pkg/github/__toolsnaps__/issue_write.snap | 4 ++-- pkg/github/__toolsnaps__/list_issue_fields.snap | 6 +++--- pkg/github/__toolsnaps__/list_issue_types.snap | 6 +++--- pkg/github/__toolsnaps__/set_issue_fields.snap | 2 +- pkg/github/__toolsnaps__/ui_get.snap | 2 +- pkg/github/issue_fields.go | 6 +++--- pkg/github/issues.go | 10 +++++----- pkg/github/issues_granular.go | 2 +- pkg/github/toolset_instructions.go | 2 +- pkg/github/ui_tools.go | 2 +- 11 files changed, 27 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 432541f434..46d3b72818 100644 --- a/README.md +++ b/README.md @@ -750,7 +750,7 @@ For negotiated supported protocol versions `2026-07-28` or newer, the consolidat - **OAuth Challenge Scopes**: `repo`, `read:org` - `method`: The type of data to fetch (string, required) - `owner`: Repository owner (required for all methods) (string, required) - - `repo`: Repository name (required for labels, assignees, milestones, branches, issue fields, reviewers) (string, optional) + - `repo`: Repository name (required for labels, assignees, milestones, branches, issue fields, reviewers; optional for issue types) (string, optional) @@ -1041,17 +1041,17 @@ For negotiated supported protocol versions `2026-07-28` or newer, the consolidat - `state`: New state (string, optional) - `state_reason`: Reason for the state change. Ignored unless state is changed. (string, optional) - `title`: Issue title (string, optional) - - `type`: Type of this issue. For updates, pass null to remove the current type. Only use if issue types are enabled for this repository. Use list_issue_types to get valid type values for this repository or its owner organization. If the repository doesn't support issue types, omit this parameter. (string | null, optional) + - `type`: Type of this issue. For updates, pass null to remove the current type. Only use if issue types are enabled for this repository. Use list_issue_types to get valid type values for this repository or its owner. If the repository doesn't support issue types, omit this parameter. (string | null, optional) - **list_issue_fields** - List issue fields - **OAuth Challenge Scopes**: `repo`, `read:org` - - `owner`: The account owner of the repository or organization. The name is not case sensitive. (string, required) - - `repo`: The name of the repository. When provided, returns fields for this specific repository (inherited from its organization). When omitted, returns org-level fields directly. (string, optional) + - `owner`: The account owner of the repository (user or organization). The name is not case sensitive. (string, required) + - `repo`: The name of the repository. When provided, returns fields for this specific repository (inherited from its owner). When omitted, returns the owner's fields directly. (string, optional) - **list_issue_types** - List available issue types - **OAuth Challenge Scopes**: `repo`, `read:org` - - `owner`: The account owner of the repository or organization. (string, required) - - `repo`: The name of the repository. When provided, returns issue types for this specific repository. When omitted, returns org-level issue types directly. (string, optional) + - `owner`: The account owner of the repository (user or organization). (string, required) + - `repo`: The name of the repository. When provided, returns issue types for this specific repository. When omitted, returns the owner's issue types directly. (string, optional) - **list_issues** - List issues - **OAuth Challenge Scopes**: `repo` diff --git a/pkg/github/__toolsnaps__/issue_write.snap b/pkg/github/__toolsnaps__/issue_write.snap index dde73657f6..850025a986 100644 --- a/pkg/github/__toolsnaps__/issue_write.snap +++ b/pkg/github/__toolsnaps__/issue_write.snap @@ -41,7 +41,7 @@ "type": "boolean" }, "field_name": { - "description": "Issue field name (case-insensitive). Must match a field returned by list_issue_fields for this repository or its organization.", + "description": "Issue field name (case-insensitive). Must match a field returned by list_issue_fields for this repository or its owner.", "type": "string" }, "field_option_name": { @@ -139,7 +139,7 @@ "type": "null" } ], - "description": "Type of this issue. For updates, pass null to remove the current type. Only use if issue types are enabled for this repository. Use list_issue_types to get valid type values for this repository or its owner organization. If the repository doesn't support issue types, omit this parameter." + "description": "Type of this issue. For updates, pass null to remove the current type. Only use if issue types are enabled for this repository. Use list_issue_types to get valid type values for this repository or its owner. If the repository doesn't support issue types, omit this parameter." } }, "required": [ diff --git a/pkg/github/__toolsnaps__/list_issue_fields.snap b/pkg/github/__toolsnaps__/list_issue_fields.snap index f9744d009e..b88917b4e1 100644 --- a/pkg/github/__toolsnaps__/list_issue_fields.snap +++ b/pkg/github/__toolsnaps__/list_issue_fields.snap @@ -4,15 +4,15 @@ "readOnlyHint": true, "title": "List issue fields" }, - "description": "List issue fields for a repository or organization. Returns field definitions including name, type (text, number, date, single_select), and for single_select fields the list of valid option names. When repo is omitted, returns org-level fields directly.", + "description": "List issue fields for a repository or its owner (user or organization). Returns field definitions including name, type (text, number, date, single_select), and for single_select fields the list of valid option names. When repo is omitted, returns the owner's fields directly, which works for organizations and the authenticated user.", "inputSchema": { "properties": { "owner": { - "description": "The account owner of the repository or organization. The name is not case sensitive.", + "description": "The account owner of the repository (user or organization). The name is not case sensitive.", "type": "string" }, "repo": { - "description": "The name of the repository. When provided, returns fields for this specific repository (inherited from its organization). When omitted, returns org-level fields directly.", + "description": "The name of the repository. When provided, returns fields for this specific repository (inherited from its owner). When omitted, returns the owner's fields directly.", "type": "string" } }, diff --git a/pkg/github/__toolsnaps__/list_issue_types.snap b/pkg/github/__toolsnaps__/list_issue_types.snap index 8f95717e09..1611f3b85f 100644 --- a/pkg/github/__toolsnaps__/list_issue_types.snap +++ b/pkg/github/__toolsnaps__/list_issue_types.snap @@ -4,15 +4,15 @@ "readOnlyHint": true, "title": "List available issue types" }, - "description": "List supported issue types for a repository or its owner organization. When repo is omitted, returns org-level issue types directly.", + "description": "List supported issue types for a repository or its owner (user or organization). When repo is omitted, returns the owner's issue types directly, which works for organizations and the authenticated user.", "inputSchema": { "properties": { "owner": { - "description": "The account owner of the repository or organization.", + "description": "The account owner of the repository (user or organization).", "type": "string" }, "repo": { - "description": "The name of the repository. When provided, returns issue types for this specific repository. When omitted, returns org-level issue types directly.", + "description": "The name of the repository. When provided, returns issue types for this specific repository. When omitted, returns the owner's issue types directly.", "type": "string" } }, diff --git a/pkg/github/__toolsnaps__/set_issue_fields.snap b/pkg/github/__toolsnaps__/set_issue_fields.snap index 64b2731bea..2c99a69d4f 100644 --- a/pkg/github/__toolsnaps__/set_issue_fields.snap +++ b/pkg/github/__toolsnaps__/set_issue_fields.snap @@ -6,7 +6,7 @@ "readOnlyHint": false, "title": "Set Issue Fields" }, - "description": "Set issue field values for an issue. Fields are organization-level custom fields (text, number, date, or single select). Use this to create or update field values on an issue.", + "description": "Set issue field values for an issue. Fields are custom fields (text, number, date, or single select) defined by the repository owner (user or organization). Use this to create or update field values on an issue.", "icons": [ { "mimeType": "image/png", diff --git a/pkg/github/__toolsnaps__/ui_get.snap b/pkg/github/__toolsnaps__/ui_get.snap index 012089497f..4f400590b9 100644 --- a/pkg/github/__toolsnaps__/ui_get.snap +++ b/pkg/github/__toolsnaps__/ui_get.snap @@ -32,7 +32,7 @@ "type": "string" }, "repo": { - "description": "Repository name (required for labels, assignees, milestones, branches, issue fields, reviewers)", + "description": "Repository name (required for labels, assignees, milestones, branches, issue fields, reviewers; optional for issue types)", "type": "string" } }, diff --git a/pkg/github/issue_fields.go b/pkg/github/issue_fields.go index 56c79bbaf9..aa48b5df8e 100644 --- a/pkg/github/issue_fields.go +++ b/pkg/github/issue_fields.go @@ -116,7 +116,7 @@ func ListIssueFields(t translations.TranslationHelperFunc) inventory.ServerTool ToolsetMetadataIssues, mcp.Tool{ Name: "list_issue_fields", - Description: t("TOOL_LIST_ISSUE_FIELDS_DESCRIPTION", "List issue fields for a repository or organization. Returns field definitions including name, type (text, number, date, single_select), and for single_select fields the list of valid option names. When repo is omitted, returns org-level fields directly."), + Description: t("TOOL_LIST_ISSUE_FIELDS_DESCRIPTION", "List issue fields for a repository or its owner (user or organization). Returns field definitions including name, type (text, number, date, single_select), and for single_select fields the list of valid option names. When repo is omitted, returns the owner's fields directly, which works for organizations and the authenticated user."), Annotations: &mcp.ToolAnnotations{ Title: t("TOOL_LIST_ISSUE_FIELDS_USER_TITLE", "List issue fields"), ReadOnlyHint: true, @@ -126,11 +126,11 @@ func ListIssueFields(t translations.TranslationHelperFunc) inventory.ServerTool Properties: map[string]*jsonschema.Schema{ "owner": { Type: "string", - Description: "The account owner of the repository or organization. The name is not case sensitive.", + Description: "The account owner of the repository (user or organization). The name is not case sensitive.", }, "repo": { Type: "string", - Description: "The name of the repository. When provided, returns fields for this specific repository (inherited from its organization). When omitted, returns org-level fields directly.", + Description: "The name of the repository. When provided, returns fields for this specific repository (inherited from its owner). When omitted, returns the owner's fields directly.", }, }, Required: []string{"owner"}, diff --git a/pkg/github/issues.go b/pkg/github/issues.go index fb3c29e8c1..69e12e31ee 100644 --- a/pkg/github/issues.go +++ b/pkg/github/issues.go @@ -1298,7 +1298,7 @@ func ListIssueTypes(t translations.TranslationHelperFunc) inventory.ServerTool { ToolsetMetadataIssues, mcp.Tool{ Name: "list_issue_types", - Description: t("TOOL_LIST_ISSUE_TYPES_FOR_ORG", "List supported issue types for a repository or its owner organization. When repo is omitted, returns org-level issue types directly."), + Description: t("TOOL_LIST_ISSUE_TYPES_FOR_ORG", "List supported issue types for a repository or its owner (user or organization). When repo is omitted, returns the owner's issue types directly, which works for organizations and the authenticated user."), Annotations: &mcp.ToolAnnotations{ Title: t("TOOL_LIST_ISSUE_TYPES_USER_TITLE", "List available issue types"), ReadOnlyHint: true, @@ -1308,11 +1308,11 @@ func ListIssueTypes(t translations.TranslationHelperFunc) inventory.ServerTool { Properties: map[string]*jsonschema.Schema{ "owner": { Type: "string", - Description: "The account owner of the repository or organization.", + Description: "The account owner of the repository (user or organization).", }, "repo": { Type: "string", - Description: "The name of the repository. When provided, returns issue types for this specific repository. When omitted, returns org-level issue types directly.", + Description: "The name of the repository. When provided, returns issue types for this specific repository. When omitted, returns the owner's issue types directly.", }, }, Required: []string{"owner"}, @@ -2735,7 +2735,7 @@ Options are: {Type: "string", MinLength: new(1)}, {Type: "null"}, }, - Description: "Type of this issue. For updates, pass null to remove the current type. Only use if issue types are enabled for this repository. Use list_issue_types to get valid type values for this repository or its owner organization. If the repository doesn't support issue types, omit this parameter.", + Description: "Type of this issue. For updates, pass null to remove the current type. Only use if issue types are enabled for this repository. Use list_issue_types to get valid type values for this repository or its owner. If the repository doesn't support issue types, omit this parameter.", }, "state": { Type: "string", @@ -2761,7 +2761,7 @@ Options are: "field_name": { Type: "string", Description: "Issue field name (case-insensitive). Must match a field " + - "returned by list_issue_fields for this repository or its organization.", + "returned by list_issue_fields for this repository or its owner.", }, "value": { Types: []string{"string", "number", "boolean"}, diff --git a/pkg/github/issues_granular.go b/pkg/github/issues_granular.go index eab4a204cd..d96268ddd0 100644 --- a/pkg/github/issues_granular.go +++ b/pkg/github/issues_granular.go @@ -978,7 +978,7 @@ func GranularSetIssueFields(t translations.TranslationHelperFunc) inventory.Serv ToolsetMetadataIssues, mcp.Tool{ Name: "set_issue_fields", - Description: t("TOOL_SET_ISSUE_FIELDS_DESCRIPTION", "Set issue field values for an issue. Fields are organization-level custom fields (text, number, date, or single select). Use this to create or update field values on an issue."), + Description: t("TOOL_SET_ISSUE_FIELDS_DESCRIPTION", "Set issue field values for an issue. Fields are custom fields (text, number, date, or single select) defined by the repository owner (user or organization). Use this to create or update field values on an issue."), Annotations: &mcp.ToolAnnotations{ Title: t("TOOL_SET_ISSUE_FIELDS_USER_TITLE", "Set Issue Fields"), ReadOnlyHint: false, diff --git a/pkg/github/toolset_instructions.go b/pkg/github/toolset_instructions.go index b282d42806..cbbe78339c 100644 --- a/pkg/github/toolset_instructions.go +++ b/pkg/github/toolset_instructions.go @@ -12,7 +12,7 @@ func generateContextToolsetInstructions(_ *inventory.Inventory) string { func generateIssuesToolsetInstructions(_ *inventory.Inventory) string { return `## Issues -Check 'list_issue_types' first for organizations to use proper issue types. Use 'search_issues' before creating new issues to avoid duplicates. Always set 'state_reason' when closing issues.` +Check 'list_issue_types' first to use the issue types defined by the repository owner (user or organization). Use 'search_issues' before creating new issues to avoid duplicates. Always set 'state_reason' when closing issues.` } func generatePullRequestsToolsetInstructions(inv *inventory.Inventory) string { diff --git a/pkg/github/ui_tools.go b/pkg/github/ui_tools.go index 21ac969199..b93006fa1c 100644 --- a/pkg/github/ui_tools.go +++ b/pkg/github/ui_tools.go @@ -60,7 +60,7 @@ func UIGet(t translations.TranslationHelperFunc) inventory.ServerTool { }, "repo": { Type: "string", - Description: "Repository name (required for labels, assignees, milestones, branches, issue fields, reviewers)", + Description: "Repository name (required for labels, assignees, milestones, branches, issue fields, reviewers; optional for issue types)", }, }, Required: []string{"method", "owner"}, From 00176ccdf21eed9f8bf617665146b0aaae034c73 Mon Sep 17 00:00:00 2001 From: Garrett Bjerkhoel Date: Thu, 12 Nov 2026 11:46:34 -0800 Subject: [PATCH 4/4] Don't echo the owner argument in the user owner error resolveIssueMetadataScope put the raw owner argument into the tool error it returns for another user's account. owner comes from the model, and go-github doesn't escape it in the users/{owner} path, so a value like "octocat?x=..." still resolves to a real user and its extra text would reach the model verbatim. Refer to "the owner" instead, since the model already knows what it passed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 48ff87e1-24bb-49f1-887f-9f2576ab0c2d --- pkg/github/issue_fields_test.go | 7 ++++++- pkg/github/issue_metadata_scope.go | 8 ++++---- pkg/github/issues_test.go | 7 ++++++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/pkg/github/issue_fields_test.go b/pkg/github/issue_fields_test.go index 39e1806448..5bfc0504b8 100644 --- a/pkg/github/issue_fields_test.go +++ b/pkg/github/issue_fields_test.go @@ -55,6 +55,7 @@ func Test_ListIssueFields(t *testing.T) { expectError bool expectedFields []IssueField expectedErrMsg string + notInErrMsg string }{ { name: "no fields returns empty list", @@ -238,7 +239,8 @@ func Test_ListIssueFields(t *testing.T) { mockVars: map[string]any{"login": githubv4.String("hubot")}, gqlResponse: githubv4mock.ErrorResponse("FORBIDDEN"), expectError: true, - expectedErrMsg: "Pass repo to list them for one of hubot's repositories", + expectedErrMsg: "Pass repo to list them for one of the owner's repositories", + notInErrMsg: "hubot", }, { name: "number field returned", @@ -336,6 +338,9 @@ func Test_ListIssueFields(t *testing.T) { require.True(t, result.IsError) errorContent := getErrorResult(t, result) assert.Contains(t, errorContent.Text, tc.expectedErrMsg) + if tc.notInErrMsg != "" { + assert.NotContains(t, errorContent.Text, tc.notInErrMsg, "the error must not echo untrusted input") + } return } diff --git a/pkg/github/issue_metadata_scope.go b/pkg/github/issue_metadata_scope.go index 60fd3f8526..fdf1ec4c49 100644 --- a/pkg/github/issue_metadata_scope.go +++ b/pkg/github/issue_metadata_scope.go @@ -53,10 +53,10 @@ func resolveIssueMetadataScope(ctx context.Context, client *github.Client, owner return scope, ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to get authenticated user", resp, err) } if !strings.EqualFold(viewer.GetLogin(), owner) { - return scope, utils.NewToolResultError(fmt.Sprintf( - "%s is a user account, and GitHub lists a user's issue types and fields only to that user. Pass repo to list them for one of %s's repositories.", - owner, owner, - )) + // owner is untrusted model input, so the error doesn't echo it. + return scope, utils.NewToolResultError( + "The owner is a user account other than the authenticated user, and GitHub lists a user's issue types and fields only to that user. Pass repo to list them for one of the owner's repositories.", + ) } scope.Kind = issueMetadataViewer return scope, nil diff --git a/pkg/github/issues_test.go b/pkg/github/issues_test.go index 3e3ea056dc..b07f66a13f 100644 --- a/pkg/github/issues_test.go +++ b/pkg/github/issues_test.go @@ -7332,6 +7332,7 @@ func Test_ListIssueTypes(t *testing.T) { expectError bool expectedIssueTypes []*github.IssueType expectedErrMsg string + notInErrMsg string }{ { name: "organization owner lists organization issue types", @@ -7376,7 +7377,8 @@ func Test_ListIssueTypes(t *testing.T) { "owner": "hubot", }, expectError: true, - expectedErrMsg: "Pass repo to list them for one of hubot's repositories", + expectedErrMsg: "Pass repo to list them for one of the owner's repositories", + notInErrMsg: "hubot", }, { name: "owner not found", @@ -7462,6 +7464,9 @@ func Test_ListIssueTypes(t *testing.T) { require.True(t, result.IsError) errorContent := getErrorResult(t, result) assert.Contains(t, errorContent.Text, tc.expectedErrMsg) + if tc.notInErrMsg != "" { + assert.NotContains(t, errorContent.Text, tc.notInErrMsg, "the error must not echo untrusted input") + } return }