@kya-os/mcp-i-cloudflare 1.5.10-canary.9 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +130 -0
- package/dist/__tests__/e2e/test-config.d.ts +37 -0
- package/dist/__tests__/e2e/test-config.d.ts.map +1 -0
- package/dist/__tests__/e2e/test-config.js +62 -0
- package/dist/__tests__/e2e/test-config.js.map +1 -0
- package/dist/adapter.d.ts +44 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +712 -112
- package/dist/adapter.js.map +1 -1
- package/dist/agent.d.ts +117 -25
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +664 -40
- package/dist/agent.js.map +1 -1
- package/dist/app.d.ts +0 -8
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +348 -119
- package/dist/app.js.map +1 -1
- package/dist/cache/kv-oauth-config-cache.d.ts +47 -0
- package/dist/cache/kv-oauth-config-cache.d.ts.map +1 -0
- package/dist/cache/kv-oauth-config-cache.js +82 -0
- package/dist/cache/kv-oauth-config-cache.js.map +1 -0
- package/dist/cache/kv-tool-protection-cache.d.ts +26 -1
- package/dist/cache/kv-tool-protection-cache.d.ts.map +1 -1
- package/dist/cache/kv-tool-protection-cache.js +19 -11
- package/dist/cache/kv-tool-protection-cache.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +39 -14
- package/dist/config.js.map +1 -1
- package/dist/helpers/env-mapper.d.ts +60 -1
- package/dist/helpers/env-mapper.d.ts.map +1 -1
- package/dist/helpers/env-mapper.js +136 -6
- package/dist/helpers/env-mapper.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -3
- package/dist/index.js.map +1 -1
- package/dist/runtime/audit-logger.d.ts +96 -0
- package/dist/runtime/audit-logger.d.ts.map +1 -0
- package/dist/runtime/audit-logger.js +276 -0
- package/dist/runtime/audit-logger.js.map +1 -0
- package/dist/runtime/oauth-handler.d.ts +5 -0
- package/dist/runtime/oauth-handler.d.ts.map +1 -1
- package/dist/runtime/oauth-handler.js +287 -35
- package/dist/runtime/oauth-handler.js.map +1 -1
- package/dist/runtime.d.ts +12 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +34 -4
- package/dist/runtime.js.map +1 -1
- package/dist/server.d.ts +7 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +120 -29
- package/dist/server.js.map +1 -1
- package/dist/services/admin.service.d.ts +1 -3
- package/dist/services/admin.service.d.ts.map +1 -1
- package/dist/services/admin.service.js +175 -146
- package/dist/services/admin.service.js.map +1 -1
- package/dist/services/consent-audit.service.d.ts +91 -0
- package/dist/services/consent-audit.service.d.ts.map +1 -0
- package/dist/services/consent-audit.service.js +243 -0
- package/dist/services/consent-audit.service.js.map +1 -0
- package/dist/services/consent-config.service.d.ts +2 -2
- package/dist/services/consent-config.service.d.ts.map +1 -1
- package/dist/services/consent-config.service.js +55 -28
- package/dist/services/consent-config.service.js.map +1 -1
- package/dist/services/consent-page-renderer.d.ts +14 -0
- package/dist/services/consent-page-renderer.d.ts.map +1 -1
- package/dist/services/consent-page-renderer.js +54 -27
- package/dist/services/consent-page-renderer.js.map +1 -1
- package/dist/services/consent.service.d.ts +93 -8
- package/dist/services/consent.service.d.ts.map +1 -1
- package/dist/services/consent.service.js +1817 -553
- package/dist/services/consent.service.js.map +1 -1
- package/dist/services/delegation.service.d.ts.map +1 -1
- package/dist/services/delegation.service.js +67 -29
- package/dist/services/delegation.service.js.map +1 -1
- package/dist/services/idp-token-storage.d.ts +68 -0
- package/dist/services/idp-token-storage.d.ts.map +1 -0
- package/dist/services/idp-token-storage.js +157 -0
- package/dist/services/idp-token-storage.js.map +1 -0
- package/dist/services/oauth-service.d.ts +66 -0
- package/dist/services/oauth-service.d.ts.map +1 -0
- package/dist/services/oauth-service.js +223 -0
- package/dist/services/oauth-service.js.map +1 -0
- package/dist/services/proof.service.d.ts +8 -6
- package/dist/services/proof.service.d.ts.map +1 -1
- package/dist/services/proof.service.js +131 -75
- package/dist/services/proof.service.js.map +1 -1
- package/dist/services/tool-context-builder.d.ts +55 -0
- package/dist/services/tool-context-builder.d.ts.map +1 -0
- package/dist/services/tool-context-builder.js +124 -0
- package/dist/services/tool-context-builder.js.map +1 -0
- package/dist/types/tool-context.d.ts +35 -0
- package/dist/types/tool-context.d.ts.map +1 -0
- package/dist/types/tool-context.js +13 -0
- package/dist/types/tool-context.js.map +1 -0
- package/dist/types.d.ts +31 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/oauth-service-registry.d.ts +65 -0
- package/dist/utils/oauth-service-registry.d.ts.map +1 -0
- package/dist/utils/oauth-service-registry.js +125 -0
- package/dist/utils/oauth-service-registry.js.map +1 -0
- package/package.json +27 -60
package/README.md
CHANGED
|
@@ -16,6 +16,8 @@ This package provides a Next.js-style architecture for building MCP-I agents on
|
|
|
16
16
|
- ✅ **Session Management**: Stateless sessions with nonce protection
|
|
17
17
|
- ✅ **KV Storage**: Use Workers KV for nonce cache and identity
|
|
18
18
|
- ✅ **Audit Logging**: Track all operations with configurable logging
|
|
19
|
+
- ✅ **CSRF Protection**: Secure OAuth state validation with server-side storage
|
|
20
|
+
- ✅ **Security Event Logging**: Comprehensive observability for security events
|
|
19
21
|
|
|
20
22
|
## Quick Start
|
|
21
23
|
|
|
@@ -306,6 +308,134 @@ Admin endpoints for cache management (optional, requires `admin.enabled: true`).
|
|
|
306
308
|
|
|
307
309
|
OAuth callback handler for delegation flow.
|
|
308
310
|
|
|
311
|
+
## Security Features
|
|
312
|
+
|
|
313
|
+
### CSRF Protection for OAuth Flows
|
|
314
|
+
|
|
315
|
+
The framework includes built-in CSRF (Cross-Site Request Forgery) protection for OAuth authorization flows. This prevents attackers from tricking users into authorizing unintended actions.
|
|
316
|
+
|
|
317
|
+
#### How It Works
|
|
318
|
+
|
|
319
|
+
1. **State Generation**: When initiating an OAuth flow, the framework generates a cryptographically secure random state value (32 bytes).
|
|
320
|
+
|
|
321
|
+
2. **Secure Storage**: The state value and associated OAuth parameters (project ID, agent DID, session ID, etc.) are stored securely in KV storage with a 10-minute TTL.
|
|
322
|
+
|
|
323
|
+
3. **State Validation**: On OAuth callback, the framework retrieves and validates the state from secure storage before processing the authorization code.
|
|
324
|
+
|
|
325
|
+
4. **One-Time Use**: State values are deleted immediately after retrieval, preventing replay attacks.
|
|
326
|
+
|
|
327
|
+
5. **CSRF Detection**: If the state is missing, expired, or invalid, the callback is rejected with a clear error message indicating a potential CSRF attack.
|
|
328
|
+
|
|
329
|
+
#### Configuration
|
|
330
|
+
|
|
331
|
+
CSRF protection is automatically enabled when `DELEGATION_STORAGE` KV namespace is configured. Optional token encryption can be enabled by setting `OAUTH_ENCRYPTION_SECRET`:
|
|
332
|
+
|
|
333
|
+
```bash
|
|
334
|
+
# wrangler.toml
|
|
335
|
+
[env.production.vars]
|
|
336
|
+
OAUTH_ENCRYPTION_SECRET = "your-encryption-secret-here"
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
#### Backward Compatibility
|
|
340
|
+
|
|
341
|
+
If `OAuthSecurityService` is not available (e.g., `DELEGATION_STORAGE` not configured), the framework falls back to base64-encoded state parameters. This maintains backward compatibility but provides less security. **For production deployments, always configure `DELEGATION_STORAGE`.**
|
|
342
|
+
|
|
343
|
+
#### Example
|
|
344
|
+
|
|
345
|
+
```typescript
|
|
346
|
+
// OAuth URL generation (automatic CSRF protection)
|
|
347
|
+
const oauthUrl = await consentService.buildOAuthUrl(
|
|
348
|
+
projectId,
|
|
349
|
+
agentDid,
|
|
350
|
+
sessionId,
|
|
351
|
+
scopes,
|
|
352
|
+
serverUrl,
|
|
353
|
+
oauthSecurityService // Automatically created if DELEGATION_STORAGE is configured
|
|
354
|
+
);
|
|
355
|
+
|
|
356
|
+
// OAuth callback (automatic CSRF validation)
|
|
357
|
+
const handler = createOAuthCallbackHandler({
|
|
358
|
+
agentShieldApiUrl: env.AGENTSHIELD_API_URL,
|
|
359
|
+
delegationStorage: env.DELEGATION_STORAGE,
|
|
360
|
+
oauthSecurityService, // Automatically created if DELEGATION_STORAGE is configured
|
|
361
|
+
});
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
### Security Event Logging
|
|
365
|
+
|
|
366
|
+
All security-critical events are logged with structured data for monitoring and observability. Security events are prefixed with `🔒 SECURITY EVENT:` for easy filtering.
|
|
367
|
+
|
|
368
|
+
#### Logged Events
|
|
369
|
+
|
|
370
|
+
- **OAuth Provider Errors**: Errors returned by OAuth providers
|
|
371
|
+
- **CSRF Protection**: State validation success/failure, expired states, invalid states
|
|
372
|
+
- **OAuth Code Exchange**: Token exchange start, success, and failure
|
|
373
|
+
- **Delegation Storage**: Token storage events (user+agent scoped, legacy, session cache)
|
|
374
|
+
- **OAuth Identity Linking**: User DID linking with OAuth identities
|
|
375
|
+
- **Storage Errors**: Non-fatal storage errors that don't block operations
|
|
376
|
+
|
|
377
|
+
#### Log Format
|
|
378
|
+
|
|
379
|
+
All security events include:
|
|
380
|
+
|
|
381
|
+
```typescript
|
|
382
|
+
{
|
|
383
|
+
timestamp: string; // ISO timestamp
|
|
384
|
+
eventType: string; // Event type identifier (e.g., 'csrf_protection_failed')
|
|
385
|
+
severity?: 'error' | 'warning' | 'info';
|
|
386
|
+
// ... event-specific fields
|
|
387
|
+
}
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
#### Example Logs
|
|
391
|
+
|
|
392
|
+
```javascript
|
|
393
|
+
// CSRF protection success
|
|
394
|
+
[OAuth] 🔒 SECURITY EVENT: State validated successfully: {
|
|
395
|
+
projectId: 'project-123',
|
|
396
|
+
agentDid: 'did:key:z6Mk...',
|
|
397
|
+
sessionId: 'session-123...',
|
|
398
|
+
timestamp: '2025-01-21T10:30:00.000Z',
|
|
399
|
+
eventType: 'csrf_protection_success'
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// CSRF attack detected
|
|
403
|
+
[OAuth] 🔒 SECURITY EVENT: State validation failed - state not found or expired: {
|
|
404
|
+
stateParam: 'invalid-state-value...',
|
|
405
|
+
timestamp: '2025-01-21T10:30:00.000Z',
|
|
406
|
+
eventType: 'csrf_protection_failed',
|
|
407
|
+
reason: 'state_not_found_or_expired'
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// Delegation token stored
|
|
411
|
+
[OAuth] 🔒 SECURITY EVENT: Delegation token stored with user+agent DID: {
|
|
412
|
+
key: 'delegation:user:did:key:z6Mk...',
|
|
413
|
+
ttl: 604800,
|
|
414
|
+
agentDid: 'did:key:z6Mk...',
|
|
415
|
+
userDid: 'did:key:z6Mk...',
|
|
416
|
+
timestamp: '2025-01-21T10:30:00.000Z',
|
|
417
|
+
eventType: 'delegation_token_stored',
|
|
418
|
+
storageType: 'user_agent_scoped'
|
|
419
|
+
}
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
#### Monitoring
|
|
423
|
+
|
|
424
|
+
Security events can be monitored using:
|
|
425
|
+
|
|
426
|
+
- **Cloudflare Workers Logs**: View logs in real-time with `wrangler tail`
|
|
427
|
+
- **Log Aggregation**: Forward logs to external services (Datadog, Splunk, etc.)
|
|
428
|
+
- **Alerting**: Set up alerts for critical security events (CSRF failures, token exchange failures)
|
|
429
|
+
|
|
430
|
+
#### Privacy
|
|
431
|
+
|
|
432
|
+
All security logs redact sensitive information:
|
|
433
|
+
|
|
434
|
+
- DIDs are truncated (first 20 characters + "...")
|
|
435
|
+
- Tokens are never logged in full
|
|
436
|
+
- OAuth subjects are hashed or truncated
|
|
437
|
+
- PII is redacted before logging
|
|
438
|
+
|
|
309
439
|
## Migration from v1.x
|
|
310
440
|
|
|
311
441
|
If you're upgrading from v1.x, see the migration guide below.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* E2E Test Configuration
|
|
3
|
+
*
|
|
4
|
+
* This file contains configuration for end-to-end tests that use real AgentShield API.
|
|
5
|
+
* Set these environment variables before running E2E tests:
|
|
6
|
+
*
|
|
7
|
+
* ```bash
|
|
8
|
+
* export E2E_AGENTSHIELD_API_KEY="sk_test_..."
|
|
9
|
+
* export E2E_AGENTSHIELD_PROJECT_ID="test-project-id"
|
|
10
|
+
* export E2E_AGENTSHIELD_API_URL="https://kya.vouched.id" # Optional, defaults to production
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Or create a `.env.e2e` file in the package root:
|
|
14
|
+
* ```
|
|
15
|
+
* E2E_AGENTSHIELD_API_KEY=sk_test_...
|
|
16
|
+
* E2E_AGENTSHIELD_PROJECT_ID=test-project-id
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export interface E2ETestConfig {
|
|
20
|
+
apiKey: string;
|
|
21
|
+
projectId: string;
|
|
22
|
+
apiUrl: string;
|
|
23
|
+
enabled: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Load E2E test configuration from environment variables
|
|
27
|
+
*/
|
|
28
|
+
export declare function loadE2EConfig(): E2ETestConfig | null;
|
|
29
|
+
/**
|
|
30
|
+
* Check if E2E tests should run
|
|
31
|
+
*/
|
|
32
|
+
export declare function shouldRunE2ETests(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Get E2E test configuration or throw if not configured
|
|
35
|
+
*/
|
|
36
|
+
export declare function getE2EConfig(): E2ETestConfig;
|
|
37
|
+
//# sourceMappingURL=test-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-config.d.ts","sourceRoot":"","sources":["../../../src/__tests__/e2e/test-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAWH,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,aAAa,GAAG,IAAI,CAyBpD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAG3C;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,aAAa,CAU5C"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* E2E Test Configuration
|
|
3
|
+
*
|
|
4
|
+
* This file contains configuration for end-to-end tests that use real AgentShield API.
|
|
5
|
+
* Set these environment variables before running E2E tests:
|
|
6
|
+
*
|
|
7
|
+
* ```bash
|
|
8
|
+
* export E2E_AGENTSHIELD_API_KEY="sk_test_..."
|
|
9
|
+
* export E2E_AGENTSHIELD_PROJECT_ID="test-project-id"
|
|
10
|
+
* export E2E_AGENTSHIELD_API_URL="https://kya.vouched.id" # Optional, defaults to production
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Or create a `.env.e2e` file in the package root:
|
|
14
|
+
* ```
|
|
15
|
+
* E2E_AGENTSHIELD_API_KEY=sk_test_...
|
|
16
|
+
* E2E_AGENTSHIELD_PROJECT_ID=test-project-id
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Load E2E test configuration from environment variables
|
|
21
|
+
*/
|
|
22
|
+
export function loadE2EConfig() {
|
|
23
|
+
// Access environment variables - works in Node.js (vitest) environment
|
|
24
|
+
const apiKey = typeof process !== "undefined" && process.env
|
|
25
|
+
? process.env.E2E_AGENTSHIELD_API_KEY
|
|
26
|
+
: undefined;
|
|
27
|
+
const projectId = typeof process !== "undefined" && process.env
|
|
28
|
+
? process.env.E2E_AGENTSHIELD_PROJECT_ID
|
|
29
|
+
: undefined;
|
|
30
|
+
const apiUrl = typeof process !== "undefined" && process.env
|
|
31
|
+
? process.env.E2E_AGENTSHIELD_API_URL || "https://kya.vouched.id"
|
|
32
|
+
: "https://kya.vouched.id";
|
|
33
|
+
if (!apiKey || !projectId) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
apiKey,
|
|
38
|
+
projectId,
|
|
39
|
+
apiUrl,
|
|
40
|
+
enabled: true,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Check if E2E tests should run
|
|
45
|
+
*/
|
|
46
|
+
export function shouldRunE2ETests() {
|
|
47
|
+
const config = loadE2EConfig();
|
|
48
|
+
return config !== null && config.enabled;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get E2E test configuration or throw if not configured
|
|
52
|
+
*/
|
|
53
|
+
export function getE2EConfig() {
|
|
54
|
+
const config = loadE2EConfig();
|
|
55
|
+
if (!config) {
|
|
56
|
+
throw new Error("E2E tests require E2E_AGENTSHIELD_API_KEY and E2E_AGENTSHIELD_PROJECT_ID environment variables.\n" +
|
|
57
|
+
"Set them in your environment or create a .env.e2e file.\n" +
|
|
58
|
+
"See packages/mcp-i-cloudflare/src/__tests__/e2e/test-config.ts for details.");
|
|
59
|
+
}
|
|
60
|
+
return config;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=test-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-config.js","sourceRoot":"","sources":["../../../src/__tests__/e2e/test-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAkBH;;GAEG;AACH,MAAM,UAAU,aAAa;IAC3B,uEAAuE;IACvE,MAAM,MAAM,GACV,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG;QAC3C,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB;QACrC,CAAC,CAAC,SAAS,CAAC;IAChB,MAAM,SAAS,GACb,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG;QAC3C,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,0BAA0B;QACxC,CAAC,CAAC,SAAS,CAAC;IAChB,MAAM,MAAM,GACV,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG;QAC3C,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,IAAI,wBAAwB;QACjE,CAAC,CAAC,wBAAwB,CAAC;IAE/B,IAAI,CAAC,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,MAAM;QACN,SAAS;QACT,MAAM;QACN,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB;IAC/B,MAAM,MAAM,GAAG,aAAa,EAAE,CAAC;IAC/B,OAAO,MAAM,KAAK,IAAI,IAAI,MAAM,CAAC,OAAO,CAAC;AAC3C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY;IAC1B,MAAM,MAAM,GAAG,aAAa,EAAE,CAAC;IAC/B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,mGAAmG;YACjG,2DAA2D;YAC3D,6EAA6E,CAChF,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/adapter.d.ts
CHANGED
|
@@ -18,12 +18,41 @@ export interface ToolDefinition {
|
|
|
18
18
|
inputSchema: any;
|
|
19
19
|
handler: (args: any) => Promise<any>;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Configuration for creating an MCP-I Cloudflare adapter
|
|
23
|
+
*
|
|
24
|
+
* @property envPrefix - Optional prefix for KV bindings (e.g., "_17429" or "MYAPP").
|
|
25
|
+
* If provided, KV bindings will be mapped from `{prefix}_NONCE_CACHE` to `NONCE_CACHE`.
|
|
26
|
+
* If not provided, auto-detection will attempt to find the prefix.
|
|
27
|
+
* Use this when deploying multiple agents in the same Cloudflare account to avoid KV namespace conflicts.
|
|
28
|
+
*/
|
|
21
29
|
export interface MCPICloudflareAdapterConfig extends MCPICloudflareConfig {
|
|
22
30
|
serverInfo?: {
|
|
23
31
|
name: string;
|
|
24
32
|
version: string;
|
|
25
33
|
};
|
|
26
34
|
tools?: ToolDefinition[];
|
|
35
|
+
/**
|
|
36
|
+
* Optional prefix for KV bindings to support multi-agent deployments
|
|
37
|
+
*
|
|
38
|
+
* When multiple MCP-I agents are deployed in the same Cloudflare account,
|
|
39
|
+
* KV namespace bindings must be unique. Use a prefix to namespace your bindings:
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* // wrangler.toml
|
|
44
|
+
* [[kv_namespaces]]
|
|
45
|
+
* binding = "_17429_NONCE_CACHE"
|
|
46
|
+
*
|
|
47
|
+
* // src/index.ts
|
|
48
|
+
* const adapter = createMCPICloudflareAdapter({
|
|
49
|
+
* env,
|
|
50
|
+
* envPrefix: "_17429", // Maps _17429_NONCE_CACHE → NONCE_CACHE
|
|
51
|
+
* // ...
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
envPrefix?: string;
|
|
27
56
|
}
|
|
28
57
|
interface RequestMeta {
|
|
29
58
|
fingerprint?: string;
|
|
@@ -31,7 +60,6 @@ interface RequestMeta {
|
|
|
31
60
|
ip?: string;
|
|
32
61
|
cfRay?: string;
|
|
33
62
|
request?: Request;
|
|
34
|
-
serverOrigin?: string;
|
|
35
63
|
}
|
|
36
64
|
interface JsonRpcRequest {
|
|
37
65
|
jsonrpc: string;
|
|
@@ -79,6 +107,19 @@ declare class CloudflareMCPServer {
|
|
|
79
107
|
* @returns OAuthIdentity or null
|
|
80
108
|
*/
|
|
81
109
|
private extractOAuthIdentityFromRequest;
|
|
110
|
+
/**
|
|
111
|
+
* Validate OAuth identity format and content
|
|
112
|
+
*
|
|
113
|
+
* Ensures:
|
|
114
|
+
* - Provider is non-empty string (1-50 chars)
|
|
115
|
+
* - Subject is non-empty string (1-255 chars)
|
|
116
|
+
* - Provider matches expected format (alphanumeric, hyphens, underscores)
|
|
117
|
+
* - Subject matches expected format (non-empty, reasonable length)
|
|
118
|
+
*
|
|
119
|
+
* @param identity - Parsed OAuth identity object
|
|
120
|
+
* @returns Validation result
|
|
121
|
+
*/
|
|
122
|
+
private validateOAuthIdentity;
|
|
82
123
|
}
|
|
83
124
|
/**
|
|
84
125
|
* Create a complete MCP-I handler for Cloudflare Workers
|
|
@@ -86,6 +127,8 @@ declare class CloudflareMCPServer {
|
|
|
86
127
|
*
|
|
87
128
|
* Supports SSE (Server-Sent Events) and HTTP JSON-RPC transports for compatibility
|
|
88
129
|
* with Claude Desktop, Cursor, MCP Inspector, and other MCP clients.
|
|
130
|
+
*
|
|
131
|
+
* Automatically handles prefixed KV bindings via `envPrefix` parameter or auto-detection.
|
|
89
132
|
*/
|
|
90
133
|
export declare function createMCPICloudflareAdapter(config: MCPICloudflareAdapterConfig): {
|
|
91
134
|
server: CloudflareMCPServer;
|
package/dist/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,oBAAoB,EAAiB,MAAM,SAAS,CAAC;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAM1D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,oBAAoB,EAAiB,MAAM,SAAS,CAAC;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAM1D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAW7D,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,C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