@kya-os/mcp-i-cloudflare 1.1.0 → 1.2.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.
- package/README.md +161 -339
- package/dist/adapter.d.ts +7 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +197 -39
- package/dist/adapter.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/storage/kv-proof-archive.d.ts +115 -0
- package/dist/storage/kv-proof-archive.d.ts.map +1 -0
- package/dist/storage/kv-proof-archive.js +264 -0
- package/dist/storage/kv-proof-archive.js.map +1 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,25 +1,41 @@
|
|
|
1
1
|
# @kya-os/mcp-i-cloudflare
|
|
2
2
|
|
|
3
|
+
> **⚠️ DEPRECATED**: This adapter does not support MCP protocol transports (SSE/HTTP streaming).
|
|
4
|
+
>
|
|
5
|
+
> **Use [McpAgent from agents/mcp](https://developers.cloudflare.com/agents/model-context-protocol/) instead.**
|
|
6
|
+
>
|
|
7
|
+
> See the [migration guide](../../CLOUDFLARE_DEPLOYMENT.md) for updated implementation patterns.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
3
11
|
Cloudflare Workers runtime for MCP-I (Model Context Protocol with Identity). Deploy cryptographically-signed MCP servers to Cloudflare's edge network with full identity support.
|
|
4
12
|
|
|
5
|
-
##
|
|
13
|
+
## Status
|
|
14
|
+
|
|
15
|
+
This package provides the MCP-I runtime layer for Cloudflare Workers but **does not** include MCP protocol transport support. For a complete MCP server implementation on Cloudflare Workers with SSE and HTTP streaming support, use the [Cloudflare Agents SDK](https://developers.cloudflare.com/agents/model-context-protocol/) with `agents/mcp`.
|
|
16
|
+
|
|
17
|
+
### What This Package Provides
|
|
6
18
|
|
|
7
|
-
- ✅ **Full MCP-I Support**: Cryptographic signing of all tool responses
|
|
8
|
-
- ✅ **Edge-Native**: Built for Cloudflare Workers with Web Crypto API
|
|
9
|
-
- ✅ **SSE Streaming**: Support for Server-Sent Events and Streamable HTTP (v1.1.0+)
|
|
10
|
-
- ✅ **Claude Desktop Compatible**: Works with mcp-remote proxy via SSE endpoints
|
|
11
19
|
- ✅ **Identity Management**: DID-based identity with Ed25519 keys
|
|
20
|
+
- ✅ **Cryptographic Proofs**: Sign tool responses with detached proofs
|
|
12
21
|
- ✅ **Session Management**: Stateless sessions with nonce protection
|
|
13
22
|
- ✅ **KV Storage**: Use Workers KV for nonce cache and identity
|
|
14
|
-
- ✅ **
|
|
15
|
-
|
|
23
|
+
- ✅ **Audit Logging**: Track all operations with configurable logging
|
|
24
|
+
|
|
25
|
+
### What This Package Does NOT Provide
|
|
16
26
|
|
|
17
|
-
|
|
27
|
+
- ❌ **MCP Protocol Transports**: No SSE or HTTP streaming support
|
|
28
|
+
- ❌ **MCP Client Compatibility**: Cannot connect to Claude Desktop or MCP Inspector
|
|
29
|
+
- ❌ **Durable Objects**: No built-in state management for sessions
|
|
30
|
+
|
|
31
|
+
For a complete MCP server that works with Claude Desktop and other MCP clients, use `agents/mcp` with the runtime from this package for optional proof generation.
|
|
32
|
+
|
|
33
|
+
## Quick Start with McpAgent
|
|
18
34
|
|
|
19
35
|
### 1. Create a new project
|
|
20
36
|
|
|
21
37
|
```bash
|
|
22
|
-
npx @kya-os/create-mcpi-app my-agent --platform cloudflare
|
|
38
|
+
npx @kya-os/create-mcpi-app my-agent --platform cloudflare
|
|
23
39
|
cd my-agent
|
|
24
40
|
```
|
|
25
41
|
|
|
@@ -38,130 +54,85 @@ npm run kv:create
|
|
|
38
54
|
# Copy the ID from output and update wrangler.toml
|
|
39
55
|
```
|
|
40
56
|
|
|
41
|
-
### 4.
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
# Generate identity locally (for development)
|
|
45
|
-
npx mcpi init
|
|
46
|
-
|
|
47
|
-
# Set secrets for production
|
|
48
|
-
wrangler secret put MCP_IDENTITY_PRIVATE_KEY
|
|
49
|
-
wrangler secret put MCP_IDENTITY_PUBLIC_KEY
|
|
50
|
-
wrangler secret put MCP_IDENTITY_DID
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
### 5. Deploy
|
|
57
|
+
### 4. Deploy
|
|
54
58
|
|
|
55
59
|
```bash
|
|
56
60
|
npm run deploy
|
|
57
61
|
```
|
|
58
62
|
|
|
59
|
-
##
|
|
60
|
-
|
|
61
|
-
### Installation
|
|
63
|
+
## Using MCP-I Runtime for Proof Generation
|
|
62
64
|
|
|
63
|
-
|
|
64
|
-
npm install @kya-os/mcp-i-cloudflare @modelcontextprotocol/sdk hono zod
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
### Worker Implementation
|
|
65
|
+
While the full adapter is deprecated, you can still use the MCP-I runtime with McpAgent for cryptographic proof generation:
|
|
68
66
|
|
|
69
67
|
```typescript
|
|
70
|
-
|
|
71
|
-
import {
|
|
72
|
-
import {
|
|
73
|
-
import {
|
|
74
|
-
import {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const app = new Hono<{ Bindings: Env }>();
|
|
84
|
-
|
|
85
|
-
// Enable CORS
|
|
86
|
-
app.use('/*', cors({
|
|
87
|
-
origin: '*',
|
|
88
|
-
allowMethods: ['GET', 'POST', 'OPTIONS'],
|
|
89
|
-
allowHeaders: ['Content-Type', 'Authorization'],
|
|
90
|
-
}));
|
|
68
|
+
import { McpAgent } from "agents/mcp";
|
|
69
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
70
|
+
import { createCloudflareRuntime, type CloudflareEnv } from "@kya-os/mcp-i-cloudflare";
|
|
71
|
+
import { Hono } from "hono";
|
|
72
|
+
import { cors } from "hono/cors";
|
|
73
|
+
|
|
74
|
+
export class MyMCP extends McpAgent {
|
|
75
|
+
server = new McpServer({
|
|
76
|
+
name: "my-server",
|
|
77
|
+
version: "1.0.0"
|
|
78
|
+
});
|
|
91
79
|
|
|
92
|
-
|
|
93
|
-
let mcpiRuntime: ReturnType<typeof createMCPIServer> | null = null;
|
|
94
|
-
let mcpServer: McpServer | null = null;
|
|
80
|
+
private mcpiRuntime?: any;
|
|
95
81
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
// Create MCP-I runtime
|
|
99
|
-
mcpiRuntime = createMCPIServer(env);
|
|
100
|
-
await mcpiRuntime.initialize();
|
|
82
|
+
constructor(state: DurableObjectState, env: CloudflareEnv) {
|
|
83
|
+
super(state, env);
|
|
101
84
|
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
85
|
+
// Optional: Initialize MCP-I runtime for proof generation
|
|
86
|
+
this.mcpiRuntime = createCloudflareRuntime({
|
|
87
|
+
env: env,
|
|
88
|
+
audit: {
|
|
89
|
+
enabled: true,
|
|
90
|
+
logFunction: (r) => console.log('[MCP-I]', r)
|
|
91
|
+
}
|
|
106
92
|
});
|
|
93
|
+
}
|
|
107
94
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
95
|
+
async init() {
|
|
96
|
+
await this.mcpiRuntime?.initialize();
|
|
97
|
+
|
|
98
|
+
this.server.tool(
|
|
99
|
+
"greet",
|
|
100
|
+
"Greet a user",
|
|
101
|
+
{ name: z.string() },
|
|
102
|
+
async ({ name }) => {
|
|
103
|
+
const result = {
|
|
104
|
+
content: [{ type: "text" as const, text: `Hello, ${name}!` }]
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// Optional: Generate cryptographic proof
|
|
108
|
+
if (this.mcpiRuntime) {
|
|
109
|
+
const { proof } = await this.mcpiRuntime.processToolCall(
|
|
110
|
+
"greet",
|
|
111
|
+
{ name },
|
|
112
|
+
async () => result,
|
|
113
|
+
null
|
|
114
|
+
);
|
|
115
|
+
console.log('[PROOF]', { did: proof.did, signature: proof.signature.substring(0, 20) });
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return result;
|
|
129
119
|
}
|
|
130
120
|
);
|
|
131
121
|
}
|
|
132
|
-
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
// Health check
|
|
136
|
-
app.get('/health', (c) => {
|
|
137
|
-
return c.json({
|
|
138
|
-
status: 'healthy',
|
|
139
|
-
timestamp: new Date().toISOString()
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
// Identity endpoint
|
|
144
|
-
app.get('/.well-known/mcp-identity', async (c) => {
|
|
145
|
-
const { mcpiRuntime } = await initialize(c.env);
|
|
146
|
-
const identity = await mcpiRuntime!.getIdentity();
|
|
147
|
-
|
|
148
|
-
return c.json({
|
|
149
|
-
did: identity.did,
|
|
150
|
-
keyId: identity.keyId,
|
|
151
|
-
publicKey: identity.publicKey
|
|
152
|
-
});
|
|
153
|
-
});
|
|
122
|
+
}
|
|
154
123
|
|
|
155
|
-
|
|
156
|
-
app.post('/mcp', async (c) => {
|
|
157
|
-
const { mcpServer } = await initialize(c.env);
|
|
158
|
-
const request = await c.req.json();
|
|
124
|
+
const app = new Hono();
|
|
159
125
|
|
|
160
|
-
|
|
161
|
-
|
|
126
|
+
app.use("/*", cors({
|
|
127
|
+
origin: "*",
|
|
128
|
+
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
|
129
|
+
allowHeaders: ["Content-Type", "Authorization", "mcp-session-id", "mcp-protocol-version"],
|
|
130
|
+
exposeHeaders: ["mcp-session-id"],
|
|
131
|
+
}));
|
|
162
132
|
|
|
163
|
-
|
|
164
|
-
});
|
|
133
|
+
app.get("/health", (c) => c.json({ status: 'healthy' }));
|
|
134
|
+
app.mount("/sse", MyMCP.serveSSE("/sse").fetch, { replaceRequest: false });
|
|
135
|
+
app.mount("/mcp", MyMCP.serve("/mcp").fetch, { replaceRequest: false });
|
|
165
136
|
|
|
166
137
|
export default app;
|
|
167
138
|
```
|
|
@@ -199,265 +170,116 @@ Dedicated SSE endpoint for Claude Desktop compatibility:
|
|
|
199
170
|
### `/.well-known/mcp-identity/*`
|
|
200
171
|
Identity verification endpoints for cryptographic proof validation.
|
|
201
172
|
|
|
202
|
-
##
|
|
173
|
+
## Response Format
|
|
203
174
|
|
|
204
|
-
|
|
175
|
+
MCP-I extends standard MCP responses with detached cryptographic proofs. Understanding the response structure is important for integration.
|
|
176
|
+
|
|
177
|
+
### Standard Tool Response
|
|
205
178
|
|
|
206
179
|
```json
|
|
207
180
|
{
|
|
208
|
-
"
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
181
|
+
"jsonrpc": "2.0",
|
|
182
|
+
"id": 1,
|
|
183
|
+
"result": {
|
|
184
|
+
"result": {
|
|
185
|
+
"content": [
|
|
186
|
+
{
|
|
187
|
+
"type": "text",
|
|
188
|
+
"text": "Hello, World!"
|
|
189
|
+
}
|
|
190
|
+
]
|
|
191
|
+
},
|
|
192
|
+
"proof": {
|
|
193
|
+
"timestamp": 1704067200000,
|
|
194
|
+
"nonce": "abc123...",
|
|
195
|
+
"did": "did:key:z6Mkh...",
|
|
196
|
+
"signature": "base64...",
|
|
197
|
+
"algorithm": "Ed25519",
|
|
198
|
+
"sessionId": "session-123"
|
|
212
199
|
}
|
|
213
200
|
}
|
|
214
201
|
}
|
|
215
202
|
```
|
|
216
203
|
|
|
217
|
-
|
|
218
|
-
The `/mcp` endpoint auto-detects transport based on Accept headers.
|
|
219
|
-
|
|
220
|
-
### wrangler.toml Configuration
|
|
221
|
-
|
|
222
|
-
```toml
|
|
223
|
-
name = "my-mcp-agent"
|
|
224
|
-
main = "src/index.ts"
|
|
225
|
-
compatibility_date = "2025-01-01"
|
|
226
|
-
compatibility_flags = ["nodejs_compat"]
|
|
227
|
-
|
|
228
|
-
# KV Namespace for nonce cache (required)
|
|
229
|
-
[[kv_namespaces]]
|
|
230
|
-
binding = "NONCE_CACHE"
|
|
231
|
-
id = "your-kv-namespace-id"
|
|
232
|
-
|
|
233
|
-
# Optional: KV for identity storage (development)
|
|
234
|
-
# [[kv_namespaces]]
|
|
235
|
-
# binding = "IDENTITY_KV"
|
|
236
|
-
# id = "your-identity-kv-id"
|
|
204
|
+
### Why `result.result`?
|
|
237
205
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
206
|
+
The nested structure exists because:
|
|
207
|
+
- **Outer `result`**: Required by JSON-RPC 2.0 specification
|
|
208
|
+
- **Inner `result`**: Contains the actual MCP tool response
|
|
209
|
+
- **`proof`**: Detached cryptographic proof (MCP-I extension)
|
|
242
210
|
|
|
243
|
-
|
|
244
|
-
[env.production]
|
|
245
|
-
name = "my-mcp-agent-production"
|
|
211
|
+
This structure maintains **backward compatibility** - standard MCP clients can extract `result.result` and ignore proofs.
|
|
246
212
|
|
|
247
|
-
|
|
248
|
-
binding = "NONCE_CACHE"
|
|
249
|
-
id = "your-production-kv-id"
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
## Identity Management
|
|
213
|
+
### LLM Visibility
|
|
253
214
|
|
|
254
|
-
|
|
215
|
+
**Important:** Language models (LLMs) DO NOT see cryptographic proofs.
|
|
255
216
|
|
|
256
|
-
|
|
217
|
+
The proof is extracted by the MCP client (like mcp-remote) and sent to a verifier service. The LLM only receives the business data from `result.result.content`.
|
|
257
218
|
|
|
258
|
-
|
|
259
|
-
// Identity stored in IDENTITY_KV namespace
|
|
260
|
-
const env = {
|
|
261
|
-
IDENTITY_KV: kvNamespace,
|
|
262
|
-
NONCE_CACHE: nonceNamespace
|
|
263
|
-
};
|
|
219
|
+
**Data flow:**
|
|
264
220
|
```
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
For production, use Wrangler secrets:
|
|
269
|
-
|
|
270
|
-
```bash
|
|
271
|
-
# Generate identity locally
|
|
272
|
-
npx mcpi init
|
|
273
|
-
|
|
274
|
-
# Copy values from .mcpi/identity.json
|
|
275
|
-
wrangler secret put MCP_IDENTITY_PRIVATE_KEY
|
|
276
|
-
wrangler secret put MCP_IDENTITY_PUBLIC_KEY
|
|
277
|
-
wrangler secret put MCP_IDENTITY_DID
|
|
278
|
-
wrangler secret put MCP_IDENTITY_KEY_ID
|
|
221
|
+
MCP Server → [result + proof]
|
|
222
|
+
├─→ proof → Agent Bouncer Service (verification)
|
|
223
|
+
└─→ result.result.content → LLM
|
|
279
224
|
```
|
|
280
225
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
Tools have the same format as Node.js MCP-I:
|
|
226
|
+
This "transparent security" design keeps authentication at the protocol layer, invisible to AI.
|
|
284
227
|
|
|
285
|
-
|
|
286
|
-
// src/tools/weather.ts
|
|
287
|
-
import { z } from 'zod';
|
|
288
|
-
|
|
289
|
-
export const weatherTool = {
|
|
290
|
-
name: 'get_weather',
|
|
291
|
-
description: 'Get weather for a location',
|
|
292
|
-
inputSchema: z.object({
|
|
293
|
-
location: z.string(),
|
|
294
|
-
units: z.enum(['celsius', 'fahrenheit']).optional()
|
|
295
|
-
}),
|
|
296
|
-
handler: async ({ location, units = 'celsius' }) => {
|
|
297
|
-
// Tool implementation
|
|
298
|
-
const weather = await fetchWeather(location, units);
|
|
299
|
-
|
|
300
|
-
return {
|
|
301
|
-
content: [{
|
|
302
|
-
type: 'text',
|
|
303
|
-
text: `Weather in ${location}: ${weather.temp}°${units[0].toUpperCase()}`
|
|
304
|
-
}]
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
};
|
|
308
|
-
```
|
|
228
|
+
### Proof Fields
|
|
309
229
|
|
|
310
|
-
|
|
230
|
+
| Field | Description |
|
|
231
|
+
|-------|-------------|
|
|
232
|
+
| `timestamp` | Unix timestamp (ms) when proof was created |
|
|
233
|
+
| `nonce` | Unique random value to prevent replay attacks (5-min lifetime) |
|
|
234
|
+
| `did` | Decentralized Identifier of the signing agent |
|
|
235
|
+
| `signature` | Ed25519 signature (base64) over proof metadata |
|
|
236
|
+
| `sessionId` | Session identifier for request/response correlation |
|
|
311
237
|
|
|
312
|
-
|
|
238
|
+
**See [MCP_I_RESPONSE_SPEC.md](../../MCP_I_RESPONSE_SPEC.md) for complete documentation.**
|
|
313
239
|
|
|
314
|
-
|
|
315
|
-
```bash
|
|
316
|
-
GET /.well-known/mcp-identity
|
|
317
|
-
|
|
318
|
-
Response:
|
|
319
|
-
{
|
|
320
|
-
"did": "did:key:z6MkhaXgBZD...",
|
|
321
|
-
"keyId": "did:key:z6MkhaXgBZD...#key-1",
|
|
322
|
-
"publicKey": "base64..."
|
|
323
|
-
}
|
|
324
|
-
```
|
|
325
|
-
|
|
326
|
-
### Proof Verification
|
|
327
|
-
```bash
|
|
328
|
-
POST /verify
|
|
240
|
+
## Claude Desktop Integration
|
|
329
241
|
|
|
330
|
-
|
|
331
|
-
{
|
|
332
|
-
"data": { ... },
|
|
333
|
-
"proof": { ... }
|
|
334
|
-
}
|
|
242
|
+
Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:
|
|
335
243
|
|
|
336
|
-
|
|
244
|
+
```json
|
|
337
245
|
{
|
|
338
|
-
"
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
## Performance Optimization
|
|
344
|
-
|
|
345
|
-
### Edge Caching
|
|
346
|
-
|
|
347
|
-
Use KV with TTL for efficient caching:
|
|
348
|
-
|
|
349
|
-
```typescript
|
|
350
|
-
// Cache DID documents
|
|
351
|
-
await env.CACHE_KV.put(
|
|
352
|
-
`did:${did}`,
|
|
353
|
-
JSON.stringify(document),
|
|
354
|
-
{ expirationTtl: 3600 } // 1 hour
|
|
355
|
-
);
|
|
356
|
-
```
|
|
357
|
-
|
|
358
|
-
### Progressive Verification
|
|
359
|
-
|
|
360
|
-
The runtime supports progressive verification for optimal edge performance:
|
|
361
|
-
|
|
362
|
-
```typescript
|
|
363
|
-
// Stage-1: Quick offline checks (no network)
|
|
364
|
-
const quickCheck = await runtime.verifyOffline(data);
|
|
365
|
-
|
|
366
|
-
// Stage-2: Full verification (may use network)
|
|
367
|
-
if (quickCheck.valid) {
|
|
368
|
-
const fullCheck = await runtime.verifyOnline(data);
|
|
369
|
-
}
|
|
370
|
-
```
|
|
371
|
-
|
|
372
|
-
## Monitoring
|
|
373
|
-
|
|
374
|
-
### Metrics
|
|
375
|
-
|
|
376
|
-
Track MCP-I operations:
|
|
377
|
-
|
|
378
|
-
```typescript
|
|
379
|
-
// In your worker
|
|
380
|
-
app.use('*', async (c, next) => {
|
|
381
|
-
const start = Date.now();
|
|
382
|
-
await next();
|
|
383
|
-
|
|
384
|
-
// Log to Analytics Engine or Workers Analytics
|
|
385
|
-
c.env.ANALYTICS.writeDataPoint({
|
|
386
|
-
endpoint: c.req.path,
|
|
387
|
-
duration: Date.now() - start,
|
|
388
|
-
status: c.res.status
|
|
389
|
-
});
|
|
390
|
-
});
|
|
391
|
-
```
|
|
392
|
-
|
|
393
|
-
### Audit Logging
|
|
394
|
-
|
|
395
|
-
Enable audit logging for security:
|
|
396
|
-
|
|
397
|
-
```typescript
|
|
398
|
-
const runtime = createMCPIServer({
|
|
399
|
-
...env,
|
|
400
|
-
audit: {
|
|
401
|
-
enabled: true,
|
|
402
|
-
logFunction: (record) => {
|
|
403
|
-
// Send to Logflare, Datadog, etc.
|
|
404
|
-
env.LOGGER.log(record);
|
|
246
|
+
"mcpServers": {
|
|
247
|
+
"my-agent": {
|
|
248
|
+
"command": "npx",
|
|
249
|
+
"args": ["mcp-remote", "https://my-agent.workers.dev/sse"]
|
|
405
250
|
}
|
|
406
251
|
}
|
|
407
|
-
}
|
|
252
|
+
}
|
|
408
253
|
```
|
|
409
254
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
### Local Development
|
|
255
|
+
**Note:** Both `/mcp` and `/sse` work with Claude Desktop. We recommend `/sse` for explicit SSE mode.
|
|
256
|
+
The `/mcp` endpoint auto-detects transport based on Accept headers.
|
|
413
257
|
|
|
414
|
-
|
|
415
|
-
# Start local dev server
|
|
416
|
-
npm run dev
|
|
258
|
+
### wrangler.toml Configuration
|
|
417
259
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
260
|
+
```toml
|
|
261
|
+
name = "my-mcp-agent"
|
|
262
|
+
main = "src/index.ts"
|
|
263
|
+
compatibility_date = "2025-06-18"
|
|
264
|
+
compatibility_flags = ["nodejs_compat"]
|
|
422
265
|
|
|
423
|
-
|
|
266
|
+
[[durable_objects.bindings]]
|
|
267
|
+
name = "MCP_OBJECT"
|
|
268
|
+
class_name = "MyMCP"
|
|
424
269
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
270
|
+
[[migrations]]
|
|
271
|
+
tag = "v1"
|
|
272
|
+
new_sqlite_classes = ["MyMCP"]
|
|
428
273
|
|
|
429
|
-
|
|
430
|
-
|
|
274
|
+
[[kv_namespaces]]
|
|
275
|
+
binding = "NONCE_CACHE"
|
|
276
|
+
id = "your-kv-namespace-id"
|
|
431
277
|
|
|
432
|
-
|
|
433
|
-
|
|
278
|
+
[vars]
|
|
279
|
+
XMCP_I_TS_SKEW_SEC = "120"
|
|
280
|
+
XMCP_I_SESSION_TTL = "1800"
|
|
434
281
|
```
|
|
435
282
|
|
|
436
|
-
## Security Best Practices
|
|
437
|
-
|
|
438
|
-
1. **Never commit private keys** - Use Wrangler secrets
|
|
439
|
-
2. **Rotate keys regularly** - Use `mcpi rotate` command
|
|
440
|
-
3. **Limit KV access** - Use least privilege bindings
|
|
441
|
-
4. **Enable audit logging** - Track all operations
|
|
442
|
-
5. **Use CORS properly** - Restrict origins in production
|
|
443
|
-
6. **Monitor rate limits** - Implement request throttling
|
|
444
|
-
|
|
445
|
-
## Troubleshooting
|
|
446
|
-
|
|
447
|
-
### Common Issues
|
|
448
|
-
|
|
449
|
-
**Error: No identity found**
|
|
450
|
-
- Ensure secrets are set: `wrangler secret list`
|
|
451
|
-
- Check KV binding in wrangler.toml
|
|
452
|
-
|
|
453
|
-
**Error: Nonce already used**
|
|
454
|
-
- Check KV namespace is configured
|
|
455
|
-
- Verify TTL settings
|
|
456
|
-
|
|
457
|
-
**Error: Timestamp outside window**
|
|
458
|
-
- Check clock skew settings
|
|
459
|
-
- Ensure client/server time sync
|
|
460
|
-
|
|
461
283
|
## API Reference
|
|
462
284
|
|
|
463
285
|
### MCPICloudflareRuntime
|
|
@@ -502,10 +324,10 @@ interface MCPICloudflareEnv {
|
|
|
502
324
|
}
|
|
503
325
|
```
|
|
504
326
|
|
|
505
|
-
##
|
|
327
|
+
## Migration Guide
|
|
506
328
|
|
|
507
|
-
See
|
|
329
|
+
See [CLOUDFLARE_DEPLOYMENT.md](../../CLOUDFLARE_DEPLOYMENT.md) for complete migration instructions and working examples.
|
|
508
330
|
|
|
509
331
|
## License
|
|
510
332
|
|
|
511
|
-
MIT
|
|
333
|
+
MIT
|
package/dist/adapter.d.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import type { MCPICloudflareConfig } from './index';
|
|
12
12
|
import type { MCPIRuntimeBase } from '@kya-os/mcp-i-core';
|
|
13
|
+
import { KVProofArchive } from './storage/kv-proof-archive';
|
|
13
14
|
export interface ToolDefinition {
|
|
14
15
|
name: string;
|
|
15
16
|
description: string;
|
|
@@ -30,10 +31,11 @@ declare class CloudflareMCPServer {
|
|
|
30
31
|
private runtime;
|
|
31
32
|
private serverInfo;
|
|
32
33
|
private tools;
|
|
34
|
+
private proofArchive?;
|
|
33
35
|
constructor(runtime: MCPIRuntimeBase, serverInfo: {
|
|
34
36
|
name: string;
|
|
35
37
|
version: string;
|
|
36
|
-
}, tools?: ToolDefinition[]);
|
|
38
|
+
}, tools?: ToolDefinition[], proofArchive?: KVProofArchive);
|
|
37
39
|
/**
|
|
38
40
|
* Handle JSON-RPC request
|
|
39
41
|
*/
|
|
@@ -42,6 +44,10 @@ declare class CloudflareMCPServer {
|
|
|
42
44
|
/**
|
|
43
45
|
* Create a complete MCP-I handler for Cloudflare Workers
|
|
44
46
|
* with full MCP protocol support and identity features
|
|
47
|
+
*
|
|
48
|
+
* @deprecated This adapter does not support MCP transports (SSE/HTTP streaming).
|
|
49
|
+
* Use McpAgent from 'agents/mcp' instead.
|
|
50
|
+
* See: https://developers.cloudflare.com/agents/model-context-protocol/
|
|
45
51
|
*/
|
|
46
52
|
export declare function createMCPICloudflareAdapter(config: MCPICloudflareAdapterConfig): {
|
|
47
53
|
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,
|
|
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;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,GAAG,CAAC;IACjB,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CACtC;AAED,MAAM,WAAW,2BAA4B,SAAQ,oBAAoB;IACvE,UAAU,CAAC,EAAE;QACX,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,KAAK,CAAC,EAAE,cAAc,EAAE,CAAC;CAC1B;AAED;;GAEG;AACH,cAAM,mBAAmB;IACvB,OAAO,CAAC,OAAO,CAAkB;IACjC,OAAO,CAAC,UAAU,CAAoC;IACtD,OAAO,CAAC,KAAK,CAA8B;IAC3C,OAAO,CAAC,YAAY,CAAC,CAAiB;gBAGpC,OAAO,EAAE,eAAe,EACxB,UAAU,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAC7C,KAAK,GAAE,cAAc,EAAO,EAC5B,YAAY,CAAC,EAAE,cAAc;IAQ/B;;OAEG;IACG,aAAa,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;CA+GhD;AAED;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,2BAA2B;;;mBAuBtD,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;EAiTnD"}
|