Skip to content

Commit d32b528

Browse files
sridharavinashtoby
authored andcommitted
feat: require GitHub Client ID environment variable for publshing
1 parent 6b72032 commit d32b528

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

tools/publisher/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ The tool uses GitHub device flow authentication:
4141
3. After successful authentication, the tool saves the token locally for future use
4242
4. The token is sent in the HTTP Authorization header with the Bearer scheme
4343

44+
### Required Environment Variable
45+
46+
Before using the GitHub authentication, you need to set the following environment variable:
47+
48+
```bash
49+
export MCP_REGISTRY_GITHUB_CLIENT_ID="your_github_client_id"
50+
```
51+
52+
This environment variable is required for the GitHub device flow authentication. If not set, the authentication will fail.
53+
4454
_NOTE_ : Authentication is made on behalf of a OAuth App which you must authorize for respective resources (e.g `org`)
4555

4656
## Example
@@ -91,6 +101,10 @@ _NOTE_ : Authentication is made on behalf of a OAuth App which you must authoriz
91101
2. Run the publisher tool:
92102

93103
```bash
104+
# First, set the required environment variable
105+
export MCP_REGISTRY_GITHUB_CLIENT_ID="your_github_client_id"
106+
107+
# Then run the publisher tool
94108
./bin/mcp-publisher --registry-url "https://mcp-registry.example.com" --mcp-file "./mcp.json"
95109
```
96110

@@ -100,6 +114,7 @@ _NOTE_ : Authentication is made on behalf of a OAuth App which you must authoriz
100114

101115
## Important Notes
102116

117+
- The `MCP_REGISTRY_GITHUB_CLIENT_ID` environment variable must be set for GitHub authentication
103118
- The authentication token is saved in a file named `.mcpregistry_token` in the current directory
104119
- The tool requires an active internet connection to authenticate with GitHub and communicate with the registry
105120
- Make sure the repository and package mentioned in your `mcp.json` file exist and are accessible

tools/publisher/main.go

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import (
1515
const (
1616
tokenFilePath = ".mcpregistry_token"
1717

18-
// TODO: Replace this with the official owned OAuth client ID
19-
GithubClientID = "Ov23ct0x1531TPL3WJ9h"
20-
2118
// GitHub OAuth URLs
2219
GitHubDeviceCodeURL = "https://github.com/login/device/code"
2320
GitHubAccessTokenURL = "https://github.com/login/oauth/access_token"
21+
22+
// Environment variable for GitHub Client ID
23+
EnvGithubClientID = "MCP_REGISTRY_GITHUB_CLIENT_ID"
2424
)
2525

2626
// DeviceCodeResponse represents the response from GitHub's device code endpoint
@@ -58,6 +58,19 @@ func main() {
5858
return
5959
}
6060

61+
// Check for GitHub client ID in environment if we're going to need it for authentication
62+
if providedToken == "" && os.Getenv(EnvGithubClientID) == "" {
63+
fmt.Printf("Warning: Environment variable %s is not set. This is required for GitHub authentication.\n", EnvGithubClientID)
64+
fmt.Println("You can set it with: export " + EnvGithubClientID + "=your_github_client_id")
65+
fmt.Println("Or provide a token directly with the --token flag.")
66+
67+
// Only return if we'll need to do GitHub auth
68+
_, statErr := os.Stat(tokenFilePath)
69+
if forceLogin || os.IsNotExist(statErr) {
70+
return
71+
}
72+
}
73+
6174
var token string
6275

6376
// If a token is provided via the command line, use it
@@ -101,6 +114,11 @@ func main() {
101114
}
102115

103116
func performDeviceFlowLogin() error {
117+
// Check if the environment variable is set
118+
if os.Getenv(EnvGithubClientID) == "" {
119+
return fmt.Errorf("environment variable %s must be set for GitHub authentication", EnvGithubClientID)
120+
}
121+
104122
// Device flow login logic using GitHub's device flow
105123
// First, request a device code
106124
deviceCode, userCode, verificationURI, err := requestDeviceCode()
@@ -133,8 +151,13 @@ func performDeviceFlowLogin() error {
133151

134152
// requestDeviceCode initiates the device authorization flow
135153
func requestDeviceCode() (string, string, string, error) {
154+
clientID := os.Getenv(EnvGithubClientID)
155+
if clientID == "" {
156+
return "", "", "", fmt.Errorf("environment variable %s is not set", EnvGithubClientID)
157+
}
158+
136159
payload := map[string]string{
137-
"client_id": GithubClientID,
160+
"client_id": clientID,
138161
"scope": "read:org read:user",
139162
}
140163

@@ -177,8 +200,13 @@ func requestDeviceCode() (string, string, string, error) {
177200

178201
// pollForToken polls for access token after user completes authorization
179202
func pollForToken(deviceCode string) (string, error) {
203+
clientID := os.Getenv(EnvGithubClientID)
204+
if clientID == "" {
205+
return "", fmt.Errorf("environment variable %s is not set", EnvGithubClientID)
206+
}
207+
180208
payload := map[string]string{
181-
"client_id": GithubClientID,
209+
"client_id": clientID,
182210
"device_code": deviceCode,
183211
"grant_type": "urn:ietf:params:oauth:grant-type:device_code",
184212
}

0 commit comments

Comments
 (0)