@kya-os/mcp-i-cloudflare 1.0.0

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.
@@ -0,0 +1,72 @@
1
+ /**
2
+ * MCP-I Runtime for Cloudflare Workers
3
+ */
4
+ import { MCPIRuntimeBase } from "@kya-os/mcp-i-core/dist/runtime/base";
5
+ import { StorageProvider } from "@kya-os/mcp-i-core/dist/types/providers";
6
+ import { WebCryptoProvider } from "../providers/crypto";
7
+ import { WorkerIdentityProvider } from "../providers/identity";
8
+ import { CloudflareKVNonceCache } from "../providers/nonce-cache";
9
+ /**
10
+ * KV-based storage provider
11
+ */
12
+ class KVStorageProvider extends StorageProvider {
13
+ kv;
14
+ constructor(kv) {
15
+ super();
16
+ this.kv = kv;
17
+ }
18
+ async get(key) {
19
+ return this.kv.get(key);
20
+ }
21
+ async set(key, value, ttl) {
22
+ const options = ttl ? { expirationTtl: ttl } : undefined;
23
+ await this.kv.put(key, value, options);
24
+ }
25
+ async delete(key) {
26
+ await this.kv.delete(key);
27
+ }
28
+ async has(key) {
29
+ const value = await this.kv.get(key);
30
+ return value !== null;
31
+ }
32
+ }
33
+ /**
34
+ * MCP-I Runtime for Cloudflare Workers
35
+ */
36
+ export class MCPICloudflareRuntime extends MCPIRuntimeBase {
37
+ constructor(env) {
38
+ // Initialize with Cloudflare-specific providers
39
+ super({
40
+ cryptoProvider: new WebCryptoProvider(),
41
+ identityProvider: new WorkerIdentityProvider(env),
42
+ nonceCacheProvider: new CloudflareKVNonceCache(env.NONCE_CACHE),
43
+ storageProvider: new KVStorageProvider(env.STORAGE_KV || env.NONCE_CACHE), // Fallback to NONCE_CACHE if no dedicated storage
44
+ // Configuration from environment
45
+ session: {
46
+ timestampSkewSeconds: parseInt(env.XMCP_I_TS_SKEW_SEC || '120'),
47
+ sessionTtlMinutes: parseInt(env.XMCP_I_SESSION_TTL || '30')
48
+ }
49
+ });
50
+ }
51
+ /**
52
+ * Override session ID generation to use Web Crypto
53
+ */
54
+ async generateSessionId() {
55
+ const bytes = crypto.getRandomValues(new Uint8Array(32));
56
+ return Buffer.from(bytes).toString('base64url');
57
+ }
58
+ /**
59
+ * Override nonce generation to use Web Crypto
60
+ */
61
+ async generateNonce() {
62
+ const bytes = crypto.getRandomValues(new Uint8Array(16));
63
+ return Buffer.from(bytes).toString('base64url');
64
+ }
65
+ }
66
+ /**
67
+ * Create MCP-I server for Cloudflare Workers
68
+ */
69
+ export function createMCPIServer(env) {
70
+ return new MCPICloudflareRuntime(env);
71
+ }
72
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAiB,MAAM,uBAAuB,CAAC;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE;;GAEG;AACH,MAAM,iBAAkB,SAAQ,eAAe;IACzB;IAApB,YAAoB,EAAe;QACjC,KAAK,EAAE,CAAC;QADU,OAAE,GAAF,EAAE,CAAa;IAEnC,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,OAAO,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,KAAa,EAAE,GAAY;QAChD,MAAM,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QACzD,MAAM,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,C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;QACzD,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAClD,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAsB;IACrD,OAAO,IAAI,qBAAqB,CAAC,GAAG,CAAC,CAAC;AACxC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@kya-os/mcp-i-cloudflare",
3
+ "version": "1.0.0",
4
+ "description": "Cloudflare Workers implementation of MCP-I framework",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist/**/*",
16
+ "README.md"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsc",
20
+ "dev": "tsc --watch",
21
+ "test": "vitest",
22
+ "lint": "eslint src/**/*.ts",
23
+ "type-check": "tsc --noEmit"
24
+ },
25
+ "keywords": [
26
+ "mcp-i",
27
+ "mcp",
28
+ "identity",
29
+ "did",
30
+ "cloudflare",
31
+ "workers",
32
+ "edge"
33
+ ],
34
+ "dependencies": {
35
+ "@kya-os/mcp-i-core": "^1.0.0",
36
+ "@kya-os/contracts": "^1.2.0",
37
+ "@modelcontextprotocol/sdk": "^1.11.4"
38
+ },
39
+ "devDependencies": {
40
+ "@cloudflare/workers-types": "^4.0.0",
41
+ "@types/node": "^20.0.0",
42
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
43
+ "@typescript-eslint/parser": "^6.0.0",
44
+ "eslint": "^8.0.0",
45
+ "typescript": "^5.3.0",
46
+ "vitest": "^1.0.0",
47
+ "wrangler": "^3.0.0"
48
+ },
49
+ "engines": {
50
+ "node": ">=20.0.0"
51
+ },
52
+ "author": "MCP-I Team",
53
+ "license": "MIT",
54
+ "repository": {
55
+ "type": "git",
56
+ "url": "git+https://github.com/modelcontextprotocol-identity/mcp-i.git"
57
+ },
58
+ "bugs": {
59
+ "url": "https://github.com/modelcontextprotocol-identity/mcp-i/issues"
60
+ },
61
+ "homepage": "https://github.com/modelcontextprotocol-identity/mcp-i#readme"
62
+ }