fastmcp 4.4.0 → 4.6.0

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.
@@ -526,6 +526,9 @@ ${e instanceof Error ? e.stack : JSON.stringify(e)}`
526
526
  this.setupPromptHandlers();
527
527
  this.triggerListChangedNotification("notifications/prompts/list_changed");
528
528
  }
529
+ async requestElicitation(params, options) {
530
+ return this.#server.elicitInput(params, options);
531
+ }
529
532
  async requestSampling(message, options) {
530
533
  return this.#server.createMessage(message, options);
531
534
  }
@@ -599,9 +602,71 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
599
602
  });
600
603
  });
601
604
  }
605
+ /**
606
+ * Builds the context object passed as the third argument to
607
+ * `resource.load` / `resourceTemplate.load` / `prompt.load`.
608
+ *
609
+ * This mirrors the `client`, `elicit`, `log`, `requestId`, `session`,
610
+ * and `sessionId` fields available to `tool.execute` via {@link Context}.
611
+ * `reportProgress` and `streamContent` are intentionally omitted: they
612
+ * are tied to a tool call's progress token / streaming notification,
613
+ * which resource and prompt reads do not have.
614
+ */
615
+ #createLoadContext(meta) {
616
+ return {
617
+ client: {
618
+ version: this.#server.getClientVersion()
619
+ },
620
+ elicit: (params, options) => this.#server.elicitInput(params, options),
621
+ log: this.#createLog(),
622
+ requestId: typeof _optionalChain([meta, 'optionalAccess', _12 => _12.requestId]) === "string" ? meta.requestId : void 0,
623
+ session: this.#auth,
624
+ sessionId: this.#sessionId
625
+ };
626
+ }
627
+ #createLog() {
628
+ return {
629
+ debug: (message, context) => {
630
+ this.#server.sendLoggingMessage({
631
+ data: {
632
+ context,
633
+ message
634
+ },
635
+ level: "debug"
636
+ });
637
+ },
638
+ error: (message, context) => {
639
+ this.#server.sendLoggingMessage({
640
+ data: {
641
+ context,
642
+ message
643
+ },
644
+ level: "error"
645
+ });
646
+ },
647
+ info: (message, context) => {
648
+ this.#server.sendLoggingMessage({
649
+ data: {
650
+ context,
651
+ message
652
+ },
653
+ level: "info"
654
+ });
655
+ },
656
+ warn: (message, context) => {
657
+ this.#server.sendLoggingMessage({
658
+ data: {
659
+ context,
660
+ message
661
+ },
662
+ level: "warning"
663
+ });
664
+ }
665
+ };
666
+ }
602
667
  #formatSchemaIssues(issues) {
603
- return _optionalChain([this, 'access', _12 => _12.#utils, 'optionalAccess', _13 => _13.formatInvalidParamsErrorMessage]) ? this.#utils.formatInvalidParamsErrorMessage(issues) : issues.map((issue) => {
604
- const path = _optionalChain([issue, 'access', _14 => _14.path, 'optionalAccess', _15 => _15.join, 'call', _16 => _16(".")]) || "root";
668
+ return _optionalChain([this, 'access', _13 => _13.#utils, 'optionalAccess', _14 => _14.formatInvalidParamsErrorMessage]) ? this.#utils.formatInvalidParamsErrorMessage(issues) : issues.map((issue) => {
669
+ const path = _optionalChain([issue, 'access', _15 => _15.path, 'optionalAccess', _16 => _16.join, 'call', _17 => _17(".")]) || "root";
605
670
  return `${path}: ${issue.message}`;
606
671
  }).join(", ");
607
672
  }
@@ -812,7 +877,8 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
812
877
  try {
813
878
  result = await prompt.load(
814
879
  args,
815
- this.#auth
880
+ this.#auth,
881
+ this.#createLoadContext(_optionalChain([request, 'access', _18 => _18.params, 'optionalAccess', _19 => _19._meta]))
816
882
  );
817
883
  } catch (error) {
818
884
  const errorMessage = error instanceof Error ? error.message : String(error);
@@ -874,7 +940,11 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
874
940
  continue;
875
941
  }
876
942
  const uri = uriTemplate.fill(match);
877
- const result = await resourceTemplate.load(match, this.#auth);
943
+ const result = await resourceTemplate.load(
944
+ match,
945
+ this.#auth,
946
+ this.#createLoadContext(_optionalChain([request, 'access', _20 => _20.params, 'optionalAccess', _21 => _21._meta]))
947
+ );
878
948
  const resources = Array.isArray(result) ? result : [result];
879
949
  return {
880
950
  contents: resources.map((resource2) => ({
@@ -896,7 +966,10 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
896
966
  }
897
967
  let maybeArrayResult;
898
968
  try {
899
- maybeArrayResult = await resource.load(this.#auth);
969
+ maybeArrayResult = await resource.load(
970
+ this.#auth,
971
+ this.#createLoadContext(_optionalChain([request, 'access', _22 => _22.params, 'optionalAccess', _23 => _23._meta]))
972
+ );
900
973
  } catch (error) {
901
974
  const errorMessage = error instanceof Error ? error.message : String(error);
902
975
  throw new (0, _typesjs.McpError)(
@@ -948,7 +1021,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
948
1021
  );
949
1022
  }
950
1023
  setupRootsHandlers() {
951
- if (_optionalChain([this, 'access', _17 => _17.#rootsConfig, 'optionalAccess', _18 => _18.enabled]) === false) {
1024
+ if (_optionalChain([this, 'access', _24 => _24.#rootsConfig, 'optionalAccess', _25 => _25.enabled]) === false) {
952
1025
  this.#logger.debug(
953
1026
  "[FastMCP debug] roots capability explicitly disabled via config"
954
1027
  );
@@ -1040,7 +1113,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
1040
1113
  }
1041
1114
  args = parsed.value;
1042
1115
  }
1043
- const progressToken = _optionalChain([request, 'access', _19 => _19.params, 'optionalAccess', _20 => _20._meta, 'optionalAccess', _21 => _21.progressToken]);
1116
+ const progressToken = _optionalChain([request, 'access', _26 => _26.params, 'optionalAccess', _27 => _27._meta, 'optionalAccess', _28 => _28.progressToken]);
1044
1117
  let result;
1045
1118
  try {
1046
1119
  const reportProgress = async (progress) => {
@@ -1065,44 +1138,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
1065
1138
  );
1066
1139
  }
1067
1140
  };
1068
- const log = {
1069
- debug: (message, context) => {
1070
- this.#server.sendLoggingMessage({
1071
- data: {
1072
- context,
1073
- message
1074
- },
1075
- level: "debug"
1076
- });
1077
- },
1078
- error: (message, context) => {
1079
- this.#server.sendLoggingMessage({
1080
- data: {
1081
- context,
1082
- message
1083
- },
1084
- level: "error"
1085
- });
1086
- },
1087
- info: (message, context) => {
1088
- this.#server.sendLoggingMessage({
1089
- data: {
1090
- context,
1091
- message
1092
- },
1093
- level: "info"
1094
- });
1095
- },
1096
- warn: (message, context) => {
1097
- this.#server.sendLoggingMessage({
1098
- data: {
1099
- context,
1100
- message
1101
- },
1102
- level: "warning"
1103
- });
1104
- }
1105
- };
1141
+ const log = this.#createLog();
1106
1142
  const streamContent = async (content) => {
1107
1143
  const contentArray = Array.isArray(content) ? content : [content];
1108
1144
  try {
@@ -1133,9 +1169,10 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
1133
1169
  client: {
1134
1170
  version: this.#server.getClientVersion()
1135
1171
  },
1172
+ elicit: (params, options) => this.#server.elicitInput(params, options),
1136
1173
  log,
1137
1174
  reportProgress,
1138
- requestId: typeof _optionalChain([request, 'access', _22 => _22.params, 'optionalAccess', _23 => _23._meta, 'optionalAccess', _24 => _24.requestId]) === "string" ? request.params._meta.requestId : void 0,
1175
+ requestId: typeof _optionalChain([request, 'access', _29 => _29.params, 'optionalAccess', _30 => _30._meta, 'optionalAccess', _31 => _31.requestId]) === "string" ? request.params._meta.requestId : void 0,
1139
1176
  session: this.#auth,
1140
1177
  sessionId: this.#sessionId,
1141
1178
  streamContent
@@ -1245,7 +1282,7 @@ function normalizePath(path) {
1245
1282
  return path.startsWith("/") ? path : `/${path}`;
1246
1283
  }
1247
1284
  function parseBasicAuthHeader(authHeader) {
1248
- const basicMatch = _optionalChain([authHeader, 'optionalAccess', _25 => _25.match, 'call', _26 => _26(/^Basic\s+(.+)$/)]);
1285
+ const basicMatch = _optionalChain([authHeader, 'optionalAccess', _32 => _32.match, 'call', _33 => _33(/^Basic\s+(.+)$/)]);
1249
1286
  if (!basicMatch) return null;
1250
1287
  try {
1251
1288
  const credentials = Buffer.from(basicMatch[1], "base64").toString("utf-8");
@@ -1647,7 +1684,7 @@ var FastMCP = class extends FastMCPEventEmitter {
1647
1684
  enableJsonResponse: httpConfig.enableJsonResponse,
1648
1685
  eventStore: httpConfig.eventStore,
1649
1686
  host: httpConfig.host,
1650
- ..._optionalChain([this, 'access', _27 => _27.#options, 'access', _28 => _28.oauth, 'optionalAccess', _29 => _29.enabled]) && _optionalChain([this, 'access', _30 => _30.#options, 'access', _31 => _31.oauth, 'access', _32 => _32.protectedResource, 'optionalAccess', _33 => _33.resource]) ? {
1687
+ ..._optionalChain([this, 'access', _34 => _34.#options, 'access', _35 => _35.oauth, 'optionalAccess', _36 => _36.enabled]) && _optionalChain([this, 'access', _37 => _37.#options, 'access', _38 => _38.oauth, 'access', _39 => _39.protectedResource, 'optionalAccess', _40 => _40.resource]) ? {
1651
1688
  oauth: {
1652
1689
  protectedResource: {
1653
1690
  resource: this.#options.oauth.protectedResource.resource
@@ -1694,7 +1731,7 @@ var FastMCP = class extends FastMCPEventEmitter {
1694
1731
  enableJsonResponse: httpConfig.enableJsonResponse,
1695
1732
  eventStore: httpConfig.eventStore,
1696
1733
  host: httpConfig.host,
1697
- ..._optionalChain([this, 'access', _34 => _34.#options, 'access', _35 => _35.oauth, 'optionalAccess', _36 => _36.enabled]) && _optionalChain([this, 'access', _37 => _37.#options, 'access', _38 => _38.oauth, 'access', _39 => _39.protectedResource, 'optionalAccess', _40 => _40.resource]) ? {
1734
+ ..._optionalChain([this, 'access', _41 => _41.#options, 'access', _42 => _42.oauth, 'optionalAccess', _43 => _43.enabled]) && _optionalChain([this, 'access', _44 => _44.#options, 'access', _45 => _45.oauth, 'access', _46 => _46.protectedResource, 'optionalAccess', _47 => _47.resource]) ? {
1698
1735
  oauth: {
1699
1736
  protectedResource: {
1700
1737
  resource: this.#options.oauth.protectedResource.resource
@@ -1867,7 +1904,7 @@ var FastMCP = class extends FastMCPEventEmitter {
1867
1904
  }
1868
1905
  }
1869
1906
  const oauthConfig = this.#options.oauth;
1870
- if (_optionalChain([oauthConfig, 'optionalAccess', _41 => _41.enabled]) && req.method === "GET") {
1907
+ if (_optionalChain([oauthConfig, 'optionalAccess', _48 => _48.enabled]) && req.method === "GET") {
1871
1908
  const url2 = new URL(req.url || "", `http://${host}`);
1872
1909
  const authorizationServerMetadataPath = joinPaths(
1873
1910
  "",
@@ -1901,8 +1938,8 @@ var FastMCP = class extends FastMCPEventEmitter {
1901
1938
  }
1902
1939
  }
1903
1940
  }
1904
- const oauthProxy = _optionalChain([oauthConfig, 'optionalAccess', _42 => _42.proxy]);
1905
- if (oauthProxy && _optionalChain([oauthConfig, 'optionalAccess', _43 => _43.enabled])) {
1941
+ const oauthProxy = _optionalChain([oauthConfig, 'optionalAccess', _49 => _49.proxy]);
1942
+ if (oauthProxy && _optionalChain([oauthConfig, 'optionalAccess', _50 => _50.enabled])) {
1906
1943
  const url2 = new URL(req.url || "", `http://${host}`);
1907
1944
  const oauthPath = basePathRelativePath;
1908
1945
  try {
@@ -1919,7 +1956,7 @@ var FastMCP = class extends FastMCPEventEmitter {
1919
1956
  const statusCode = error.statusCode || 400;
1920
1957
  res.writeHead(statusCode, { "Content-Type": "application/json" }).end(
1921
1958
  JSON.stringify(
1922
- _optionalChain([error, 'access', _44 => _44.toJSON, 'optionalCall', _45 => _45()]) || {
1959
+ _optionalChain([error, 'access', _51 => _51.toJSON, 'optionalCall', _52 => _52()]) || {
1923
1960
  error: "invalid_request"
1924
1961
  }
1925
1962
  )
@@ -1946,7 +1983,7 @@ var FastMCP = class extends FastMCPEventEmitter {
1946
1983
  } catch (error) {
1947
1984
  res.writeHead(400, { "Content-Type": "application/json" }).end(
1948
1985
  JSON.stringify(
1949
- _optionalChain([error, 'access', _46 => _46.toJSON, 'optionalCall', _47 => _47()]) || {
1986
+ _optionalChain([error, 'access', _53 => _53.toJSON, 'optionalCall', _54 => _54()]) || {
1950
1987
  error: "invalid_request"
1951
1988
  }
1952
1989
  )
@@ -1968,7 +2005,7 @@ var FastMCP = class extends FastMCPEventEmitter {
1968
2005
  } catch (error) {
1969
2006
  res.writeHead(400, { "Content-Type": "application/json" }).end(
1970
2007
  JSON.stringify(
1971
- _optionalChain([error, 'access', _48 => _48.toJSON, 'optionalCall', _49 => _49()]) || {
2008
+ _optionalChain([error, 'access', _55 => _55.toJSON, 'optionalCall', _56 => _56()]) || {
1972
2009
  error: "server_error"
1973
2010
  }
1974
2011
  )
@@ -2003,7 +2040,7 @@ var FastMCP = class extends FastMCPEventEmitter {
2003
2040
  } catch (error) {
2004
2041
  res.writeHead(400, { "Content-Type": "application/json" }).end(
2005
2042
  JSON.stringify(
2006
- _optionalChain([error, 'access', _50 => _50.toJSON, 'optionalCall', _51 => _51()]) || {
2043
+ _optionalChain([error, 'access', _57 => _57.toJSON, 'optionalCall', _58 => _58()]) || {
2007
2044
  error: "server_error"
2008
2045
  }
2009
2046
  )
@@ -2025,8 +2062,8 @@ var FastMCP = class extends FastMCPEventEmitter {
2025
2062
  const basicAuth = parseBasicAuthHeader(
2026
2063
  req.headers.authorization
2027
2064
  );
2028
- const clientId = _optionalChain([basicAuth, 'optionalAccess', _52 => _52.clientId]) || params.get("client_id") || "";
2029
- const clientSecret = _nullishCoalesce(_nullishCoalesce(_optionalChain([basicAuth, 'optionalAccess', _53 => _53.clientSecret]), () => ( params.get("client_secret"))), () => ( void 0));
2065
+ const clientId = _optionalChain([basicAuth, 'optionalAccess', _59 => _59.clientId]) || params.get("client_id") || "";
2066
+ const clientSecret = _nullishCoalesce(_nullishCoalesce(_optionalChain([basicAuth, 'optionalAccess', _60 => _60.clientSecret]), () => ( params.get("client_secret"))), () => ( void 0));
2030
2067
  let response;
2031
2068
  if (grantType === "authorization_code") {
2032
2069
  response = await oauthProxy.exchangeAuthorizationCode({
@@ -2056,7 +2093,7 @@ var FastMCP = class extends FastMCPEventEmitter {
2056
2093
  const statusCode = error.statusCode || 400;
2057
2094
  res.writeHead(statusCode, { "Content-Type": "application/json" }).end(
2058
2095
  JSON.stringify(
2059
- _optionalChain([error, 'access', _54 => _54.toJSON, 'optionalCall', _55 => _55()]) || {
2096
+ _optionalChain([error, 'access', _61 => _61.toJSON, 'optionalCall', _62 => _62()]) || {
2060
2097
  error: "invalid_request"
2061
2098
  }
2062
2099
  )
@@ -2127,23 +2164,23 @@ var FastMCP = class extends FastMCPEventEmitter {
2127
2164
  const envBasePath = process.env.FASTMCP_BASE_PATH;
2128
2165
  const envStateless = process.env.FASTMCP_STATELESS;
2129
2166
  const envHost = process.env.FASTMCP_HOST;
2130
- const transportType = _optionalChain([overrides, 'optionalAccess', _56 => _56.transportType]) || (transportArg === "http-stream" ? "httpStream" : transportArg) || envTransport || "stdio";
2167
+ const transportType = _optionalChain([overrides, 'optionalAccess', _63 => _63.transportType]) || (transportArg === "http-stream" ? "httpStream" : transportArg) || envTransport || "stdio";
2131
2168
  if (transportType === "httpStream") {
2132
2169
  const port = parseInt(
2133
- _optionalChain([overrides, 'optionalAccess', _57 => _57.httpStream, 'optionalAccess', _58 => _58.port, 'optionalAccess', _59 => _59.toString, 'call', _60 => _60()]) || portArg || envPort || "8080"
2170
+ _optionalChain([overrides, 'optionalAccess', _64 => _64.httpStream, 'optionalAccess', _65 => _65.port, 'optionalAccess', _66 => _66.toString, 'call', _67 => _67()]) || portArg || envPort || "8080"
2134
2171
  );
2135
- const host = _optionalChain([overrides, 'optionalAccess', _61 => _61.httpStream, 'optionalAccess', _62 => _62.host]) || hostArg || envHost || "localhost";
2136
- const endpoint = _optionalChain([overrides, 'optionalAccess', _63 => _63.httpStream, 'optionalAccess', _64 => _64.endpoint]) || endpointArg || envEndpoint || "/mcp";
2172
+ const host = _optionalChain([overrides, 'optionalAccess', _68 => _68.httpStream, 'optionalAccess', _69 => _69.host]) || hostArg || envHost || "localhost";
2173
+ const endpoint = _optionalChain([overrides, 'optionalAccess', _70 => _70.httpStream, 'optionalAccess', _71 => _71.endpoint]) || endpointArg || envEndpoint || "/mcp";
2137
2174
  const basePath = normalizeBasePath(
2138
- _optionalChain([overrides, 'optionalAccess', _65 => _65.httpStream, 'optionalAccess', _66 => _66.basePath]) || basePathArg || envBasePath
2175
+ _optionalChain([overrides, 'optionalAccess', _72 => _72.httpStream, 'optionalAccess', _73 => _73.basePath]) || basePathArg || envBasePath
2139
2176
  );
2140
- const enableJsonResponse = _optionalChain([overrides, 'optionalAccess', _67 => _67.httpStream, 'optionalAccess', _68 => _68.enableJsonResponse]) || false;
2141
- const stateless = _optionalChain([overrides, 'optionalAccess', _69 => _69.httpStream, 'optionalAccess', _70 => _70.stateless]) || statelessArg === "true" || envStateless === "true" || false;
2142
- const cors = _optionalChain([overrides, 'optionalAccess', _71 => _71.httpStream, 'optionalAccess', _72 => _72.cors]);
2143
- const eventStore = _optionalChain([overrides, 'optionalAccess', _73 => _73.httpStream, 'optionalAccess', _74 => _74.eventStore]);
2144
- const sslCa = _optionalChain([overrides, 'optionalAccess', _75 => _75.httpStream, 'optionalAccess', _76 => _76.sslCa]);
2145
- const sslCert = _optionalChain([overrides, 'optionalAccess', _77 => _77.httpStream, 'optionalAccess', _78 => _78.sslCert]);
2146
- const sslKey = _optionalChain([overrides, 'optionalAccess', _79 => _79.httpStream, 'optionalAccess', _80 => _80.sslKey]);
2177
+ const enableJsonResponse = _optionalChain([overrides, 'optionalAccess', _74 => _74.httpStream, 'optionalAccess', _75 => _75.enableJsonResponse]) || false;
2178
+ const stateless = _optionalChain([overrides, 'optionalAccess', _76 => _76.httpStream, 'optionalAccess', _77 => _77.stateless]) || statelessArg === "true" || envStateless === "true" || false;
2179
+ const cors = _optionalChain([overrides, 'optionalAccess', _78 => _78.httpStream, 'optionalAccess', _79 => _79.cors]);
2180
+ const eventStore = _optionalChain([overrides, 'optionalAccess', _80 => _80.httpStream, 'optionalAccess', _81 => _81.eventStore]);
2181
+ const sslCa = _optionalChain([overrides, 'optionalAccess', _82 => _82.httpStream, 'optionalAccess', _83 => _83.sslCa]);
2182
+ const sslCert = _optionalChain([overrides, 'optionalAccess', _84 => _84.httpStream, 'optionalAccess', _85 => _85.sslCert]);
2183
+ const sslKey = _optionalChain([overrides, 'optionalAccess', _86 => _86.httpStream, 'optionalAccess', _87 => _87.sslKey]);
2147
2184
  return {
2148
2185
  httpStream: {
2149
2186
  basePath,
@@ -2216,4 +2253,4 @@ var FastMCP = class extends FastMCPEventEmitter {
2216
2253
 
2217
2254
 
2218
2255
  exports.DiscoveryDocumentCache = DiscoveryDocumentCache; exports.imageContent = imageContent; exports.audioContent = audioContent; exports.UnexpectedStateError = UnexpectedStateError; exports.UserError = UserError; exports.ServerState = ServerState; exports.FastMCPSession = FastMCPSession; exports.FastMCP = FastMCP;
2219
- //# sourceMappingURL=chunk-3YTRRGCE.cjs.map
2256
+ //# sourceMappingURL=chunk-VBRUMQDO.cjs.map