@kya-os/mcp-i-cloudflare 1.1.1 → 1.2.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 +158 -347
- package/dist/adapter.d.ts +7 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +189 -7
- 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,36 +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+, fixed in v1.1.1)
|
|
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
|
-
- ✅ **Progressive Verification**: Optimized for edge performance
|
|
16
|
-
|
|
17
|
-
## ⚠️ Cloudflare Workers Limitations
|
|
23
|
+
- ✅ **Audit Logging**: Track all operations with configurable logging
|
|
18
24
|
|
|
19
|
-
|
|
25
|
+
### What This Package Does NOT Provide
|
|
20
26
|
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
- **100-second timeout for streaming** - If implementing true streaming, must send data at least every 100 seconds
|
|
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
|
|
25
30
|
|
|
26
|
-
|
|
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.
|
|
27
32
|
|
|
28
|
-
## Quick Start
|
|
33
|
+
## Quick Start with McpAgent
|
|
29
34
|
|
|
30
35
|
### 1. Create a new project
|
|
31
36
|
|
|
32
37
|
```bash
|
|
33
|
-
npx @kya-os/create-mcpi-app my-agent --platform cloudflare
|
|
38
|
+
npx @kya-os/create-mcpi-app my-agent --platform cloudflare
|
|
34
39
|
cd my-agent
|
|
35
40
|
```
|
|
36
41
|
|
|
@@ -49,130 +54,85 @@ npm run kv:create
|
|
|
49
54
|
# Copy the ID from output and update wrangler.toml
|
|
50
55
|
```
|
|
51
56
|
|
|
52
|
-
### 4.
|
|
53
|
-
|
|
54
|
-
```bash
|
|
55
|
-
# Generate identity locally (for development)
|
|
56
|
-
npx mcpi init
|
|
57
|
-
|
|
58
|
-
# Set secrets for production
|
|
59
|
-
wrangler secret put MCP_IDENTITY_PRIVATE_KEY
|
|
60
|
-
wrangler secret put MCP_IDENTITY_PUBLIC_KEY
|
|
61
|
-
wrangler secret put MCP_IDENTITY_DID
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
### 5. Deploy
|
|
57
|
+
### 4. Deploy
|
|
65
58
|
|
|
66
59
|
```bash
|
|
67
60
|
npm run deploy
|
|
68
61
|
```
|
|
69
62
|
|
|
70
|
-
##
|
|
71
|
-
|
|
72
|
-
### Installation
|
|
73
|
-
|
|
74
|
-
```bash
|
|
75
|
-
npm install @kya-os/mcp-i-cloudflare @modelcontextprotocol/sdk hono zod
|
|
76
|
-
```
|
|
63
|
+
## Using MCP-I Runtime for Proof Generation
|
|
77
64
|
|
|
78
|
-
|
|
65
|
+
While the full adapter is deprecated, you can still use the MCP-I runtime with McpAgent for cryptographic proof generation:
|
|
79
66
|
|
|
80
67
|
```typescript
|
|
81
|
-
|
|
82
|
-
import {
|
|
83
|
-
import {
|
|
84
|
-
import {
|
|
85
|
-
import {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const app = new Hono<{ Bindings: Env }>();
|
|
95
|
-
|
|
96
|
-
// Enable CORS
|
|
97
|
-
app.use('/*', cors({
|
|
98
|
-
origin: '*',
|
|
99
|
-
allowMethods: ['GET', 'POST', 'OPTIONS'],
|
|
100
|
-
allowHeaders: ['Content-Type', 'Authorization'],
|
|
101
|
-
}));
|
|
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
|
+
});
|
|
102
79
|
|
|
103
|
-
|
|
104
|
-
let mcpiRuntime: ReturnType<typeof createMCPIServer> | null = null;
|
|
105
|
-
let mcpServer: McpServer | null = null;
|
|
80
|
+
private mcpiRuntime?: any;
|
|
106
81
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
// Create MCP-I runtime
|
|
110
|
-
mcpiRuntime = createMCPIServer(env);
|
|
111
|
-
await mcpiRuntime.initialize();
|
|
82
|
+
constructor(state: DurableObjectState, env: CloudflareEnv) {
|
|
83
|
+
super(state, env);
|
|
112
84
|
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
+
}
|
|
117
92
|
});
|
|
93
|
+
}
|
|
118
94
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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;
|
|
140
119
|
}
|
|
141
120
|
);
|
|
142
121
|
}
|
|
143
|
-
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
// Health check
|
|
147
|
-
app.get('/health', (c) => {
|
|
148
|
-
return c.json({
|
|
149
|
-
status: 'healthy',
|
|
150
|
-
timestamp: new Date().toISOString()
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
// Identity endpoint
|
|
155
|
-
app.get('/.well-known/mcp-identity', async (c) => {
|
|
156
|
-
const { mcpiRuntime } = await initialize(c.env);
|
|
157
|
-
const identity = await mcpiRuntime!.getIdentity();
|
|
158
|
-
|
|
159
|
-
return c.json({
|
|
160
|
-
did: identity.did,
|
|
161
|
-
keyId: identity.keyId,
|
|
162
|
-
publicKey: identity.publicKey
|
|
163
|
-
});
|
|
164
|
-
});
|
|
122
|
+
}
|
|
165
123
|
|
|
166
|
-
|
|
167
|
-
app.post('/mcp', async (c) => {
|
|
168
|
-
const { mcpServer } = await initialize(c.env);
|
|
169
|
-
const request = await c.req.json();
|
|
124
|
+
const app = new Hono();
|
|
170
125
|
|
|
171
|
-
|
|
172
|
-
|
|
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
|
+
}));
|
|
173
132
|
|
|
174
|
-
|
|
175
|
-
});
|
|
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 });
|
|
176
136
|
|
|
177
137
|
export default app;
|
|
178
138
|
```
|
|
@@ -210,265 +170,116 @@ Dedicated SSE endpoint for Claude Desktop compatibility:
|
|
|
210
170
|
### `/.well-known/mcp-identity/*`
|
|
211
171
|
Identity verification endpoints for cryptographic proof validation.
|
|
212
172
|
|
|
213
|
-
##
|
|
173
|
+
## Response Format
|
|
214
174
|
|
|
215
|
-
|
|
175
|
+
MCP-I extends standard MCP responses with detached cryptographic proofs. Understanding the response structure is important for integration.
|
|
176
|
+
|
|
177
|
+
### Standard Tool Response
|
|
216
178
|
|
|
217
179
|
```json
|
|
218
180
|
{
|
|
219
|
-
"
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
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"
|
|
223
199
|
}
|
|
224
200
|
}
|
|
225
201
|
}
|
|
226
202
|
```
|
|
227
203
|
|
|
228
|
-
|
|
229
|
-
The `/mcp` endpoint auto-detects transport based on Accept headers.
|
|
204
|
+
### Why `result.result`?
|
|
230
205
|
|
|
231
|
-
|
|
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)
|
|
232
210
|
|
|
233
|
-
|
|
234
|
-
name = "my-mcp-agent"
|
|
235
|
-
main = "src/index.ts"
|
|
236
|
-
compatibility_date = "2025-01-01"
|
|
237
|
-
compatibility_flags = ["nodejs_compat"]
|
|
211
|
+
This structure maintains **backward compatibility** - standard MCP clients can extract `result.result` and ignore proofs.
|
|
238
212
|
|
|
239
|
-
|
|
240
|
-
[[kv_namespaces]]
|
|
241
|
-
binding = "NONCE_CACHE"
|
|
242
|
-
id = "your-kv-namespace-id"
|
|
243
|
-
|
|
244
|
-
# Optional: KV for identity storage (development)
|
|
245
|
-
# [[kv_namespaces]]
|
|
246
|
-
# binding = "IDENTITY_KV"
|
|
247
|
-
# id = "your-identity-kv-id"
|
|
213
|
+
### LLM Visibility
|
|
248
214
|
|
|
249
|
-
|
|
250
|
-
[vars]
|
|
251
|
-
XMCP_I_TS_SKEW_SEC = "120"
|
|
252
|
-
XMCP_I_SESSION_TTL = "1800"
|
|
215
|
+
**Important:** Language models (LLMs) DO NOT see cryptographic proofs.
|
|
253
216
|
|
|
254
|
-
|
|
255
|
-
[env.production]
|
|
256
|
-
name = "my-mcp-agent-production"
|
|
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
|
-
binding = "NONCE_CACHE"
|
|
260
|
-
id = "your-production-kv-id"
|
|
219
|
+
**Data flow:**
|
|
261
220
|
```
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
### Development
|
|
266
|
-
|
|
267
|
-
For development, you can store identity in KV:
|
|
268
|
-
|
|
269
|
-
```typescript
|
|
270
|
-
// Identity stored in IDENTITY_KV namespace
|
|
271
|
-
const env = {
|
|
272
|
-
IDENTITY_KV: kvNamespace,
|
|
273
|
-
NONCE_CACHE: nonceNamespace
|
|
274
|
-
};
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
### Production
|
|
278
|
-
|
|
279
|
-
For production, use Wrangler secrets:
|
|
280
|
-
|
|
281
|
-
```bash
|
|
282
|
-
# Generate identity locally
|
|
283
|
-
npx mcpi init
|
|
284
|
-
|
|
285
|
-
# Copy values from .mcpi/identity.json
|
|
286
|
-
wrangler secret put MCP_IDENTITY_PRIVATE_KEY
|
|
287
|
-
wrangler secret put MCP_IDENTITY_PUBLIC_KEY
|
|
288
|
-
wrangler secret put MCP_IDENTITY_DID
|
|
289
|
-
wrangler secret put MCP_IDENTITY_KEY_ID
|
|
221
|
+
MCP Server → [result + proof]
|
|
222
|
+
├─→ proof → Agent Bouncer Service (verification)
|
|
223
|
+
└─→ result.result.content → LLM
|
|
290
224
|
```
|
|
291
225
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
Tools have the same format as Node.js MCP-I:
|
|
295
|
-
|
|
296
|
-
```typescript
|
|
297
|
-
// src/tools/weather.ts
|
|
298
|
-
import { z } from 'zod';
|
|
299
|
-
|
|
300
|
-
export const weatherTool = {
|
|
301
|
-
name: 'get_weather',
|
|
302
|
-
description: 'Get weather for a location',
|
|
303
|
-
inputSchema: z.object({
|
|
304
|
-
location: z.string(),
|
|
305
|
-
units: z.enum(['celsius', 'fahrenheit']).optional()
|
|
306
|
-
}),
|
|
307
|
-
handler: async ({ location, units = 'celsius' }) => {
|
|
308
|
-
// Tool implementation
|
|
309
|
-
const weather = await fetchWeather(location, units);
|
|
310
|
-
|
|
311
|
-
return {
|
|
312
|
-
content: [{
|
|
313
|
-
type: 'text',
|
|
314
|
-
text: `Weather in ${location}: ${weather.temp}°${units[0].toUpperCase()}`
|
|
315
|
-
}]
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
};
|
|
319
|
-
```
|
|
226
|
+
This "transparent security" design keeps authentication at the protocol layer, invisible to AI.
|
|
320
227
|
|
|
321
|
-
|
|
228
|
+
### Proof Fields
|
|
322
229
|
|
|
323
|
-
|
|
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 |
|
|
324
237
|
|
|
325
|
-
|
|
326
|
-
```bash
|
|
327
|
-
GET /.well-known/mcp-identity
|
|
238
|
+
**See [MCP_I_RESPONSE_SPEC.md](../../MCP_I_RESPONSE_SPEC.md) for complete documentation.**
|
|
328
239
|
|
|
329
|
-
|
|
330
|
-
{
|
|
331
|
-
"did": "did:key:z6MkhaXgBZD...",
|
|
332
|
-
"keyId": "did:key:z6MkhaXgBZD...#key-1",
|
|
333
|
-
"publicKey": "base64..."
|
|
334
|
-
}
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
### Proof Verification
|
|
338
|
-
```bash
|
|
339
|
-
POST /verify
|
|
240
|
+
## Claude Desktop Integration
|
|
340
241
|
|
|
341
|
-
|
|
342
|
-
{
|
|
343
|
-
"data": { ... },
|
|
344
|
-
"proof": { ... }
|
|
345
|
-
}
|
|
242
|
+
Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:
|
|
346
243
|
|
|
347
|
-
|
|
244
|
+
```json
|
|
348
245
|
{
|
|
349
|
-
"
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
## Performance Optimization
|
|
355
|
-
|
|
356
|
-
### Edge Caching
|
|
357
|
-
|
|
358
|
-
Use KV with TTL for efficient caching:
|
|
359
|
-
|
|
360
|
-
```typescript
|
|
361
|
-
// Cache DID documents
|
|
362
|
-
await env.CACHE_KV.put(
|
|
363
|
-
`did:${did}`,
|
|
364
|
-
JSON.stringify(document),
|
|
365
|
-
{ expirationTtl: 3600 } // 1 hour
|
|
366
|
-
);
|
|
367
|
-
```
|
|
368
|
-
|
|
369
|
-
### Progressive Verification
|
|
370
|
-
|
|
371
|
-
The runtime supports progressive verification for optimal edge performance:
|
|
372
|
-
|
|
373
|
-
```typescript
|
|
374
|
-
// Stage-1: Quick offline checks (no network)
|
|
375
|
-
const quickCheck = await runtime.verifyOffline(data);
|
|
376
|
-
|
|
377
|
-
// Stage-2: Full verification (may use network)
|
|
378
|
-
if (quickCheck.valid) {
|
|
379
|
-
const fullCheck = await runtime.verifyOnline(data);
|
|
380
|
-
}
|
|
381
|
-
```
|
|
382
|
-
|
|
383
|
-
## Monitoring
|
|
384
|
-
|
|
385
|
-
### Metrics
|
|
386
|
-
|
|
387
|
-
Track MCP-I operations:
|
|
388
|
-
|
|
389
|
-
```typescript
|
|
390
|
-
// In your worker
|
|
391
|
-
app.use('*', async (c, next) => {
|
|
392
|
-
const start = Date.now();
|
|
393
|
-
await next();
|
|
394
|
-
|
|
395
|
-
// Log to Analytics Engine or Workers Analytics
|
|
396
|
-
c.env.ANALYTICS.writeDataPoint({
|
|
397
|
-
endpoint: c.req.path,
|
|
398
|
-
duration: Date.now() - start,
|
|
399
|
-
status: c.res.status
|
|
400
|
-
});
|
|
401
|
-
});
|
|
402
|
-
```
|
|
403
|
-
|
|
404
|
-
### Audit Logging
|
|
405
|
-
|
|
406
|
-
Enable audit logging for security:
|
|
407
|
-
|
|
408
|
-
```typescript
|
|
409
|
-
const runtime = createMCPIServer({
|
|
410
|
-
...env,
|
|
411
|
-
audit: {
|
|
412
|
-
enabled: true,
|
|
413
|
-
logFunction: (record) => {
|
|
414
|
-
// Send to Logflare, Datadog, etc.
|
|
415
|
-
env.LOGGER.log(record);
|
|
246
|
+
"mcpServers": {
|
|
247
|
+
"my-agent": {
|
|
248
|
+
"command": "npx",
|
|
249
|
+
"args": ["mcp-remote", "https://my-agent.workers.dev/sse"]
|
|
416
250
|
}
|
|
417
251
|
}
|
|
418
|
-
}
|
|
252
|
+
}
|
|
419
253
|
```
|
|
420
254
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
### 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.
|
|
424
257
|
|
|
425
|
-
|
|
426
|
-
# Start local dev server
|
|
427
|
-
npm run dev
|
|
258
|
+
### wrangler.toml Configuration
|
|
428
259
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
260
|
+
```toml
|
|
261
|
+
name = "my-mcp-agent"
|
|
262
|
+
main = "src/index.ts"
|
|
263
|
+
compatibility_date = "2025-06-18"
|
|
264
|
+
compatibility_flags = ["nodejs_compat"]
|
|
433
265
|
|
|
434
|
-
|
|
266
|
+
[[durable_objects.bindings]]
|
|
267
|
+
name = "MCP_OBJECT"
|
|
268
|
+
class_name = "MyMCP"
|
|
435
269
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
270
|
+
[[migrations]]
|
|
271
|
+
tag = "v1"
|
|
272
|
+
new_sqlite_classes = ["MyMCP"]
|
|
439
273
|
|
|
440
|
-
|
|
441
|
-
|
|
274
|
+
[[kv_namespaces]]
|
|
275
|
+
binding = "NONCE_CACHE"
|
|
276
|
+
id = "your-kv-namespace-id"
|
|
442
277
|
|
|
443
|
-
|
|
444
|
-
|
|
278
|
+
[vars]
|
|
279
|
+
XMCP_I_TS_SKEW_SEC = "120"
|
|
280
|
+
XMCP_I_SESSION_TTL = "1800"
|
|
445
281
|
```
|
|
446
282
|
|
|
447
|
-
## Security Best Practices
|
|
448
|
-
|
|
449
|
-
1. **Never commit private keys** - Use Wrangler secrets
|
|
450
|
-
2. **Rotate keys regularly** - Use `mcpi rotate` command
|
|
451
|
-
3. **Limit KV access** - Use least privilege bindings
|
|
452
|
-
4. **Enable audit logging** - Track all operations
|
|
453
|
-
5. **Use CORS properly** - Restrict origins in production
|
|
454
|
-
6. **Monitor rate limits** - Implement request throttling
|
|
455
|
-
|
|
456
|
-
## Troubleshooting
|
|
457
|
-
|
|
458
|
-
### Common Issues
|
|
459
|
-
|
|
460
|
-
**Error: No identity found**
|
|
461
|
-
- Ensure secrets are set: `wrangler secret list`
|
|
462
|
-
- Check KV binding in wrangler.toml
|
|
463
|
-
|
|
464
|
-
**Error: Nonce already used**
|
|
465
|
-
- Check KV namespace is configured
|
|
466
|
-
- Verify TTL settings
|
|
467
|
-
|
|
468
|
-
**Error: Timestamp outside window**
|
|
469
|
-
- Check clock skew settings
|
|
470
|
-
- Ensure client/server time sync
|
|
471
|
-
|
|
472
283
|
## API Reference
|
|
473
284
|
|
|
474
285
|
### MCPICloudflareRuntime
|
|
@@ -513,10 +324,10 @@ interface MCPICloudflareEnv {
|
|
|
513
324
|
}
|
|
514
325
|
```
|
|
515
326
|
|
|
516
|
-
##
|
|
327
|
+
## Migration Guide
|
|
517
328
|
|
|
518
|
-
See
|
|
329
|
+
See [CLOUDFLARE_DEPLOYMENT.md](../../CLOUDFLARE_DEPLOYMENT.md) for complete migration instructions and working examples.
|
|
519
330
|
|
|
520
331
|
## License
|
|
521
332
|
|
|
522
|
-
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;CAqHhD;AAED;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,2BAA2B;;;mBAuBtD,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;EAiTnD"}
|