@mcp-b/global 1.1.3-beta.2 → 1.1.3-beta.3
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 +51 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.iife.js +7 -5
- package/dist/index.js +52 -15
- package/dist/index.js.map +1 -1
- package/package.json +26 -10
package/dist/index.js
CHANGED
|
@@ -687,6 +687,12 @@ var WebModelContext = class {
|
|
|
687
687
|
toolUnregisterFunctions;
|
|
688
688
|
resourceUnregisterFunctions;
|
|
689
689
|
promptUnregisterFunctions;
|
|
690
|
+
/**
|
|
691
|
+
* Tracks which list change notifications are pending.
|
|
692
|
+
* Uses microtask-based batching to coalesce rapid registrations
|
|
693
|
+
* (e.g., React mount phase) into a single notification per list type.
|
|
694
|
+
*/
|
|
695
|
+
pendingNotifications = /* @__PURE__ */ new Set();
|
|
690
696
|
testingAPI;
|
|
691
697
|
/**
|
|
692
698
|
* Creates a new WebModelContext instance.
|
|
@@ -793,9 +799,9 @@ var WebModelContext = class {
|
|
|
793
799
|
this.updateBridgeTools();
|
|
794
800
|
this.updateBridgeResources();
|
|
795
801
|
this.updateBridgePrompts();
|
|
796
|
-
this.
|
|
797
|
-
this.
|
|
798
|
-
this.
|
|
802
|
+
this.scheduleListChanged("tools");
|
|
803
|
+
this.scheduleListChanged("resources");
|
|
804
|
+
this.scheduleListChanged("prompts");
|
|
799
805
|
}
|
|
800
806
|
/**
|
|
801
807
|
* Validates and normalizes a resource descriptor.
|
|
@@ -872,7 +878,7 @@ var WebModelContext = class {
|
|
|
872
878
|
this.dynamicTools.set(tool.name, validatedTool);
|
|
873
879
|
this.toolRegistrationTimestamps.set(tool.name, now);
|
|
874
880
|
this.updateBridgeTools();
|
|
875
|
-
this.
|
|
881
|
+
this.scheduleListChanged("tools");
|
|
876
882
|
const unregisterFn = () => {
|
|
877
883
|
console.log(`[Web Model Context] Unregistering tool: ${tool.name}`);
|
|
878
884
|
if (this.provideContextTools.has(tool.name)) throw new Error(`[Web Model Context] Cannot unregister tool "${tool.name}": This tool was registered via provideContext(). Use provideContext() to update the base tool set.`);
|
|
@@ -884,7 +890,7 @@ var WebModelContext = class {
|
|
|
884
890
|
this.toolRegistrationTimestamps.delete(tool.name);
|
|
885
891
|
this.toolUnregisterFunctions.delete(tool.name);
|
|
886
892
|
this.updateBridgeTools();
|
|
887
|
-
this.
|
|
893
|
+
this.scheduleListChanged("tools");
|
|
888
894
|
};
|
|
889
895
|
this.toolUnregisterFunctions.set(tool.name, unregisterFn);
|
|
890
896
|
return { unregister: unregisterFn };
|
|
@@ -912,7 +918,7 @@ var WebModelContext = class {
|
|
|
912
918
|
this.dynamicResources.set(resource.uri, validatedResource);
|
|
913
919
|
this.resourceRegistrationTimestamps.set(resource.uri, now);
|
|
914
920
|
this.updateBridgeResources();
|
|
915
|
-
this.
|
|
921
|
+
this.scheduleListChanged("resources");
|
|
916
922
|
const unregisterFn = () => {
|
|
917
923
|
console.log(`[Web Model Context] Unregistering resource: ${resource.uri}`);
|
|
918
924
|
if (this.provideContextResources.has(resource.uri)) throw new Error(`[Web Model Context] Cannot unregister resource "${resource.uri}": This resource was registered via provideContext(). Use provideContext() to update the base resource set.`);
|
|
@@ -924,7 +930,7 @@ var WebModelContext = class {
|
|
|
924
930
|
this.resourceRegistrationTimestamps.delete(resource.uri);
|
|
925
931
|
this.resourceUnregisterFunctions.delete(resource.uri);
|
|
926
932
|
this.updateBridgeResources();
|
|
927
|
-
this.
|
|
933
|
+
this.scheduleListChanged("resources");
|
|
928
934
|
};
|
|
929
935
|
this.resourceUnregisterFunctions.set(resource.uri, unregisterFn);
|
|
930
936
|
return { unregister: unregisterFn };
|
|
@@ -950,7 +956,7 @@ var WebModelContext = class {
|
|
|
950
956
|
this.resourceUnregisterFunctions.delete(uri);
|
|
951
957
|
}
|
|
952
958
|
this.updateBridgeResources();
|
|
953
|
-
this.
|
|
959
|
+
this.scheduleListChanged("resources");
|
|
954
960
|
}
|
|
955
961
|
/**
|
|
956
962
|
* Lists all registered resources in MCP format.
|
|
@@ -1003,7 +1009,7 @@ var WebModelContext = class {
|
|
|
1003
1009
|
this.dynamicPrompts.set(prompt.name, validatedPrompt);
|
|
1004
1010
|
this.promptRegistrationTimestamps.set(prompt.name, now);
|
|
1005
1011
|
this.updateBridgePrompts();
|
|
1006
|
-
this.
|
|
1012
|
+
this.scheduleListChanged("prompts");
|
|
1007
1013
|
const unregisterFn = () => {
|
|
1008
1014
|
console.log(`[Web Model Context] Unregistering prompt: ${prompt.name}`);
|
|
1009
1015
|
if (this.provideContextPrompts.has(prompt.name)) throw new Error(`[Web Model Context] Cannot unregister prompt "${prompt.name}": This prompt was registered via provideContext(). Use provideContext() to update the base prompt set.`);
|
|
@@ -1015,7 +1021,7 @@ var WebModelContext = class {
|
|
|
1015
1021
|
this.promptRegistrationTimestamps.delete(prompt.name);
|
|
1016
1022
|
this.promptUnregisterFunctions.delete(prompt.name);
|
|
1017
1023
|
this.updateBridgePrompts();
|
|
1018
|
-
this.
|
|
1024
|
+
this.scheduleListChanged("prompts");
|
|
1019
1025
|
};
|
|
1020
1026
|
this.promptUnregisterFunctions.set(prompt.name, unregisterFn);
|
|
1021
1027
|
return { unregister: unregisterFn };
|
|
@@ -1041,7 +1047,7 @@ var WebModelContext = class {
|
|
|
1041
1047
|
this.promptUnregisterFunctions.delete(name);
|
|
1042
1048
|
}
|
|
1043
1049
|
this.updateBridgePrompts();
|
|
1044
|
-
this.
|
|
1050
|
+
this.scheduleListChanged("prompts");
|
|
1045
1051
|
}
|
|
1046
1052
|
/**
|
|
1047
1053
|
* Lists all registered prompts in MCP format.
|
|
@@ -1081,7 +1087,7 @@ var WebModelContext = class {
|
|
|
1081
1087
|
this.toolUnregisterFunctions.delete(name);
|
|
1082
1088
|
}
|
|
1083
1089
|
this.updateBridgeTools();
|
|
1084
|
-
this.
|
|
1090
|
+
this.scheduleListChanged("tools");
|
|
1085
1091
|
}
|
|
1086
1092
|
/**
|
|
1087
1093
|
* Clears all registered context from both buckets (Chromium native API).
|
|
@@ -1104,9 +1110,9 @@ var WebModelContext = class {
|
|
|
1104
1110
|
this.updateBridgeTools();
|
|
1105
1111
|
this.updateBridgeResources();
|
|
1106
1112
|
this.updateBridgePrompts();
|
|
1107
|
-
this.
|
|
1108
|
-
this.
|
|
1109
|
-
this.
|
|
1113
|
+
this.scheduleListChanged("tools");
|
|
1114
|
+
this.scheduleListChanged("resources");
|
|
1115
|
+
this.scheduleListChanged("prompts");
|
|
1110
1116
|
}
|
|
1111
1117
|
/**
|
|
1112
1118
|
* Updates the bridge tools map with merged tools from both buckets.
|
|
@@ -1190,6 +1196,37 @@ var WebModelContext = class {
|
|
|
1190
1196
|
});
|
|
1191
1197
|
}
|
|
1192
1198
|
/**
|
|
1199
|
+
* Schedules a list changed notification using microtask batching.
|
|
1200
|
+
* Multiple calls for the same list type within the same task are coalesced
|
|
1201
|
+
* into a single notification. This dramatically reduces notification spam
|
|
1202
|
+
* during React mount/unmount cycles.
|
|
1203
|
+
*
|
|
1204
|
+
* @param listType - The type of list that changed ('tools' | 'resources' | 'prompts')
|
|
1205
|
+
* @private
|
|
1206
|
+
*/
|
|
1207
|
+
scheduleListChanged(listType) {
|
|
1208
|
+
if (this.pendingNotifications.has(listType)) return;
|
|
1209
|
+
this.pendingNotifications.add(listType);
|
|
1210
|
+
queueMicrotask(() => {
|
|
1211
|
+
this.pendingNotifications.delete(listType);
|
|
1212
|
+
switch (listType) {
|
|
1213
|
+
case "tools":
|
|
1214
|
+
this.notifyToolsListChanged();
|
|
1215
|
+
break;
|
|
1216
|
+
case "resources":
|
|
1217
|
+
this.notifyResourcesListChanged();
|
|
1218
|
+
break;
|
|
1219
|
+
case "prompts":
|
|
1220
|
+
this.notifyPromptsListChanged();
|
|
1221
|
+
break;
|
|
1222
|
+
default: {
|
|
1223
|
+
const _exhaustive = listType;
|
|
1224
|
+
console.error(`[Web Model Context] Unknown list type: ${_exhaustive}`);
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
});
|
|
1228
|
+
}
|
|
1229
|
+
/**
|
|
1193
1230
|
* Reads a resource by URI (internal use only by MCP bridge).
|
|
1194
1231
|
* Handles both static resources and URI templates.
|
|
1195
1232
|
*
|