Skip to content

Commit 64317a8

Browse files
authored
Add API token authentication and restructure MCP server (#18)
* - partially revise code structure - added tests: unit and end-to-end - updated all libraries used by the server - added the ability to access the server using a Globalping API token * spelling and logic fixes according to coderabbit review * Restore global fetch after tests to avoid side effects * client limit set to default if below 1 * removed integration and oauth flow tests * - rewritten using the official ts client - tests have been rewritten as well. Cloudflare workers only allow integration and unit tests. * format fix * fixes according coderabbit * fixes according coderrabit * fixes according coderabbit * Add GitHub Actions workflow for testing and update integration tests - Created a new workflow file for running tests on every commit - Updated tsconfig to correct the path for worker configuration. - Changed isolatedStorage setting in vitest configuration to false. * workflow fix * workflow fix * Improve API token request error handling and validation * Fix API token request authorization check to handle missing type * Add mcptotal.io to exception hosts list * Add imports for AuthRequest and PKCECodePair in layout.ts * Update configuration and dependencies; add new API route and improve token handling
1 parent 622e984 commit 64317a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+17753
-4122
lines changed

.github/workflows/test.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: ["*"]
6+
pull_request:
7+
branches: ["*"]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 10
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: "20"
22+
cache: "npm"
23+
24+
- name: Install dependencies
25+
run: npm ci
26+
27+
- name: Create .dev.vars for integration tests
28+
run: |
29+
cat > .dev.vars << 'EOF'
30+
GLOBALPING_CLIENT_ID=test-client-id
31+
GLOBALPING_API_TOKEN=test-token-for-ci-environment
32+
EOF
33+
34+
- name: Run TypeScript check
35+
run: npx tsc --noEmit
36+
37+
- name: Run unit tests
38+
run: npm run test:unit
39+
40+
- name: Run integration tests
41+
run: npm run test:integration
42+
43+
- name: Upload test results
44+
if: always()
45+
uses: actions/upload-artifact@v4
46+
with:
47+
name: test-results
48+
path: |
49+
coverage/
50+
test-results/
51+
retention-days: 7
52+
if-no-files-found: ignore

README.md

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
The Globalping MCP Server implements the [Model Context Protocol (MCP)](https://modelcontextprotocol.io), allowing AI models like OpenAI's GPT and Anthropic's Claude to interact with Globalping's network measurement capabilities through natural language.
2626

27-
It also supports oAuth authentication, which offers a secure way to interact with our API and benefits from higher rate limits associated with your account.
27+
It also supports two authentication methods: OAuth and API token authentication. Both methods offer a secure way to interact with our API and provide higher rate limits associated with your account.
2828

2929
### Key Features
3030

@@ -33,7 +33,7 @@ It also supports oAuth authentication, which offers a secure way to interact wit
3333
- 📊 **Comprehensive Measurements**: Support for ping, traceroute, DNS, MTR, and HTTP tests
3434
- 🔍 **Smart Context Handling**: Provides detailed parameter descriptions for AI clients to intelligently select measurement types and options
3535
- 🔄 **Comparative Analysis**: Allows to compare network performance between different targets
36-
- 🔑 **oAuth Support**: Use your own Globalping account for higher rate limits
36+
- 🔑 **Authentication Support**: Use OAuth or API token with your Globalping account for higher rate limits
3737

3838

3939
## Installation
@@ -129,6 +129,58 @@ Legacy SSE transport:
129129
}
130130
```
131131
5. Click "Save" and restart Cursor
132+
## Authentication
133+
134+
The Globalping MCP server supports two authentication methods:
135+
- **OAuth Authentication**: Automatically handled by the server for secure access
136+
- **API Token Authentication**: Manual token configuration via Authorization header
137+
138+
Both methods provide higher rate limits and priority access to the probe network.
139+
140+
### Using Globalping API Token
141+
142+
The server automatically detects when an API token is provided in the Authorization header and uses it for authentication instead of OAuth.
143+
144+
#### Getting Your API Token
145+
146+
1. Visit [globalping.io](https://globalping.io)
147+
2. Sign in to your account
148+
3. Navigate to your account settings to generate an API token
149+
150+
#### Configuration with Authentication
151+
152+
Streamable HTTP transport:
153+
```json
154+
{
155+
"mcpServers": {
156+
"globalping": {
157+
"command": "npx",
158+
"args": [
159+
"mcp-remote",
160+
"https://mcp.globalping.dev/mcp",
161+
"--header",
162+
"Authorization: Bearer YOUR_GLOBALPING_API_TOKEN"
163+
]
164+
}
165+
}
166+
}
167+
```
168+
Legacy SSE transport:
169+
```json
170+
{
171+
"mcpServers": {
172+
"globalping": {
173+
"command": "npx",
174+
"args": [
175+
"mcp-remote",
176+
"https://mcp.globalping.dev/sse",
177+
"--header",
178+
"Authorization: Bearer YOUR_GLOBALPING_API_TOKEN"
179+
]
180+
}
181+
}
182+
}
183+
```
132184

133185
## Connecting AI Assistants
134186

@@ -200,10 +252,14 @@ You can also combine these with a plus sign for more specific targeting: "London
200252
The codebase is organized into modules:
201253

202254
- `src/index.ts` - Main entry point and MCP agent definition
203-
- `src/globalping/types.ts` - TypeScript interfaces for the Globalping API
204-
- `src/globalping/api.ts` - API wrapper functions for Globalping
205-
- `src/globalping/tools.ts` - MCP tool implementations
206-
- `src/utils.ts` - Helper utilities for rendering the web UI
255+
- `src/app.ts` - OAuth web routes
256+
- `src/api` - Globalping API client
257+
- `src/auth` - Authentication utilities
258+
- `src/config` - Configuration and constants
259+
- `src/lib` - Utility functions
260+
- `src/mcp` - MCP tool handlers
261+
- `src/types` - TypeScript type definitions
262+
- `src/ui` - HTML templates
207263

208264

209265
### Add Globalping credentials
@@ -216,4 +272,4 @@ Add Globalping OAuth credentials:
216272
Used for `OAuthProvider` docs https://github.com/cloudflare/workers-oauth-provider
217273
- create a KV namespace and copy ID
218274
- binding for it must be `OAUTH_KV`
219-
- configure `kv_namespaces` in the `wrangler.jsonc` file
275+
- configure `kv_namespaces` in the `wrangler.jsonc` file

gemini-extension.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"name": "globalping",
3-
"version": "0.0.2",
4-
"description": "Enable AI models to interact with a global network measurement platform and run network measurements, benchmarks and tests.",
5-
"mcpServers": {
6-
"globalping-mcp": {
7-
"httpUrl": "https://mcp.globalping.dev/mcp",
8-
"oauth": {
9-
"enabled": true
10-
}
11-
}
12-
}
2+
"name": "globalping",
3+
"version": "0.0.2",
4+
"description": "Enable AI models to interact with a global network measurement platform and run network measurements, benchmarks and tests.",
5+
"mcpServers": {
6+
"globalping-mcp": {
7+
"httpUrl": "https://mcp.globalping.dev/mcp",
8+
"oauth": {
9+
"enabled": true
10+
}
11+
}
12+
}
1313
}

0 commit comments

Comments
 (0)