- Notifications
You must be signed in to change notification settings - Fork1.1k
Feature/chewy standards tool#510
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1100,3 +1100,158 @@ func GetTag(getClient GetClientFn, t translations.TranslationHelperFunc) (tool m | ||||||||||||||
return mcp.NewToolResultText(string(r)), nil | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
// GetChewyStandards creates a tool to get development standards from Chewy's repository. | ||||||||||||||
func GetChewyStandards(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { | ||||||||||||||
return mcp.NewTool("get_chewy_standards", | ||||||||||||||
mcp.WithDescription(t("TOOL_GET_CHEWY_STANDARDS_DESCRIPTION", "Get development standards and guidelines from Chewy's repository")), | ||||||||||||||
mcp.WithToolAnnotation(mcp.ToolAnnotation{ | ||||||||||||||
Title: t("TOOL_GET_CHEWY_STANDARDS_USER_TITLE", "Get Chewy development standards"), | ||||||||||||||
ReadOnlyHint: toBoolPtr(true), | ||||||||||||||
}), | ||||||||||||||
mcp.WithString("owner", | ||||||||||||||
mcp.Description("Repository owner (defaults to Chewy-Inc)"), | ||||||||||||||
), | ||||||||||||||
mcp.WithString("repo", | ||||||||||||||
mcp.Description("Repository name containing development standards (defaults to chewy-tech-standards)"), | ||||||||||||||
), | ||||||||||||||
mcp.WithString("standards_path", | ||||||||||||||
mcp.Description("Path to standards directory or file (defaults to searching the entire repository)"), | ||||||||||||||
), | ||||||||||||||
mcp.WithString("ref", | ||||||||||||||
mcp.Description("Git reference (branch, tag, or commit SHA) to get standards from (defaults to main/master)"), | ||||||||||||||
), | ||||||||||||||
), | ||||||||||||||
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { | ||||||||||||||
owner, err := OptionalParam[string](request, "owner") | ||||||||||||||
if err != nil { | ||||||||||||||
return mcp.NewToolResultError(err.Error()), nil | ||||||||||||||
} | ||||||||||||||
if owner == "" { | ||||||||||||||
owner = "Chewy-Inc" | ||||||||||||||
} | ||||||||||||||
repo, err := OptionalParam[string](request, "repo") | ||||||||||||||
if err != nil { | ||||||||||||||
return mcp.NewToolResultError(err.Error()), nil | ||||||||||||||
} | ||||||||||||||
if repo == "" { | ||||||||||||||
repo = "chewy-tech-standards" | ||||||||||||||
} | ||||||||||||||
standardsPath, err := OptionalParam[string](request, "standards_path") | ||||||||||||||
if err != nil { | ||||||||||||||
return mcp.NewToolResultError(err.Error()), nil | ||||||||||||||
} | ||||||||||||||
ref, err := OptionalParam[string](request, "ref") | ||||||||||||||
if err != nil { | ||||||||||||||
return mcp.NewToolResultError(err.Error()), nil | ||||||||||||||
} | ||||||||||||||
client, err := getClient(ctx) | ||||||||||||||
if err != nil { | ||||||||||||||
return nil, fmt.Errorf("failed to get GitHub client: %w", err) | ||||||||||||||
} | ||||||||||||||
// If a specific path is provided, use it; otherwise search the whole repository | ||||||||||||||
var pathsToSearch []string | ||||||||||||||
var searchWholeRepo bool | ||||||||||||||
if standardsPath != "" { | ||||||||||||||
pathsToSearch = []string{standardsPath} | ||||||||||||||
searchWholeRepo = false | ||||||||||||||
} else { | ||||||||||||||
// Search the whole repository (starting from root) | ||||||||||||||
pathsToSearch = []string{""} | ||||||||||||||
searchWholeRepo = true | ||||||||||||||
} | ||||||||||||||
var results []map[string]interface{} | ||||||||||||||
opts := &github.RepositoryContentGetOptions{Ref: ref} | ||||||||||||||
if searchWholeRepo { | ||||||||||||||
// Get the entire repository tree | ||||||||||||||
tree, resp, err := client.Git.GetTree(ctx, owner, repo, "HEAD", true) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Use the user-provided Suggested change
Copilot uses AI. Check for mistakes. | ||||||||||||||
if err != nil { | ||||||||||||||
return mcp.NewToolResultError(fmt.Sprintf("Failed to get repository tree: %v", err)), nil | ||||||||||||||
} | ||||||||||||||
if resp != nil { | ||||||||||||||
defer func() { _ = resp.Body.Close() }() | ||||||||||||||
} | ||||||||||||||
if resp.StatusCode == 200 && tree != nil { | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Add a check for non-200 responses from Suggested change
Copilot uses AI. Check for mistakes. | ||||||||||||||
results = append(results, map[string]interface{}{ | ||||||||||||||
"path": "", | ||||||||||||||
"type": "repository", | ||||||||||||||
"content": tree, | ||||||||||||||
"source_repo": fmt.Sprintf("%s/%s", owner, repo), | ||||||||||||||
"reference": ref, | ||||||||||||||
}) | ||||||||||||||
} | ||||||||||||||
} else { | ||||||||||||||
// Search specific paths | ||||||||||||||
for _, path := range pathsToSearch { | ||||||||||||||
fileContent, dirContent, resp, err := client.Repositories.GetContents(ctx, owner, repo, path, opts) | ||||||||||||||
if err != nil { | ||||||||||||||
// Continue to next path if this one doesn't exist | ||||||||||||||
continue | ||||||||||||||
} | ||||||||||||||
if resp != nil { | ||||||||||||||
defer func() { _ = resp.Body.Close() }() | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Avoid deferring Copilot uses AI. Check for mistakes. | ||||||||||||||
} | ||||||||||||||
if resp.StatusCode == 200 { | ||||||||||||||
var content interface{} | ||||||||||||||
var contentType string | ||||||||||||||
var actualPath string | ||||||||||||||
if fileContent != nil { | ||||||||||||||
content = fileContent | ||||||||||||||
contentType = "file" | ||||||||||||||
actualPath = path | ||||||||||||||
} else if dirContent != nil { | ||||||||||||||
content = dirContent | ||||||||||||||
contentType = "directory" | ||||||||||||||
actualPath = path | ||||||||||||||
} | ||||||||||||||
if content != nil { | ||||||||||||||
results = append(results, map[string]interface{}{ | ||||||||||||||
"path": actualPath, | ||||||||||||||
"type": contentType, | ||||||||||||||
"content": content, | ||||||||||||||
"source_repo": fmt.Sprintf("%s/%s", owner, repo), | ||||||||||||||
"reference": ref, | ||||||||||||||
}) | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
if len(results) == 0 { | ||||||||||||||
return mcp.NewToolResultError("No development standards found in the specified repository. Try specifying a custom standards_path or ensure the repository contains standard documentation."), nil | ||||||||||||||
} | ||||||||||||||
// Create a structured response | ||||||||||||||
searchNote := "This tool searched the entire repository for development standards." | ||||||||||||||
if !searchWholeRepo { | ||||||||||||||
searchNote = "This tool searched the specified path for development standards. Leave 'standards_path' empty to search the entire repository." | ||||||||||||||
} | ||||||||||||||
response := map[string]interface{}{ | ||||||||||||||
"chewy_org": owner, | ||||||||||||||
"repository": repo, | ||||||||||||||
"reference": ref, | ||||||||||||||
"standards_found": len(results), | ||||||||||||||
"standards": results, | ||||||||||||||
"search_note": searchNote, | ||||||||||||||
} | ||||||||||||||
r, err := json.Marshal(response) | ||||||||||||||
if err != nil { | ||||||||||||||
return nil, fmt.Errorf("failed to marshal response: %w", err) | ||||||||||||||
} | ||||||||||||||
return mcp.NewToolResultText(string(r)), nil | ||||||||||||||
} | ||||||||||||||
} |
Uh oh!
There was an error while loading.Please reload this page.