Skip to content

Commit 9094dc2

Browse files
committed
✨ feat: add GitHub token input and improve IP retrieval
- Updated `.mcp.json` to include a new input for GitHub personal access token, marked as a password. - Added server configuration for GitHub to run a Docker-based MCP server with the token as an environment variable. - Enhanced IP address retrieval in `Program.cs` by checking the "CF-Connecting-IP" header first, improving accuracy when requests are routed through Cloudflare. If the header is absent or invalid, it falls back to the original method.
1 parent 9acf9a1 commit 9094dc2

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

.mcp.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"inputs": [
3+
{
4+
"id": "github_pat",
5+
"description": "GitHub personal access token",
6+
"type": "promptString",
7+
"password": true
8+
}
9+
],
10+
"servers": {
11+
"github": {
12+
"type": "stdio",
13+
"command": "docker",
14+
"args": [
15+
"run",
16+
"-i",
17+
"--rm",
18+
"-e",
19+
"GITHUB_PERSONAL_ACCESS_TOKEN",
20+
"ghcr.io/github/github-mcp-server"
21+
],
22+
"env": {
23+
"GITHUB_PERSONAL_ACCESS_TOKEN": "${input:github_pat}"
24+
}
25+
}
26+
}
27+
}

src/API/UrlShortener.Server/Program.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,17 @@ await shortUrlService.DeleteShortUrl(new DeleteShortUrlRequest()
131131
{
132132
var defaultUrlForRedirect = configuration.GetValue<string>("DefaultUrlForRedirect") ??
133133
throw new InvalidOperationException();
134-
IPAddress? ipAddress = httpContextAccessor?.HttpContext?.Connection?.RemoteIpAddress;
134+
// Try to get the real client IP from Cloudflare header first
135+
string? cfConnectingIp = httpContextAccessor?.HttpContext?.Request?.Headers["CF-Connecting-IP"].FirstOrDefault();
136+
IPAddress? ipAddress = null;
137+
if (!string.IsNullOrWhiteSpace(cfConnectingIp) && IPAddress.TryParse(cfConnectingIp, out var parsedIp))
138+
{
139+
ipAddress = parsedIp;
140+
}
141+
else
142+
{
143+
ipAddress = httpContextAccessor?.HttpContext?.Connection?.RemoteIpAddress;
144+
}
135145
var uaString = httpContextAccessor?.HttpContext?.Request?.Headers["User-Agent"].ToString();
136146
var uaParser = Parser.GetDefault();
137147
ClientInfo c = uaParser.Parse(uaString);

0 commit comments

Comments
 (0)