@decocms/runtime 1.0.0-alpha-candy.2 → 1.0.0-alpha.11
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/config-schema.json +553 -0
- package/package.json +4 -4
- package/src/index.ts +21 -16
- package/src/state.ts +2 -1
- package/src/tools.ts +13 -7
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$ref": "#/definitions/WranglerConfig",
|
|
4
|
+
"definitions": {
|
|
5
|
+
"WranglerConfig": {
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"name": {
|
|
9
|
+
"type": "string"
|
|
10
|
+
},
|
|
11
|
+
"main": {
|
|
12
|
+
"type": "string"
|
|
13
|
+
},
|
|
14
|
+
"scope": {
|
|
15
|
+
"type": "string"
|
|
16
|
+
},
|
|
17
|
+
"main_module": {
|
|
18
|
+
"type": "string"
|
|
19
|
+
},
|
|
20
|
+
"routes": {
|
|
21
|
+
"type": "array",
|
|
22
|
+
"items": {
|
|
23
|
+
"$ref": "#/definitions/Route"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"compatibility_date": {
|
|
27
|
+
"type": "string"
|
|
28
|
+
},
|
|
29
|
+
"compatibility_flags": {
|
|
30
|
+
"type": "array",
|
|
31
|
+
"items": {
|
|
32
|
+
"type": "string"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"vars": {
|
|
36
|
+
"type": "object",
|
|
37
|
+
"additionalProperties": {
|
|
38
|
+
"type": "string"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"kv_namespaces": {
|
|
42
|
+
"type": "array",
|
|
43
|
+
"items": {
|
|
44
|
+
"$ref": "#/definitions/KVNamespace"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"triggers": {
|
|
48
|
+
"$ref": "#/definitions/Triggers"
|
|
49
|
+
},
|
|
50
|
+
"ai": {
|
|
51
|
+
"type": "object",
|
|
52
|
+
"properties": {
|
|
53
|
+
"binding": {
|
|
54
|
+
"type": "string"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"required": [
|
|
58
|
+
"binding"
|
|
59
|
+
],
|
|
60
|
+
"additionalProperties": false
|
|
61
|
+
},
|
|
62
|
+
"browser": {
|
|
63
|
+
"type": "object",
|
|
64
|
+
"properties": {
|
|
65
|
+
"binding": {
|
|
66
|
+
"type": "string"
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"required": [
|
|
70
|
+
"binding"
|
|
71
|
+
],
|
|
72
|
+
"additionalProperties": false
|
|
73
|
+
},
|
|
74
|
+
"durable_objects": {
|
|
75
|
+
"type": "object",
|
|
76
|
+
"properties": {
|
|
77
|
+
"bindings": {
|
|
78
|
+
"type": "array",
|
|
79
|
+
"items": {
|
|
80
|
+
"type": "object",
|
|
81
|
+
"properties": {
|
|
82
|
+
"name": {
|
|
83
|
+
"type": "string"
|
|
84
|
+
},
|
|
85
|
+
"class_name": {
|
|
86
|
+
"type": "string"
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"required": [
|
|
90
|
+
"name",
|
|
91
|
+
"class_name"
|
|
92
|
+
],
|
|
93
|
+
"additionalProperties": false
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
"additionalProperties": false
|
|
98
|
+
},
|
|
99
|
+
"hyperdrive": {
|
|
100
|
+
"type": "array",
|
|
101
|
+
"items": {
|
|
102
|
+
"type": "object",
|
|
103
|
+
"properties": {
|
|
104
|
+
"binding": {
|
|
105
|
+
"type": "string"
|
|
106
|
+
},
|
|
107
|
+
"id": {
|
|
108
|
+
"type": "string"
|
|
109
|
+
},
|
|
110
|
+
"localConnectionString": {
|
|
111
|
+
"type": "string"
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
"required": [
|
|
115
|
+
"binding",
|
|
116
|
+
"id",
|
|
117
|
+
"localConnectionString"
|
|
118
|
+
],
|
|
119
|
+
"additionalProperties": false
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
"d1_databases": {
|
|
123
|
+
"type": "array",
|
|
124
|
+
"items": {
|
|
125
|
+
"type": "object",
|
|
126
|
+
"properties": {
|
|
127
|
+
"database_name": {
|
|
128
|
+
"type": "string"
|
|
129
|
+
},
|
|
130
|
+
"database_id": {
|
|
131
|
+
"type": "string"
|
|
132
|
+
},
|
|
133
|
+
"binding": {
|
|
134
|
+
"type": "string"
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
"required": [
|
|
138
|
+
"database_name",
|
|
139
|
+
"binding"
|
|
140
|
+
],
|
|
141
|
+
"additionalProperties": false
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
"queues": {
|
|
145
|
+
"type": "object",
|
|
146
|
+
"properties": {
|
|
147
|
+
"consumers": {
|
|
148
|
+
"type": "array",
|
|
149
|
+
"items": {
|
|
150
|
+
"type": "object",
|
|
151
|
+
"properties": {
|
|
152
|
+
"queue": {
|
|
153
|
+
"type": "string"
|
|
154
|
+
},
|
|
155
|
+
"max_batch_timeout": {
|
|
156
|
+
"type": "number"
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
"required": [
|
|
160
|
+
"queue",
|
|
161
|
+
"max_batch_timeout"
|
|
162
|
+
],
|
|
163
|
+
"additionalProperties": false
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
"producers": {
|
|
167
|
+
"type": "array",
|
|
168
|
+
"items": {
|
|
169
|
+
"type": "object",
|
|
170
|
+
"properties": {
|
|
171
|
+
"queue": {
|
|
172
|
+
"type": "string"
|
|
173
|
+
},
|
|
174
|
+
"binding": {
|
|
175
|
+
"type": "string"
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
"required": [
|
|
179
|
+
"queue",
|
|
180
|
+
"binding"
|
|
181
|
+
],
|
|
182
|
+
"additionalProperties": false
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
"additionalProperties": false
|
|
187
|
+
},
|
|
188
|
+
"workflows": {
|
|
189
|
+
"type": "array",
|
|
190
|
+
"items": {
|
|
191
|
+
"type": "object",
|
|
192
|
+
"properties": {
|
|
193
|
+
"name": {
|
|
194
|
+
"type": "string"
|
|
195
|
+
},
|
|
196
|
+
"binding": {
|
|
197
|
+
"type": "string"
|
|
198
|
+
},
|
|
199
|
+
"class_name": {
|
|
200
|
+
"type": "string"
|
|
201
|
+
},
|
|
202
|
+
"script_name": {
|
|
203
|
+
"type": "string"
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
"required": [
|
|
207
|
+
"name",
|
|
208
|
+
"binding"
|
|
209
|
+
],
|
|
210
|
+
"additionalProperties": false
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
"migrations": {
|
|
214
|
+
"type": "array",
|
|
215
|
+
"items": {
|
|
216
|
+
"$ref": "#/definitions/Migration"
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
"assets": {
|
|
220
|
+
"type": "object",
|
|
221
|
+
"properties": {
|
|
222
|
+
"directory": {
|
|
223
|
+
"type": "string"
|
|
224
|
+
},
|
|
225
|
+
"binding": {
|
|
226
|
+
"type": "string"
|
|
227
|
+
},
|
|
228
|
+
"jwt": {
|
|
229
|
+
"type": "string"
|
|
230
|
+
},
|
|
231
|
+
"not_found_handling": {
|
|
232
|
+
"type": "string",
|
|
233
|
+
"enum": [
|
|
234
|
+
"none",
|
|
235
|
+
"404-page",
|
|
236
|
+
"single-page-application"
|
|
237
|
+
]
|
|
238
|
+
},
|
|
239
|
+
"run_worker_first": {
|
|
240
|
+
"type": "boolean"
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
"additionalProperties": false
|
|
244
|
+
},
|
|
245
|
+
"keep_assets": {
|
|
246
|
+
"type": "boolean"
|
|
247
|
+
},
|
|
248
|
+
"deco": {
|
|
249
|
+
"type": "object",
|
|
250
|
+
"properties": {
|
|
251
|
+
"enable_workflows": {
|
|
252
|
+
"type": "boolean"
|
|
253
|
+
},
|
|
254
|
+
"workspace": {
|
|
255
|
+
"type": "string"
|
|
256
|
+
},
|
|
257
|
+
"local": {
|
|
258
|
+
"type": "boolean"
|
|
259
|
+
},
|
|
260
|
+
"integration": {
|
|
261
|
+
"type": "object",
|
|
262
|
+
"properties": {
|
|
263
|
+
"friendlyName": {
|
|
264
|
+
"type": "string"
|
|
265
|
+
},
|
|
266
|
+
"icon": {
|
|
267
|
+
"type": "string"
|
|
268
|
+
},
|
|
269
|
+
"description": {
|
|
270
|
+
"type": "string"
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
"additionalProperties": false
|
|
274
|
+
},
|
|
275
|
+
"bindings": {
|
|
276
|
+
"type": "array",
|
|
277
|
+
"items": {
|
|
278
|
+
"$ref": "#/definitions/Binding"
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
"additionalProperties": false
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
"required": [
|
|
286
|
+
"name"
|
|
287
|
+
],
|
|
288
|
+
"additionalProperties": false
|
|
289
|
+
},
|
|
290
|
+
"Route": {
|
|
291
|
+
"type": "object",
|
|
292
|
+
"properties": {
|
|
293
|
+
"pattern": {
|
|
294
|
+
"type": "string"
|
|
295
|
+
},
|
|
296
|
+
"custom_domain": {
|
|
297
|
+
"type": "boolean"
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
"required": [
|
|
301
|
+
"pattern"
|
|
302
|
+
],
|
|
303
|
+
"additionalProperties": false
|
|
304
|
+
},
|
|
305
|
+
"KVNamespace": {
|
|
306
|
+
"type": "object",
|
|
307
|
+
"properties": {
|
|
308
|
+
"binding": {
|
|
309
|
+
"type": "string"
|
|
310
|
+
},
|
|
311
|
+
"id": {
|
|
312
|
+
"type": "string"
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
"required": [
|
|
316
|
+
"binding",
|
|
317
|
+
"id"
|
|
318
|
+
],
|
|
319
|
+
"additionalProperties": false
|
|
320
|
+
},
|
|
321
|
+
"Triggers": {
|
|
322
|
+
"type": "object",
|
|
323
|
+
"properties": {
|
|
324
|
+
"crons": {
|
|
325
|
+
"type": "array",
|
|
326
|
+
"items": {
|
|
327
|
+
"type": "string"
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
},
|
|
331
|
+
"required": [
|
|
332
|
+
"crons"
|
|
333
|
+
],
|
|
334
|
+
"additionalProperties": false
|
|
335
|
+
},
|
|
336
|
+
"Migration": {
|
|
337
|
+
"anyOf": [
|
|
338
|
+
{
|
|
339
|
+
"$ref": "#/definitions/NewClassMigration"
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
"$ref": "#/definitions/DeletedClassMigration"
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
"$ref": "#/definitions/RenamedClassMigration"
|
|
346
|
+
}
|
|
347
|
+
]
|
|
348
|
+
},
|
|
349
|
+
"NewClassMigration": {
|
|
350
|
+
"type": "object",
|
|
351
|
+
"properties": {
|
|
352
|
+
"tag": {
|
|
353
|
+
"type": "string"
|
|
354
|
+
},
|
|
355
|
+
"new_classes": {
|
|
356
|
+
"type": "array",
|
|
357
|
+
"items": {
|
|
358
|
+
"type": "string"
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
"new_sqlite_classes": {
|
|
362
|
+
"type": "array",
|
|
363
|
+
"items": {
|
|
364
|
+
"type": "string"
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
},
|
|
368
|
+
"additionalProperties": false,
|
|
369
|
+
"required": [
|
|
370
|
+
"tag"
|
|
371
|
+
]
|
|
372
|
+
},
|
|
373
|
+
"DeletedClassMigration": {
|
|
374
|
+
"type": "object",
|
|
375
|
+
"properties": {
|
|
376
|
+
"tag": {
|
|
377
|
+
"type": "string"
|
|
378
|
+
},
|
|
379
|
+
"deleted_classes": {
|
|
380
|
+
"type": "array",
|
|
381
|
+
"items": {
|
|
382
|
+
"type": "string"
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
},
|
|
386
|
+
"required": [
|
|
387
|
+
"deleted_classes",
|
|
388
|
+
"tag"
|
|
389
|
+
],
|
|
390
|
+
"additionalProperties": false
|
|
391
|
+
},
|
|
392
|
+
"RenamedClassMigration": {
|
|
393
|
+
"type": "object",
|
|
394
|
+
"properties": {
|
|
395
|
+
"tag": {
|
|
396
|
+
"type": "string"
|
|
397
|
+
},
|
|
398
|
+
"renamed_classes": {
|
|
399
|
+
"type": "array",
|
|
400
|
+
"items": {
|
|
401
|
+
"type": "object",
|
|
402
|
+
"properties": {
|
|
403
|
+
"from": {
|
|
404
|
+
"type": "string"
|
|
405
|
+
},
|
|
406
|
+
"to": {
|
|
407
|
+
"type": "string"
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
"required": [
|
|
411
|
+
"from",
|
|
412
|
+
"to"
|
|
413
|
+
],
|
|
414
|
+
"additionalProperties": false
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
},
|
|
418
|
+
"required": [
|
|
419
|
+
"renamed_classes",
|
|
420
|
+
"tag"
|
|
421
|
+
],
|
|
422
|
+
"additionalProperties": false
|
|
423
|
+
},
|
|
424
|
+
"Binding": {
|
|
425
|
+
"anyOf": [
|
|
426
|
+
{
|
|
427
|
+
"$ref": "#/definitions/MCPBinding"
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
"$ref": "#/definitions/ContractBinding"
|
|
431
|
+
}
|
|
432
|
+
]
|
|
433
|
+
},
|
|
434
|
+
"MCPBinding": {
|
|
435
|
+
"anyOf": [
|
|
436
|
+
{
|
|
437
|
+
"$ref": "#/definitions/MCPConnectionBinding"
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
"$ref": "#/definitions/MCPAppBinding"
|
|
441
|
+
}
|
|
442
|
+
]
|
|
443
|
+
},
|
|
444
|
+
"MCPConnectionBinding": {
|
|
445
|
+
"type": "object",
|
|
446
|
+
"properties": {
|
|
447
|
+
"name": {
|
|
448
|
+
"type": "string"
|
|
449
|
+
},
|
|
450
|
+
"type": {
|
|
451
|
+
"type": "string",
|
|
452
|
+
"const": "mcp"
|
|
453
|
+
},
|
|
454
|
+
"connection_id": {
|
|
455
|
+
"type": "string",
|
|
456
|
+
"description": "If not provided, will return a function that takes the integration id and return the binding implementation.."
|
|
457
|
+
}
|
|
458
|
+
},
|
|
459
|
+
"required": [
|
|
460
|
+
"connection_id",
|
|
461
|
+
"name",
|
|
462
|
+
"type"
|
|
463
|
+
],
|
|
464
|
+
"additionalProperties": false
|
|
465
|
+
},
|
|
466
|
+
"MCPAppBinding": {
|
|
467
|
+
"type": "object",
|
|
468
|
+
"properties": {
|
|
469
|
+
"name": {
|
|
470
|
+
"type": "string"
|
|
471
|
+
},
|
|
472
|
+
"type": {
|
|
473
|
+
"type": "string",
|
|
474
|
+
"const": "mcp"
|
|
475
|
+
},
|
|
476
|
+
"app_name": {
|
|
477
|
+
"type": "string",
|
|
478
|
+
"description": "The name of the integration to bind."
|
|
479
|
+
}
|
|
480
|
+
},
|
|
481
|
+
"required": [
|
|
482
|
+
"app_name",
|
|
483
|
+
"name",
|
|
484
|
+
"type"
|
|
485
|
+
],
|
|
486
|
+
"additionalProperties": false
|
|
487
|
+
},
|
|
488
|
+
"ContractBinding": {
|
|
489
|
+
"type": "object",
|
|
490
|
+
"properties": {
|
|
491
|
+
"name": {
|
|
492
|
+
"type": "string"
|
|
493
|
+
},
|
|
494
|
+
"type": {
|
|
495
|
+
"type": "string",
|
|
496
|
+
"const": "contract"
|
|
497
|
+
},
|
|
498
|
+
"contract": {
|
|
499
|
+
"$ref": "#/definitions/Contract",
|
|
500
|
+
"description": "The clauses of this contract"
|
|
501
|
+
}
|
|
502
|
+
},
|
|
503
|
+
"required": [
|
|
504
|
+
"contract",
|
|
505
|
+
"name",
|
|
506
|
+
"type"
|
|
507
|
+
],
|
|
508
|
+
"additionalProperties": false
|
|
509
|
+
},
|
|
510
|
+
"Contract": {
|
|
511
|
+
"type": "object",
|
|
512
|
+
"properties": {
|
|
513
|
+
"body": {
|
|
514
|
+
"type": "string"
|
|
515
|
+
},
|
|
516
|
+
"clauses": {
|
|
517
|
+
"type": "array",
|
|
518
|
+
"items": {
|
|
519
|
+
"$ref": "#/definitions/ContractClause"
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
},
|
|
523
|
+
"required": [
|
|
524
|
+
"body",
|
|
525
|
+
"clauses"
|
|
526
|
+
],
|
|
527
|
+
"additionalProperties": false
|
|
528
|
+
},
|
|
529
|
+
"ContractClause": {
|
|
530
|
+
"type": "object",
|
|
531
|
+
"properties": {
|
|
532
|
+
"id": {
|
|
533
|
+
"type": "string"
|
|
534
|
+
},
|
|
535
|
+
"price": {
|
|
536
|
+
"type": [
|
|
537
|
+
"string",
|
|
538
|
+
"number"
|
|
539
|
+
]
|
|
540
|
+
},
|
|
541
|
+
"description": {
|
|
542
|
+
"type": "string"
|
|
543
|
+
}
|
|
544
|
+
},
|
|
545
|
+
"required": [
|
|
546
|
+
"id",
|
|
547
|
+
"price"
|
|
548
|
+
],
|
|
549
|
+
"additionalProperties": false
|
|
550
|
+
}
|
|
551
|
+
},
|
|
552
|
+
"allowTrailingCommas": true
|
|
553
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/runtime",
|
|
3
|
-
"version": "1.0.0-alpha
|
|
3
|
+
"version": "1.0.0-alpha.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@cloudflare/workers-types": "^4.20250617.0",
|
|
7
7
|
"@deco/mcp": "npm:@jsr/deco__mcp@0.5.5",
|
|
8
|
-
"@decocms/bindings": "
|
|
8
|
+
"@decocms/bindings": "*",
|
|
9
9
|
"@mastra/core": "^0.20.2",
|
|
10
|
-
"@modelcontextprotocol/sdk": "
|
|
10
|
+
"@modelcontextprotocol/sdk": "1.20.2",
|
|
11
11
|
"@ai-sdk/provider": "^2.0.0",
|
|
12
12
|
"bidc": "0.0.3",
|
|
13
13
|
"drizzle-orm": "^0.44.5",
|
|
@@ -37,4 +37,4 @@
|
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
}
|
|
40
|
-
}
|
|
40
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -166,31 +166,36 @@ export const withBindings = <TEnv>({
|
|
|
166
166
|
let context;
|
|
167
167
|
if (typeof tokenOrContext === "string") {
|
|
168
168
|
const decoded = decodeJwt(tokenOrContext);
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
169
|
+
// Support both new JWT format (fields directly on payload) and legacy format (nested in metadata)
|
|
170
|
+
const metadata =
|
|
171
|
+
(decoded.metadata as {
|
|
172
|
+
state?: Record<string, unknown>;
|
|
173
|
+
meshUrl?: string;
|
|
174
|
+
connectionId?: string;
|
|
175
|
+
}) ?? {};
|
|
174
176
|
|
|
175
177
|
context = {
|
|
176
|
-
state: metadata.state,
|
|
178
|
+
state: decoded.state ?? metadata.state,
|
|
177
179
|
token: tokenOrContext,
|
|
178
|
-
meshUrl: metadata.meshUrl,
|
|
179
|
-
connectionId: metadata.connectionId,
|
|
180
|
-
ensureAuthenticated: AUTHENTICATED(decoded.user),
|
|
180
|
+
meshUrl: (decoded.meshUrl as string) ?? metadata.meshUrl,
|
|
181
|
+
connectionId: (decoded.connectionId as string) ?? metadata.connectionId,
|
|
182
|
+
ensureAuthenticated: AUTHENTICATED(decoded.user ?? decoded.sub),
|
|
181
183
|
} as RequestContext<any>;
|
|
182
184
|
} else if (typeof tokenOrContext === "object") {
|
|
183
185
|
context = tokenOrContext;
|
|
184
186
|
const decoded = decodeJwt(tokenOrContext.token);
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
187
|
+
// Support both new JWT format (fields directly on payload) and legacy format (nested in metadata)
|
|
188
|
+
const metadata =
|
|
189
|
+
(decoded.metadata as {
|
|
190
|
+
state?: Record<string, unknown>;
|
|
191
|
+
meshUrl?: string;
|
|
192
|
+
connectionId?: string;
|
|
193
|
+
}) ?? {};
|
|
190
194
|
const appName = decoded.appName as string | undefined;
|
|
191
195
|
context.callerApp = appName;
|
|
192
|
-
context.connectionId ??=
|
|
193
|
-
|
|
196
|
+
context.connectionId ??=
|
|
197
|
+
(decoded.connectionId as string) ?? metadata.connectionId;
|
|
198
|
+
context.ensureAuthenticated = AUTHENTICATED(decoded.user ?? decoded.sub);
|
|
194
199
|
} else {
|
|
195
200
|
// should not reach here
|
|
196
201
|
throw new Error("Invalid token or context");
|
package/src/state.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { DefaultEnv } from "./index.ts";
|
|
2
3
|
import type { AppContext } from "./tools.ts";
|
|
3
4
|
|
|
4
5
|
const asyncLocalStorage = new AsyncLocalStorage<AppContext | undefined>();
|
|
@@ -7,7 +8,7 @@ export const State = {
|
|
|
7
8
|
getStore: () => {
|
|
8
9
|
return asyncLocalStorage.getStore();
|
|
9
10
|
},
|
|
10
|
-
run: <TEnv, R, TArgs extends unknown[]>(
|
|
11
|
+
run: <TEnv extends DefaultEnv, R, TArgs extends unknown[]>(
|
|
11
12
|
ctx: AppContext<TEnv>,
|
|
12
13
|
f: (...args: TArgs) => R,
|
|
13
14
|
...args: TArgs
|
package/src/tools.ts
CHANGED
|
@@ -65,7 +65,10 @@ export type CreatedTool = {
|
|
|
65
65
|
outputSchema?: z.ZodTypeAny;
|
|
66
66
|
streamable?: true;
|
|
67
67
|
// Use a permissive execute signature - accepts any context shape
|
|
68
|
-
execute(context: {
|
|
68
|
+
execute(context: {
|
|
69
|
+
context: unknown;
|
|
70
|
+
runtimeContext: AppContext;
|
|
71
|
+
}): Promise<unknown>;
|
|
69
72
|
};
|
|
70
73
|
|
|
71
74
|
/**
|
|
@@ -80,7 +83,7 @@ export function createPrivateTool<
|
|
|
80
83
|
opts.execute = (input: ToolExecutionContext<TSchemaIn>) => {
|
|
81
84
|
const env = input.runtimeContext.env;
|
|
82
85
|
if (env) {
|
|
83
|
-
env.
|
|
86
|
+
env.MESH_REQUEST_CONTEXT?.ensureAuthenticated();
|
|
84
87
|
}
|
|
85
88
|
return execute(input);
|
|
86
89
|
};
|
|
@@ -96,7 +99,7 @@ export function createStreamableTool<
|
|
|
96
99
|
execute: (input: ToolExecutionContext<TSchemaIn>) => {
|
|
97
100
|
const env = input.runtimeContext.env;
|
|
98
101
|
if (env) {
|
|
99
|
-
env.
|
|
102
|
+
env.MESH_REQUEST_CONTEXT?.ensureAuthenticated();
|
|
100
103
|
}
|
|
101
104
|
return streamableTool.execute({
|
|
102
105
|
...input,
|
|
@@ -171,7 +174,7 @@ export type Fetch<TEnv = unknown> = (
|
|
|
171
174
|
ctx: ExecutionContext,
|
|
172
175
|
) => Promise<Response> | Response;
|
|
173
176
|
|
|
174
|
-
export interface AppContext<TEnv =
|
|
177
|
+
export interface AppContext<TEnv extends DefaultEnv = DefaultEnv> {
|
|
175
178
|
env: TEnv;
|
|
176
179
|
ctx: { waitUntil: (promise: Promise<unknown>) => void };
|
|
177
180
|
req?: Request;
|
|
@@ -180,7 +183,10 @@ export interface AppContext<TEnv = unknown> {
|
|
|
180
183
|
const decoChatOAuthToolsFor = <TSchema extends z.ZodTypeAny = never>({
|
|
181
184
|
state: schema,
|
|
182
185
|
scopes,
|
|
183
|
-
}: CreateMCPServerOptions<
|
|
186
|
+
}: CreateMCPServerOptions<
|
|
187
|
+
unknown,
|
|
188
|
+
TSchema
|
|
189
|
+
>["configuration"] = {}): CreatedTool[] => {
|
|
184
190
|
const jsonSchema = schema
|
|
185
191
|
? zodToJsonSchema(schema)
|
|
186
192
|
: { type: "object", properties: {} };
|
|
@@ -280,7 +286,7 @@ export const createMCPServer = <
|
|
|
280
286
|
result = { bytes: await result.bytes() };
|
|
281
287
|
}
|
|
282
288
|
return {
|
|
283
|
-
structuredContent: result,
|
|
289
|
+
structuredContent: result as Record<string, unknown>,
|
|
284
290
|
content: [
|
|
285
291
|
{
|
|
286
292
|
type: "text",
|
|
@@ -314,7 +320,7 @@ export const createMCPServer = <
|
|
|
314
320
|
throw new Error("Missing state, did you forget to call State.bind?");
|
|
315
321
|
}
|
|
316
322
|
const env = currentState?.env;
|
|
317
|
-
const { tools } = await createServer(env);
|
|
323
|
+
const { tools } = await createServer(env as TEnv & DefaultEnv<TSchema>);
|
|
318
324
|
const tool = tools.find((t) => t.id === toolCallId);
|
|
319
325
|
const execute = tool?.execute;
|
|
320
326
|
if (!execute) {
|