Skip to content

Commit 2b36a5a

Browse files
authored
Merge branch 'main' into add-get-project-tool
2 parents 1568a48 + 0a1d6db commit 2b36a5a

File tree

7 files changed

+373
-2
lines changed

7 files changed

+373
-2
lines changed

.github/workflows/docker-publish.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ on:
1414
tags: ["v*.*.*"]
1515
pull_request:
1616
branches: ["main", "next"]
17+
workflow_dispatch:
18+
inputs:
19+
description:
20+
required: false
21+
description: "Description of the run."
22+
type: string
23+
default: "Manual run"
1724

1825
env:
1926
# Use docker.io for Docker Hub if empty
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Publish to MCP Registry
2+
3+
on:
4+
push:
5+
tags: ["v*"] # Triggers on version tags like v1.0.0
6+
workflow_dispatch: # Allow manual triggering
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
id-token: write # Required for OIDC authentication
13+
contents: read
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v5
18+
19+
- name: Fetch tags
20+
run: git fetch --tags
21+
22+
- name: Install MCP Publisher
23+
run: |
24+
curl -L "https://github.com/modelcontextprotocol/registry/releases/download/v1.0.0/mcp-publisher_1.0.0_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/').tar.gz" | tar xz mcp-publisher
25+
26+
- name: Update server.json version
27+
run: |
28+
if [[ "${{ github.ref_type }}" == "tag" ]]; then
29+
# Use the tag that triggered the workflow
30+
TAG_VERSION=$(echo "${{ github.ref_name }}" | sed 's/^v//')
31+
echo "Using triggered tag: ${{ github.ref_name }}"
32+
else
33+
# Fallback to latest tag (for manual triggers)
34+
LATEST_TAG=$(git tag --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+(-.*)?$' | head -n 1)
35+
if [ -z "$LATEST_TAG" ]; then
36+
echo "❌ No release tag found. Cannot determine version."
37+
exit 1
38+
fi
39+
TAG_VERSION=$(echo "$LATEST_TAG" | sed 's/^v//')
40+
echo "Using latest tag: $LATEST_TAG"
41+
fi
42+
sed -i "s/\${VERSION}/$TAG_VERSION/g" server.json
43+
echo "Updated server.json version to $TAG_VERSION"
44+
45+
- name: Login to MCP Registry
46+
run: ./mcp-publisher login github-oidc
47+
48+
- name: Publish to MCP Registry
49+
run: ./mcp-publisher publish

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,17 @@ The following sets of tools are available (all are on by default):
10201020

10211021
</details>
10221022

1023+
<details>
1024+
1025+
<summary>Copilot Spaces</summary>
1026+
1027+
- **get_copilot_space** - Get Copilot Space
1028+
- `owner`: The owner of the space. (string, required)
1029+
- `name`: The name of the space. (string, required)
1030+
1031+
- **list_copilot_spaces** - List Copilot Spaces
1032+
</details>
1033+
10231034
#### Specifying Toolsets
10241035

10251036
To specify toolsets you want available to the LLM, you can pass an allow-list in two ways:

internal/ghmcp/server.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ func NewMCPServer(cfg MCPServerConfig) (*server.MCPServer, error) {
105105
},
106106
}
107107

108-
ghServer := github.NewServer(cfg.Version, server.WithHooks(hooks))
109-
110108
enabledToolsets := cfg.EnabledToolsets
111109
if cfg.DynamicToolsets {
112110
// filter "all" from the enabled toolsets
@@ -118,6 +116,14 @@ func NewMCPServer(cfg MCPServerConfig) (*server.MCPServer, error) {
118116
}
119117
}
120118

119+
// Generate instructions based on enabled toolsets
120+
instructions := github.GenerateInstructions(enabledToolsets)
121+
122+
ghServer := github.NewServer(cfg.Version,
123+
server.WithInstructions(instructions),
124+
server.WithHooks(hooks),
125+
)
126+
121127
getClient := func(_ context.Context) (*gogithub.Client, error) {
122128
return restClient, nil // closing over client
123129
}

pkg/github/instructions.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package github
2+
3+
import (
4+
"os"
5+
"slices"
6+
"strings"
7+
)
8+
9+
// GenerateInstructions creates server instructions based on enabled toolsets
10+
func GenerateInstructions(enabledToolsets []string) string {
11+
// For testing - add a flag to disable instructions
12+
if os.Getenv("DISABLE_INSTRUCTIONS") == "true" {
13+
return "" // Baseline mode
14+
}
15+
16+
var instructions []string
17+
18+
// Core instruction - always included if context toolset enabled
19+
if slices.Contains(enabledToolsets, "context") {
20+
instructions = append(instructions, "Always call 'get_me' first to understand current user permissions and context.")
21+
}
22+
23+
// Individual toolset instructions
24+
for _, toolset := range enabledToolsets {
25+
if inst := getToolsetInstructions(toolset); inst != "" {
26+
instructions = append(instructions, inst)
27+
}
28+
}
29+
30+
// Base instruction with context management
31+
baseInstruction := `The GitHub MCP Server provides tools to interact with GitHub platform.
32+
33+
Tool selection guidance:
34+
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.
35+
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).
36+
37+
Context management:
38+
1. Use pagination whenever possible with batches of 5-10 items.
39+
2. Use minimal_output parameter set to true if the full information is not needed to accomplish a task.`
40+
41+
allInstructions := []string{baseInstruction}
42+
allInstructions = append(allInstructions, instructions...)
43+
44+
return strings.Join(allInstructions, " ")
45+
}
46+
47+
// getToolsetInstructions returns specific instructions for individual toolsets
48+
func getToolsetInstructions(toolset string) string {
49+
switch toolset {
50+
case "pull_requests":
51+
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."
52+
case "issues":
53+
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."
54+
case "discussions":
55+
return "## Discussions\n\nUse 'list_discussion_categories' to understand available categories before creating discussions. Filter by category for better organization."
56+
default:
57+
return ""
58+
}
59+
}
60+

pkg/github/instructions_test.go

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
package github
2+
3+
import (
4+
"os"
5+
"testing"
6+
)
7+
8+
func TestGenerateInstructions(t *testing.T) {
9+
tests := []struct {
10+
name string
11+
enabledToolsets []string
12+
expectedEmpty bool
13+
}{
14+
{
15+
name: "empty toolsets",
16+
enabledToolsets: []string{},
17+
expectedEmpty: false,
18+
},
19+
{
20+
name: "only context toolset",
21+
enabledToolsets: []string{"context"},
22+
expectedEmpty: false,
23+
},
24+
{
25+
name: "pull requests toolset",
26+
enabledToolsets: []string{"pull_requests"},
27+
expectedEmpty: false,
28+
},
29+
{
30+
name: "issues toolset",
31+
enabledToolsets: []string{"issues"},
32+
expectedEmpty: false,
33+
},
34+
{
35+
name: "discussions toolset",
36+
enabledToolsets: []string{"discussions"},
37+
expectedEmpty: false,
38+
},
39+
{
40+
name: "multiple toolsets (context + pull_requests)",
41+
enabledToolsets: []string{"context", "pull_requests"},
42+
expectedEmpty: false,
43+
},
44+
{
45+
name: "multiple toolsets (issues + pull_requests)",
46+
enabledToolsets: []string{"issues", "pull_requests"},
47+
expectedEmpty: false,
48+
},
49+
}
50+
51+
for _, tt := range tests {
52+
t.Run(tt.name, func(t *testing.T) {
53+
result := GenerateInstructions(tt.enabledToolsets)
54+
55+
if tt.expectedEmpty {
56+
if result != "" {
57+
t.Errorf("Expected empty instructions but got: %s", result)
58+
}
59+
} else {
60+
if result == "" {
61+
t.Errorf("Expected non-empty instructions but got empty result")
62+
}
63+
}
64+
})
65+
}
66+
}
67+
68+
func TestGenerateInstructionsWithDisableFlag(t *testing.T) {
69+
tests := []struct {
70+
name string
71+
disableEnvValue string
72+
enabledToolsets []string
73+
expectedEmpty bool
74+
}{
75+
{
76+
name: "DISABLE_INSTRUCTIONS=true returns empty",
77+
disableEnvValue: "true",
78+
enabledToolsets: []string{"context", "issues", "pull_requests"},
79+
expectedEmpty: true,
80+
},
81+
{
82+
name: "DISABLE_INSTRUCTIONS=false returns normal instructions",
83+
disableEnvValue: "false",
84+
enabledToolsets: []string{"context"},
85+
expectedEmpty: false,
86+
},
87+
{
88+
name: "DISABLE_INSTRUCTIONS unset returns normal instructions",
89+
disableEnvValue: "",
90+
enabledToolsets: []string{"issues"},
91+
expectedEmpty: false,
92+
},
93+
}
94+
95+
for _, tt := range tests {
96+
t.Run(tt.name, func(t *testing.T) {
97+
// Save original env value
98+
originalValue := os.Getenv("DISABLE_INSTRUCTIONS")
99+
defer func() {
100+
if originalValue == "" {
101+
os.Unsetenv("DISABLE_INSTRUCTIONS")
102+
} else {
103+
os.Setenv("DISABLE_INSTRUCTIONS", originalValue)
104+
}
105+
}()
106+
107+
// Set test env value
108+
if tt.disableEnvValue == "" {
109+
os.Unsetenv("DISABLE_INSTRUCTIONS")
110+
} else {
111+
os.Setenv("DISABLE_INSTRUCTIONS", tt.disableEnvValue)
112+
}
113+
114+
result := GenerateInstructions(tt.enabledToolsets)
115+
116+
if tt.expectedEmpty {
117+
if result != "" {
118+
t.Errorf("Expected empty instructions but got: %s", result)
119+
}
120+
} else {
121+
if result == "" {
122+
t.Errorf("Expected non-empty instructions but got empty result")
123+
}
124+
}
125+
})
126+
}
127+
}
128+
129+
func TestGetToolsetInstructions(t *testing.T) {
130+
tests := []struct {
131+
toolset string
132+
expectedEmpty bool
133+
}{
134+
{
135+
toolset: "pull_requests",
136+
expectedEmpty: false,
137+
},
138+
{
139+
toolset: "issues",
140+
expectedEmpty: false,
141+
},
142+
{
143+
toolset: "discussions",
144+
expectedEmpty: false,
145+
},
146+
{
147+
toolset: "nonexistent",
148+
expectedEmpty: true,
149+
},
150+
}
151+
152+
for _, tt := range tests {
153+
t.Run(tt.toolset, func(t *testing.T) {
154+
result := getToolsetInstructions(tt.toolset)
155+
if tt.expectedEmpty {
156+
if result != "" {
157+
t.Errorf("Expected empty result for toolset '%s', but got: %s", tt.toolset, result)
158+
}
159+
} else {
160+
if result == "" {
161+
t.Errorf("Expected non-empty result for toolset '%s', but got empty", tt.toolset)
162+
}
163+
}
164+
})
165+
}
166+
}

0 commit comments

Comments
 (0)