-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Add list_issue_fields tool #2445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
kelsey-myers
wants to merge
12
commits into
github:main
Choose a base branch
from
kelsey-myers:mj/add-list-org-issue-fields
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3d71005
Add list_org_issue_fields tool
michaeljacholke 98b5647
Clean up code
michaeljacholke df12a08
complete struct fields & rename option type
michaeljacholke f5942f3
Drop created_at/updated_at from IssueField and IssueSingleSelectField…
kelsey-myers 8bd698b
Address feedback
kelsey-myers a6d1f6e
Address Copilot review: close resp.Body, set expectError=true for mis…
kelsey-myers e2bb101
Merge branch 'main' into mj/add-list-org-issue-fields
kelsey-myers abc5398
Adjust to list_issue_fields
kelsey-myers 0fd7142
Add feature flag
kelsey-myers 20d45e2
Allow tool to support read:org or repo
kelsey-myers 2bbee8b
Docs
kelsey-myers 8922132
address comments
kelsey-myers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "annotations": { | ||
| "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.", | ||
| "inputSchema": { | ||
| "properties": { | ||
| "owner": { | ||
| "description": "The account owner of the repository 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.", | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "owner" | ||
| ], | ||
| "type": "object" | ||
| }, | ||
| "name": "list_issue_fields" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,223 @@ | ||
| package github | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| ghcontext "github.com/github/github-mcp-server/pkg/context" | ||
| ghErrors "github.com/github/github-mcp-server/pkg/errors" | ||
| "github.com/github/github-mcp-server/pkg/inventory" | ||
| "github.com/github/github-mcp-server/pkg/scopes" | ||
| "github.com/github/github-mcp-server/pkg/translations" | ||
| "github.com/github/github-mcp-server/pkg/utils" | ||
| "github.com/google/jsonschema-go/jsonschema" | ||
| "github.com/modelcontextprotocol/go-sdk/mcp" | ||
| "github.com/shurcooL/githubv4" | ||
| ) | ||
|
|
||
| // IssueField represents a repository issue field definition. | ||
| type IssueField struct { | ||
| ID string `json:"id"` | ||
| Name string `json:"name"` | ||
| Description string `json:"description,omitempty"` | ||
| DataType string `json:"data_type"` | ||
| Visibility string `json:"visibility"` | ||
| Options []IssueSingleSelectFieldOption `json:"options,omitempty"` | ||
| } | ||
|
|
||
| // IssueSingleSelectFieldOption represents an option for a single_select issue field. | ||
| type IssueSingleSelectFieldOption struct { | ||
| ID string `json:"id"` | ||
| Name string `json:"name"` | ||
| Description string `json:"description,omitempty"` | ||
| Color string `json:"color"` | ||
| Priority *int `json:"priority,omitempty"` | ||
| } | ||
|
|
||
| // issueFieldNode is the GraphQL fragment for a single issue field in the IssueFields union. | ||
| // Only the fragment matching __typename is populated; read from the matching fragment. | ||
| type issueFieldNode struct { | ||
| TypeName githubv4.String `graphql:"__typename"` | ||
| IssueFieldText struct { | ||
| ID githubv4.ID | ||
| Name githubv4.String | ||
| Description githubv4.String | ||
| DataType githubv4.String | ||
| Visibility githubv4.String | ||
| } `graphql:"... on IssueFieldText"` | ||
| IssueFieldNumber struct { | ||
| ID githubv4.ID | ||
| Name githubv4.String | ||
| Description githubv4.String | ||
| DataType githubv4.String | ||
| Visibility githubv4.String | ||
| } `graphql:"... on IssueFieldNumber"` | ||
| IssueFieldDate struct { | ||
| ID githubv4.ID | ||
| Name githubv4.String | ||
| Description githubv4.String | ||
| DataType githubv4.String | ||
| Visibility githubv4.String | ||
| } `graphql:"... on IssueFieldDate"` | ||
| IssueFieldSingleSelect struct { | ||
| ID githubv4.ID | ||
| Name githubv4.String | ||
| Description githubv4.String | ||
| DataType githubv4.String | ||
| Visibility githubv4.String | ||
| Options []struct { | ||
| ID githubv4.ID | ||
| Name githubv4.String | ||
| Description githubv4.String | ||
| Color githubv4.String | ||
| Priority *int | ||
| } | ||
| } `graphql:"... on IssueFieldSingleSelect"` | ||
| } | ||
|
|
||
| // issueFieldsRepoQuery is the GraphQL query for listing issue fields on a repository. | ||
| type issueFieldsRepoQuery struct { | ||
| Repository struct { | ||
| IssueFields struct { | ||
| Nodes []issueFieldNode | ||
| } `graphql:"issueFields(first: 100)"` | ||
| } `graphql:"repository(owner: $owner, name: $name)"` | ||
| } | ||
|
|
||
| // issueFieldsOrgQuery is the GraphQL query for listing issue fields on an organization. | ||
| type issueFieldsOrgQuery struct { | ||
| Organization struct { | ||
| IssueFields struct { | ||
| Nodes []issueFieldNode | ||
| } `graphql:"issueFields(first: 100)"` | ||
| } `graphql:"organization(login: $login)"` | ||
| } | ||
|
|
||
| // ListIssueFields creates a tool to list issue field definitions for a repository or organization. | ||
| func ListIssueFields(t translations.TranslationHelperFunc) inventory.ServerTool { | ||
| return NewTool( | ||
| 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."), | ||
| Annotations: &mcp.ToolAnnotations{ | ||
|
kelsey-myers marked this conversation as resolved.
|
||
| Title: t("TOOL_LIST_ISSUE_FIELDS_USER_TITLE", "List issue fields"), | ||
| ReadOnlyHint: true, | ||
| }, | ||
| InputSchema: &jsonschema.Schema{ | ||
| Type: "object", | ||
| Properties: map[string]*jsonschema.Schema{ | ||
| "owner": { | ||
| Type: "string", | ||
| Description: "The account owner of the repository 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.", | ||
| }, | ||
| }, | ||
| Required: []string{"owner"}, | ||
| }, | ||
| }, | ||
| []scopes.Scope{scopes.Repo, scopes.ReadOrg}, | ||
| func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) { | ||
| owner, err := RequiredParam[string](args, "owner") | ||
| if err != nil { | ||
| return utils.NewToolResultError(err.Error()), nil, nil | ||
| } | ||
| repo, err := OptionalParam[string](args, "repo") | ||
| if err != nil { | ||
| return utils.NewToolResultError(err.Error()), nil, nil | ||
| } | ||
|
|
||
| gqlClient, err := deps.GetGQLClient(ctx) | ||
| if err != nil { | ||
| return utils.NewToolResultErrorFromErr("failed to get GitHub GraphQL client", err), nil, nil | ||
| } | ||
|
|
||
| ctxWithFeatures := ghcontext.WithGraphQLFeatures(ctx, "issue_fields") | ||
| var nodes []issueFieldNode | ||
| if repo != "" { | ||
| var query issueFieldsRepoQuery | ||
| vars := map[string]any{ | ||
| "owner": githubv4.String(owner), | ||
| "name": githubv4.String(repo), | ||
| } | ||
| if err := gqlClient.Query(ctxWithFeatures, &query, vars); err != nil { | ||
| return ghErrors.NewGitHubGraphQLErrorResponse(ctx, "failed to list issue fields", err), nil, nil | ||
| } | ||
| nodes = query.Repository.IssueFields.Nodes | ||
| } else { | ||
| var query issueFieldsOrgQuery | ||
| vars := map[string]any{ | ||
| "login": githubv4.String(owner), | ||
| } | ||
| if err := gqlClient.Query(ctxWithFeatures, &query, vars); err != nil { | ||
| return ghErrors.NewGitHubGraphQLErrorResponse(ctx, "failed to list issue fields", err), nil, nil | ||
| } | ||
|
kelsey-myers marked this conversation as resolved.
|
||
| nodes = query.Organization.IssueFields.Nodes | ||
| } | ||
|
|
||
| fields := make([]IssueField, 0, len(nodes)) | ||
| for _, node := range nodes { | ||
| var f IssueField | ||
| // Read from the fragment matching __typename; the other fragments are zero-valued. | ||
| switch string(node.TypeName) { | ||
| case "IssueFieldSingleSelect": | ||
| opts := make([]IssueSingleSelectFieldOption, 0, len(node.IssueFieldSingleSelect.Options)) | ||
| for _, o := range node.IssueFieldSingleSelect.Options { | ||
| opts = append(opts, IssueSingleSelectFieldOption{ | ||
| ID: fmt.Sprintf("%v", o.ID), | ||
| Name: string(o.Name), | ||
| Description: string(o.Description), | ||
| Color: string(o.Color), | ||
| Priority: o.Priority, | ||
| }) | ||
| } | ||
| f = IssueField{ | ||
| ID: fmt.Sprintf("%v", node.IssueFieldSingleSelect.ID), | ||
| Name: string(node.IssueFieldSingleSelect.Name), | ||
| Description: string(node.IssueFieldSingleSelect.Description), | ||
| DataType: string(node.IssueFieldSingleSelect.DataType), | ||
| Visibility: string(node.IssueFieldSingleSelect.Visibility), | ||
| Options: opts, | ||
| } | ||
| case "IssueFieldText": | ||
| f = IssueField{ | ||
| ID: fmt.Sprintf("%v", node.IssueFieldText.ID), | ||
| Name: string(node.IssueFieldText.Name), | ||
| Description: string(node.IssueFieldText.Description), | ||
| DataType: string(node.IssueFieldText.DataType), | ||
| Visibility: string(node.IssueFieldText.Visibility), | ||
| } | ||
| case "IssueFieldNumber": | ||
| f = IssueField{ | ||
| ID: fmt.Sprintf("%v", node.IssueFieldNumber.ID), | ||
| Name: string(node.IssueFieldNumber.Name), | ||
| Description: string(node.IssueFieldNumber.Description), | ||
| DataType: string(node.IssueFieldNumber.DataType), | ||
| Visibility: string(node.IssueFieldNumber.Visibility), | ||
| } | ||
| case "IssueFieldDate": | ||
| f = IssueField{ | ||
| ID: fmt.Sprintf("%v", node.IssueFieldDate.ID), | ||
| Name: string(node.IssueFieldDate.Name), | ||
| Description: string(node.IssueFieldDate.Description), | ||
| DataType: string(node.IssueFieldDate.DataType), | ||
| Visibility: string(node.IssueFieldDate.Visibility), | ||
| } | ||
| default: | ||
| continue | ||
| } | ||
| fields = append(fields, f) | ||
| } | ||
|
|
||
| r, err := json.Marshal(fields) | ||
| if err != nil { | ||
| return utils.NewToolResultErrorFromErr("failed to marshal issue fields", err), nil, nil | ||
| } | ||
|
|
||
| return utils.NewToolResultText(string(r)), nil, nil | ||
| }) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.