fastmcp 4.23.7 → 4.23.8

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.
Files changed (39) hide show
  1. package/dist/FastMCP.cjs +4 -4
  2. package/dist/FastMCP.d.cts +1 -1
  3. package/dist/FastMCP.d.ts +1 -1
  4. package/dist/FastMCP.js +3 -3
  5. package/dist/auth/index.cjs +2 -2
  6. package/dist/auth/index.js +1 -1
  7. package/dist/bin/fastmcp.cjs +7 -1
  8. package/dist/bin/fastmcp.cjs.map +1 -1
  9. package/dist/bin/fastmcp.js +7 -1
  10. package/dist/bin/fastmcp.js.map +1 -1
  11. package/dist/{chunk-C7TBI7A5.cjs → chunk-AJRXMUZR.cjs} +8 -4
  12. package/dist/chunk-AJRXMUZR.cjs.map +1 -0
  13. package/dist/{chunk-YZ5QEHBX.js → chunk-F76U45MT.js} +11 -3
  14. package/dist/chunk-F76U45MT.js.map +1 -0
  15. package/dist/{chunk-7WNI6AGD.js → chunk-PLUAEIWE.js} +42 -19
  16. package/dist/chunk-PLUAEIWE.js.map +1 -0
  17. package/dist/{chunk-MPFPOZ2H.cjs → chunk-T2F3RYH2.cjs} +12 -4
  18. package/dist/chunk-T2F3RYH2.cjs.map +1 -0
  19. package/dist/{chunk-CA2EPNZF.js → chunk-UY253ACS.js} +8 -4
  20. package/dist/chunk-UY253ACS.js.map +1 -0
  21. package/dist/{chunk-TBMRFQ6M.cjs → chunk-XEP3OP7Q.cjs} +99 -76
  22. package/dist/chunk-XEP3OP7Q.cjs.map +1 -0
  23. package/dist/edge/index.cjs +8 -4
  24. package/dist/edge/index.cjs.map +1 -1
  25. package/dist/edge/index.js +6 -2
  26. package/dist/edge/index.js.map +1 -1
  27. package/dist/examples/custom-routes.cjs +4 -4
  28. package/dist/examples/custom-routes.js +3 -3
  29. package/dist/openapi/index.cjs +17 -12
  30. package/dist/openapi/index.cjs.map +1 -1
  31. package/dist/openapi/index.js +12 -7
  32. package/dist/openapi/index.js.map +1 -1
  33. package/package.json +1 -1
  34. package/dist/chunk-7WNI6AGD.js.map +0 -1
  35. package/dist/chunk-C7TBI7A5.cjs.map +0 -1
  36. package/dist/chunk-CA2EPNZF.js.map +0 -1
  37. package/dist/chunk-MPFPOZ2H.cjs.map +0 -1
  38. package/dist/chunk-TBMRFQ6M.cjs.map +0 -1
  39. package/dist/chunk-YZ5QEHBX.js.map +0 -1
@@ -1,10 +1,11 @@
1
1
  import {
2
2
  cancelResponseBody
3
- } from "./chunk-CA2EPNZF.js";
3
+ } from "./chunk-UY253ACS.js";
4
4
  import {
5
+ objectRootSchema,
5
6
  strictInputSchema,
6
7
  zodInputSchema
7
- } from "./chunk-YZ5QEHBX.js";
8
+ } from "./chunk-F76U45MT.js";
8
9
 
9
10
  // src/FastMCP.ts
10
11
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
@@ -186,9 +187,11 @@ function jsonSchemaAdapter(schema) {
186
187
  };
187
188
  }
188
189
  async function compileSchema(schema) {
190
+ const dialect = schema.$schema?.replace(/^http:\/\//, "https://").replace(/#$/, "");
191
+ const isDraft2020 = dialect === "https://json-schema.org/draft/2020-12/schema";
189
192
  let ajvModule;
190
193
  try {
191
- ajvModule = await import("ajv");
194
+ ajvModule = isDraft2020 ? await import("ajv/dist/2020.js") : await import("ajv");
192
195
  } catch {
193
196
  throw new Error(
194
197
  'The "ajv" package is required to validate JSON Schema tool parameters. Install it with: npm install ajv'
@@ -204,7 +207,7 @@ async function compileSchema(schema) {
204
207
  addFormats(ajv);
205
208
  } catch {
206
209
  }
207
- return ajv.compile(schema);
210
+ return ajv.compile(isDraft2020 ? { ...schema, $schema: dialect } : schema);
208
211
  }
209
212
  function toIssue(error) {
210
213
  const path = error.instancePath.split("/").slice(1).map((segment) => segment.replaceAll("~1", "/").replaceAll("~0", "~")).map((segment) => {
@@ -1571,8 +1574,8 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
1571
1574
  },
1572
1575
  name: tool.name,
1573
1576
  ...tool.outputSchema && {
1574
- outputSchema: await toJsonSchema(
1575
- tool.outputSchema
1577
+ outputSchema: objectRootSchema(
1578
+ await toJsonSchema(tool.outputSchema)
1576
1579
  )
1577
1580
  },
1578
1581
  // Pass through _meta for MCP ext-apps UI support (issue #229)
@@ -1745,10 +1748,22 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
1745
1748
  }
1746
1749
  } catch (error) {
1747
1750
  if (error instanceof UserError) {
1751
+ let structuredContent = error.extras;
1752
+ if (structuredContent && tool.outputSchema) {
1753
+ try {
1754
+ structuredContent = await this.#validateStructuredContent(
1755
+ tool,
1756
+ structuredContent,
1757
+ request.params.name
1758
+ );
1759
+ } catch {
1760
+ structuredContent = void 0;
1761
+ }
1762
+ }
1748
1763
  return {
1749
1764
  content: [{ text: error.message, type: "text" }],
1750
1765
  isError: true,
1751
- ...error.extras ? { structuredContent: error.extras } : {}
1766
+ ...structuredContent ? { structuredContent } : {}
1752
1767
  };
1753
1768
  }
1754
1769
  const errorMessage = error instanceof Error ? error.message : String(error);
@@ -1964,7 +1979,9 @@ var FastMCP = class extends FastMCPEventEmitter {
1964
1979
  * Adds a resource to the server.
1965
1980
  */
1966
1981
  addResource(resource) {
1967
- this.#resources = this.#resources.filter((r) => r.name !== resource.name);
1982
+ this.#resources = this.#resources.filter(
1983
+ (r) => r.name !== resource.name && r.uri !== resource.uri
1984
+ );
1968
1985
  this.#resources.push(resource);
1969
1986
  if (this.#serverState === "running" /* Running */) {
1970
1987
  this.#resourcesListChanged(this.#resources);
@@ -1974,13 +1991,12 @@ var FastMCP = class extends FastMCPEventEmitter {
1974
1991
  * Adds resources to the server.
1975
1992
  */
1976
1993
  addResources(resources) {
1977
- const newResourceNames = new Set(
1978
- resources.map((resource) => resource.name)
1979
- );
1980
- this.#resources = this.#resources.filter(
1981
- (r) => !newResourceNames.has(r.name)
1982
- );
1983
- this.#resources.push(...resources);
1994
+ for (const resource of resources) {
1995
+ this.#resources = this.#resources.filter(
1996
+ (r) => r.name !== resource.name && r.uri !== resource.uri
1997
+ );
1998
+ this.#resources.push(resource);
1999
+ }
1984
2000
  if (this.#serverState === "running" /* Running */) {
1985
2001
  this.#resourcesListChanged(this.#resources);
1986
2002
  }
@@ -2028,9 +2044,12 @@ var FastMCP = class extends FastMCPEventEmitter {
2028
2044
  */
2029
2045
  addTools(tools) {
2030
2046
  tools.forEach(assertToolSchemas);
2031
- const newToolNames = new Set(tools.map((tool) => tool.name));
2032
- this.#tools = this.#tools.filter((t) => !newToolNames.has(t.name));
2033
- this.#tools.push(...tools);
2047
+ const toolsByName = new Map(this.#tools.map((tool) => [tool.name, tool]));
2048
+ for (const tool of tools) {
2049
+ toolsByName.delete(tool.name);
2050
+ toolsByName.set(tool.name, tool);
2051
+ }
2052
+ this.#tools = Array.from(toolsByName.values());
2034
2053
  if (this.#serverState === "running" /* Running */) {
2035
2054
  this.#toolsListChanged(this.#tools);
2036
2055
  }
@@ -2332,6 +2351,9 @@ var FastMCP = class extends FastMCPEventEmitter {
2332
2351
  this.#serverState = "running" /* Running */;
2333
2352
  }
2334
2353
  } else if (config.transportType === "httpStream") {
2354
+ if (this.#httpStreamServer) {
2355
+ throw new Error("HTTP server is already running");
2356
+ }
2335
2357
  const httpConfig = config.httpStream;
2336
2358
  const protocol = httpConfig.sslCert || httpConfig.sslKey ? "https" : "http";
2337
2359
  const streamEndpoint = joinPaths(
@@ -2461,6 +2483,7 @@ var FastMCP = class extends FastMCPEventEmitter {
2461
2483
  );
2462
2484
  if (this.#httpStreamServer) {
2463
2485
  await this.#httpStreamServer.close();
2486
+ this.#httpStreamServer = null;
2464
2487
  }
2465
2488
  this.#serverState = "stopped" /* Stopped */;
2466
2489
  }
@@ -3247,4 +3270,4 @@ export {
3247
3270
  FastMCPSession,
3248
3271
  FastMCP
3249
3272
  };
3250
- //# sourceMappingURL=chunk-7WNI6AGD.js.map
3273
+ //# sourceMappingURL=chunk-PLUAEIWE.js.map