e5d69a5188
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
Build and Test Go Project / build (macos-latest) (push) Has been cancelled
Build and Test Go Project / build (ubuntu-latest) (push) Has been cancelled
Build and Test Go Project / build (windows-latest) (push) Has been cancelled
License Check / license-check (push) Has been cancelled
61 lines
2.4 KiB
Go
61 lines
2.4 KiB
Go
package github
|
|
|
|
import (
|
|
"os"
|
|
"slices"
|
|
"strings"
|
|
)
|
|
|
|
// GenerateInstructions creates server instructions based on enabled toolsets
|
|
func GenerateInstructions(enabledToolsets []string) string {
|
|
// For testing - add a flag to disable instructions
|
|
if os.Getenv("DISABLE_INSTRUCTIONS") == "true" {
|
|
return "" // Baseline mode
|
|
}
|
|
|
|
var instructions []string
|
|
|
|
// Core instruction - always included if context toolset enabled
|
|
if slices.Contains(enabledToolsets, "context") {
|
|
instructions = append(instructions, "Always call 'get_me' first to understand current user permissions and context.")
|
|
}
|
|
|
|
// Individual toolset instructions
|
|
for _, toolset := range enabledToolsets {
|
|
if inst := getToolsetInstructions(toolset); inst != "" {
|
|
instructions = append(instructions, inst)
|
|
}
|
|
}
|
|
|
|
// Base instruction with context management
|
|
baseInstruction := `The GitHub MCP Server provides tools to interact with GitHub platform.
|
|
|
|
Tool selection guidance:
|
|
1. Use 'list_*' tools for broad, simple retrieval and pagination of all items of a type (e.g., all issues, all PRs, all branches) with basic filtering.
|
|
2. Use 'search_*' tools for targeted queries with specific criteria, keywords, or complex filters (e.g., issues with certain text, PRs by author, code containing functions).
|
|
|
|
Context management:
|
|
1. Use pagination whenever possible with batches of 5-10 items.
|
|
2. Use minimal_output parameter set to true if the full information is not needed to accomplish a task.`
|
|
|
|
allInstructions := []string{baseInstruction}
|
|
allInstructions = append(allInstructions, instructions...)
|
|
|
|
return strings.Join(allInstructions, " ")
|
|
}
|
|
|
|
// getToolsetInstructions returns specific instructions for individual toolsets
|
|
func getToolsetInstructions(toolset string) string {
|
|
switch toolset {
|
|
case "pull_requests":
|
|
return "## Pull Requests\n\nPR review workflow: Always use 'create_pending_pull_request_review' → 'add_comment_to_pending_review' → 'submit_pending_pull_request_review' for complex reviews with line-specific comments."
|
|
case "issues":
|
|
return "## Issues\n\nCheck '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."
|
|
case "discussions":
|
|
return "## Discussions\n\nUse 'list_discussion_categories' to understand available categories before creating discussions. Filter by category for better organization."
|
|
default:
|
|
return ""
|
|
}
|
|
}
|
|
|