fastmcp 3.26.8 → 3.26.9
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/dist/FastMCP.cjs +45 -46
- package/dist/FastMCP.cjs.map +1 -1
- package/dist/FastMCP.js +45 -46
- package/dist/FastMCP.js.map +1 -1
- package/package.json +1 -1
package/dist/FastMCP.cjs
CHANGED
|
@@ -342,9 +342,9 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
342
342
|
#needsEventLoopFlush = false;
|
|
343
343
|
#pingConfig;
|
|
344
344
|
#pingInterval = null;
|
|
345
|
-
#prompts =
|
|
346
|
-
#resources =
|
|
347
|
-
#resourceTemplates =
|
|
345
|
+
#prompts = /* @__PURE__ */ new Map();
|
|
346
|
+
#resources = /* @__PURE__ */ new Map();
|
|
347
|
+
#resourceTemplates = /* @__PURE__ */ new Map();
|
|
348
348
|
#roots = [];
|
|
349
349
|
#rootsConfig;
|
|
350
350
|
#server;
|
|
@@ -407,16 +407,16 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
407
407
|
for (const resource of resources) {
|
|
408
408
|
this.addResource(resource);
|
|
409
409
|
}
|
|
410
|
-
this.setupResourceHandlers(
|
|
410
|
+
this.setupResourceHandlers();
|
|
411
411
|
if (resourcesTemplates.length) {
|
|
412
412
|
for (const resourceTemplate of resourcesTemplates) {
|
|
413
413
|
this.addResourceTemplate(resourceTemplate);
|
|
414
414
|
}
|
|
415
|
-
this.setupResourceTemplateHandlers(
|
|
415
|
+
this.setupResourceTemplateHandlers();
|
|
416
416
|
}
|
|
417
417
|
}
|
|
418
418
|
if (prompts.length) {
|
|
419
|
-
this.setupPromptHandlers(
|
|
419
|
+
this.setupPromptHandlers();
|
|
420
420
|
}
|
|
421
421
|
}
|
|
422
422
|
async close() {
|
|
@@ -514,30 +514,30 @@ ${e instanceof Error ? e.stack : JSON.stringify(e)}`
|
|
|
514
514
|
}
|
|
515
515
|
}
|
|
516
516
|
promptsListChanged(prompts) {
|
|
517
|
-
this.#prompts
|
|
517
|
+
this.#prompts.clear();
|
|
518
518
|
for (const prompt of prompts) {
|
|
519
519
|
this.addPrompt(prompt);
|
|
520
520
|
}
|
|
521
|
-
this.setupPromptHandlers(
|
|
521
|
+
this.setupPromptHandlers();
|
|
522
522
|
this.triggerListChangedNotification("notifications/prompts/list_changed");
|
|
523
523
|
}
|
|
524
524
|
async requestSampling(message, options) {
|
|
525
525
|
return this.#server.createMessage(message, options);
|
|
526
526
|
}
|
|
527
527
|
resourcesListChanged(resources) {
|
|
528
|
-
this.#resources
|
|
528
|
+
this.#resources.clear();
|
|
529
529
|
for (const resource of resources) {
|
|
530
530
|
this.addResource(resource);
|
|
531
531
|
}
|
|
532
|
-
this.setupResourceHandlers(
|
|
532
|
+
this.setupResourceHandlers();
|
|
533
533
|
this.triggerListChangedNotification("notifications/resources/list_changed");
|
|
534
534
|
}
|
|
535
535
|
resourceTemplatesListChanged(resourceTemplates) {
|
|
536
|
-
this.#resourceTemplates
|
|
536
|
+
this.#resourceTemplates.clear();
|
|
537
537
|
for (const resourceTemplate of resourceTemplates) {
|
|
538
538
|
this.addResourceTemplate(resourceTemplate);
|
|
539
539
|
}
|
|
540
|
-
this.setupResourceTemplateHandlers(
|
|
540
|
+
this.setupResourceTemplateHandlers();
|
|
541
541
|
this.triggerListChangedNotification("notifications/resources/list_changed");
|
|
542
542
|
}
|
|
543
543
|
toolsListChanged(tools) {
|
|
@@ -639,10 +639,10 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
639
639
|
};
|
|
640
640
|
}
|
|
641
641
|
};
|
|
642
|
-
this.#prompts.
|
|
642
|
+
this.#prompts.set(prompt.name, prompt);
|
|
643
643
|
}
|
|
644
644
|
addResource(inputResource) {
|
|
645
|
-
this.#resources.
|
|
645
|
+
this.#resources.set(inputResource.uri, inputResource);
|
|
646
646
|
}
|
|
647
647
|
addResourceTemplate(inputResourceTemplate) {
|
|
648
648
|
const completers = {};
|
|
@@ -665,13 +665,13 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
665
665
|
};
|
|
666
666
|
}
|
|
667
667
|
};
|
|
668
|
-
this.#resourceTemplates.
|
|
668
|
+
this.#resourceTemplates.set(resourceTemplate.name, resourceTemplate);
|
|
669
669
|
}
|
|
670
670
|
setupCompleteHandlers() {
|
|
671
671
|
this.#server.setRequestHandler(_typesjs.CompleteRequestSchema, async (request) => {
|
|
672
672
|
if (request.params.ref.type === "ref/prompt") {
|
|
673
673
|
const ref = request.params.ref;
|
|
674
|
-
const prompt = "name" in ref && this.#prompts.
|
|
674
|
+
const prompt = "name" in ref && this.#prompts.get(ref.name);
|
|
675
675
|
if (!prompt) {
|
|
676
676
|
throw new UnexpectedStateError("Unknown prompt", {
|
|
677
677
|
request
|
|
@@ -695,7 +695,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
695
695
|
}
|
|
696
696
|
if (request.params.ref.type === "ref/resource") {
|
|
697
697
|
const ref = request.params.ref;
|
|
698
|
-
const resource = "uri" in ref && this.#resourceTemplates.find(
|
|
698
|
+
const resource = "uri" in ref && Array.from(this.#resourceTemplates.values()).find(
|
|
699
699
|
(resource2) => resource2.uriTemplate === ref.uri
|
|
700
700
|
);
|
|
701
701
|
if (!resource) {
|
|
@@ -741,7 +741,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
741
741
|
return {};
|
|
742
742
|
});
|
|
743
743
|
}
|
|
744
|
-
setupPromptHandlers(
|
|
744
|
+
setupPromptHandlers() {
|
|
745
745
|
let cachedPromptsList = null;
|
|
746
746
|
this.#server.setRequestHandler(_typesjs.ListPromptsRequestSchema, async () => {
|
|
747
747
|
if (cachedPromptsList) {
|
|
@@ -749,7 +749,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
749
749
|
prompts: cachedPromptsList
|
|
750
750
|
};
|
|
751
751
|
}
|
|
752
|
-
cachedPromptsList = prompts.map((prompt) => {
|
|
752
|
+
cachedPromptsList = Array.from(this.#prompts.values()).map((prompt) => {
|
|
753
753
|
return {
|
|
754
754
|
arguments: prompt.arguments,
|
|
755
755
|
complete: prompt.complete,
|
|
@@ -762,9 +762,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
762
762
|
};
|
|
763
763
|
});
|
|
764
764
|
this.#server.setRequestHandler(_typesjs.GetPromptRequestSchema, async (request) => {
|
|
765
|
-
const prompt = prompts.
|
|
766
|
-
(prompt2) => prompt2.name === request.params.name
|
|
767
|
-
);
|
|
765
|
+
const prompt = this.#prompts.get(request.params.name);
|
|
768
766
|
if (!prompt) {
|
|
769
767
|
throw new (0, _typesjs.McpError)(
|
|
770
768
|
_typesjs.ErrorCode.MethodNotFound,
|
|
@@ -811,7 +809,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
811
809
|
}
|
|
812
810
|
});
|
|
813
811
|
}
|
|
814
|
-
setupResourceHandlers(
|
|
812
|
+
setupResourceHandlers() {
|
|
815
813
|
let cachedResourcesList = null;
|
|
816
814
|
this.#server.setRequestHandler(_typesjs.ListResourcesRequestSchema, async () => {
|
|
817
815
|
if (cachedResourcesList) {
|
|
@@ -819,12 +817,14 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
819
817
|
resources: cachedResourcesList
|
|
820
818
|
};
|
|
821
819
|
}
|
|
822
|
-
cachedResourcesList = resources.
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
820
|
+
cachedResourcesList = Array.from(this.#resources.values()).map(
|
|
821
|
+
(resource) => ({
|
|
822
|
+
description: resource.description,
|
|
823
|
+
mimeType: resource.mimeType,
|
|
824
|
+
name: resource.name,
|
|
825
|
+
uri: resource.uri
|
|
826
|
+
})
|
|
827
|
+
);
|
|
828
828
|
return {
|
|
829
829
|
resources: cachedResourcesList
|
|
830
830
|
};
|
|
@@ -833,11 +833,9 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
833
833
|
_typesjs.ReadResourceRequestSchema,
|
|
834
834
|
async (request) => {
|
|
835
835
|
if ("uri" in request.params) {
|
|
836
|
-
const resource = resources.
|
|
837
|
-
(resource2) => "uri" in resource2 && resource2.uri === request.params.uri
|
|
838
|
-
);
|
|
836
|
+
const resource = this.#resources.get(request.params.uri);
|
|
839
837
|
if (!resource) {
|
|
840
|
-
for (const resourceTemplate of this.#resourceTemplates) {
|
|
838
|
+
for (const resourceTemplate of this.#resourceTemplates.values()) {
|
|
841
839
|
const uriTemplate = _uritemplates2.default.call(void 0,
|
|
842
840
|
resourceTemplate.uriTemplate
|
|
843
841
|
);
|
|
@@ -847,9 +845,9 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
847
845
|
}
|
|
848
846
|
const uri = uriTemplate.fill(match);
|
|
849
847
|
const result = await resourceTemplate.load(match, this.#auth);
|
|
850
|
-
const
|
|
848
|
+
const resources = Array.isArray(result) ? result : [result];
|
|
851
849
|
return {
|
|
852
|
-
contents:
|
|
850
|
+
contents: resources.map((resource2) => ({
|
|
853
851
|
...resource2,
|
|
854
852
|
description: resourceTemplate.description,
|
|
855
853
|
mimeType: _nullishCoalesce(resource2.mimeType, () => ( resourceTemplate.mimeType)),
|
|
@@ -860,7 +858,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
860
858
|
}
|
|
861
859
|
throw new (0, _typesjs.McpError)(
|
|
862
860
|
_typesjs.ErrorCode.MethodNotFound,
|
|
863
|
-
`Resource not found: '${request.params.uri}'. Available resources: ${resources.map((r) => r.uri).join(", ") || "none"}`
|
|
861
|
+
`Resource not found: '${request.params.uri}'. Available resources: ${Array.from(this.#resources.values()).map((r) => r.uri).join(", ") || "none"}`
|
|
864
862
|
);
|
|
865
863
|
}
|
|
866
864
|
if (!("uri" in resource)) {
|
|
@@ -895,7 +893,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
895
893
|
}
|
|
896
894
|
);
|
|
897
895
|
}
|
|
898
|
-
setupResourceTemplateHandlers(
|
|
896
|
+
setupResourceTemplateHandlers() {
|
|
899
897
|
let cachedResourceTemplatesList = null;
|
|
900
898
|
this.#server.setRequestHandler(
|
|
901
899
|
_typesjs.ListResourceTemplatesRequestSchema,
|
|
@@ -905,14 +903,14 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
905
903
|
resourceTemplates: cachedResourceTemplatesList
|
|
906
904
|
};
|
|
907
905
|
}
|
|
908
|
-
cachedResourceTemplatesList =
|
|
909
|
-
(
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
);
|
|
906
|
+
cachedResourceTemplatesList = Array.from(
|
|
907
|
+
this.#resourceTemplates.values()
|
|
908
|
+
).map((resourceTemplate) => ({
|
|
909
|
+
description: resourceTemplate.description,
|
|
910
|
+
mimeType: resourceTemplate.mimeType,
|
|
911
|
+
name: resourceTemplate.name,
|
|
912
|
+
uriTemplate: resourceTemplate.uriTemplate
|
|
913
|
+
}));
|
|
916
914
|
return {
|
|
917
915
|
resourceTemplates: cachedResourceTemplatesList
|
|
918
916
|
};
|
|
@@ -957,6 +955,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
957
955
|
}
|
|
958
956
|
}
|
|
959
957
|
setupToolHandlers(tools) {
|
|
958
|
+
const toolsMap = new Map(tools.map((tool) => [tool.name, tool]));
|
|
960
959
|
let cachedToolsList = null;
|
|
961
960
|
this.#server.setRequestHandler(_typesjs.ListToolsRequestSchema, async () => {
|
|
962
961
|
if (cachedToolsList) {
|
|
@@ -983,7 +982,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
983
982
|
};
|
|
984
983
|
});
|
|
985
984
|
this.#server.setRequestHandler(_typesjs.CallToolRequestSchema, async (request) => {
|
|
986
|
-
const tool =
|
|
985
|
+
const tool = toolsMap.get(request.params.name);
|
|
987
986
|
if (!tool) {
|
|
988
987
|
throw new (0, _typesjs.McpError)(
|
|
989
988
|
_typesjs.ErrorCode.MethodNotFound,
|