fastmcp 4.0.0 → 4.0.1

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.
@@ -1819,23 +1819,26 @@ var FastMCP = class extends FastMCPEventEmitter {
1819
1819
  const url2 = new URL(req.url || "", `http://${host}`);
1820
1820
  try {
1821
1821
  if (req.method === "POST" && url2.pathname === "/oauth/register") {
1822
- let body = "";
1823
- req.on("data", (chunk) => body += chunk);
1824
- req.on("end", async () => {
1825
- try {
1826
- const request = JSON.parse(body);
1827
- const response = await oauthProxy.registerClient(request);
1828
- res.writeHead(201, { "Content-Type": "application/json" }).end(JSON.stringify(response));
1829
- } catch (error) {
1830
- const statusCode = error.statusCode || 400;
1831
- res.writeHead(statusCode, { "Content-Type": "application/json" }).end(
1832
- JSON.stringify(
1833
- error.toJSON?.() || {
1834
- error: "invalid_request"
1835
- }
1836
- )
1837
- );
1838
- }
1822
+ await new Promise((resolve) => {
1823
+ let body = "";
1824
+ req.on("data", (chunk) => body += chunk);
1825
+ req.on("end", async () => {
1826
+ try {
1827
+ const request = JSON.parse(body);
1828
+ const response = await oauthProxy.registerClient(request);
1829
+ res.writeHead(201, { "Content-Type": "application/json" }).end(JSON.stringify(response));
1830
+ } catch (error) {
1831
+ const statusCode = error.statusCode || 400;
1832
+ res.writeHead(statusCode, { "Content-Type": "application/json" }).end(
1833
+ JSON.stringify(
1834
+ error.toJSON?.() || {
1835
+ error: "invalid_request"
1836
+ }
1837
+ )
1838
+ );
1839
+ }
1840
+ resolve();
1841
+ });
1839
1842
  });
1840
1843
  return;
1841
1844
  }
@@ -1886,82 +1889,93 @@ var FastMCP = class extends FastMCPEventEmitter {
1886
1889
  return;
1887
1890
  }
1888
1891
  if (req.method === "POST" && url2.pathname === "/oauth/consent") {
1889
- let body = "";
1890
- req.on("data", (chunk) => body += chunk);
1891
- req.on("end", async () => {
1892
- try {
1893
- const mockRequest = new Request(`http://${host}/oauth/consent`, {
1894
- body,
1895
- headers: {
1896
- "Content-Type": "application/x-www-form-urlencoded"
1897
- },
1898
- method: "POST"
1899
- });
1900
- const response = await oauthProxy.handleConsent(mockRequest);
1901
- const location = response.headers.get("Location");
1902
- if (location) {
1903
- res.writeHead(response.status, { Location: location }).end();
1904
- } else {
1905
- const text = await response.text();
1906
- res.writeHead(response.status).end(text);
1907
- }
1908
- } catch (error) {
1909
- res.writeHead(400, { "Content-Type": "application/json" }).end(
1910
- JSON.stringify(
1911
- error.toJSON?.() || {
1912
- error: "server_error"
1892
+ await new Promise((resolve) => {
1893
+ let body = "";
1894
+ req.on("data", (chunk) => body += chunk);
1895
+ req.on("end", async () => {
1896
+ try {
1897
+ const mockRequest = new Request(
1898
+ `http://${host}/oauth/consent`,
1899
+ {
1900
+ body,
1901
+ headers: {
1902
+ "Content-Type": "application/x-www-form-urlencoded"
1903
+ },
1904
+ method: "POST"
1913
1905
  }
1914
- )
1915
- );
1916
- }
1906
+ );
1907
+ const response = await oauthProxy.handleConsent(mockRequest);
1908
+ const location = response.headers.get("Location");
1909
+ if (location) {
1910
+ res.writeHead(response.status, { Location: location }).end();
1911
+ } else {
1912
+ const text = await response.text();
1913
+ res.writeHead(response.status).end(text);
1914
+ }
1915
+ } catch (error) {
1916
+ res.writeHead(400, { "Content-Type": "application/json" }).end(
1917
+ JSON.stringify(
1918
+ error.toJSON?.() || {
1919
+ error: "server_error"
1920
+ }
1921
+ )
1922
+ );
1923
+ }
1924
+ resolve();
1925
+ });
1917
1926
  });
1918
1927
  return;
1919
1928
  }
1920
1929
  if (req.method === "POST" && url2.pathname === "/oauth/token") {
1921
- let body = "";
1922
- req.on("data", (chunk) => body += chunk);
1923
- req.on("end", async () => {
1924
- try {
1925
- const params = new URLSearchParams(body);
1926
- const grantType = params.get("grant_type");
1927
- const basicAuth = parseBasicAuthHeader(req.headers.authorization);
1928
- const clientId = basicAuth?.clientId || params.get("client_id") || "";
1929
- const clientSecret = basicAuth?.clientSecret ?? params.get("client_secret") ?? void 0;
1930
- let response;
1931
- if (grantType === "authorization_code") {
1932
- response = await oauthProxy.exchangeAuthorizationCode({
1933
- client_id: clientId,
1934
- client_secret: clientSecret,
1935
- code: params.get("code") || "",
1936
- code_verifier: params.get("code_verifier") || void 0,
1937
- grant_type: "authorization_code",
1938
- redirect_uri: params.get("redirect_uri") || ""
1939
- });
1940
- } else if (grantType === "refresh_token") {
1941
- response = await oauthProxy.exchangeRefreshToken({
1942
- client_id: clientId,
1943
- client_secret: clientSecret,
1944
- grant_type: "refresh_token",
1945
- refresh_token: params.get("refresh_token") || "",
1946
- scope: params.get("scope") || void 0
1947
- });
1948
- } else {
1949
- throw {
1950
- statusCode: 400,
1951
- toJSON: () => ({ error: "unsupported_grant_type" })
1952
- };
1930
+ await new Promise((resolve) => {
1931
+ let body = "";
1932
+ req.on("data", (chunk) => body += chunk);
1933
+ req.on("end", async () => {
1934
+ try {
1935
+ const params = new URLSearchParams(body);
1936
+ const grantType = params.get("grant_type");
1937
+ const basicAuth = parseBasicAuthHeader(
1938
+ req.headers.authorization
1939
+ );
1940
+ const clientId = basicAuth?.clientId || params.get("client_id") || "";
1941
+ const clientSecret = basicAuth?.clientSecret ?? params.get("client_secret") ?? void 0;
1942
+ let response;
1943
+ if (grantType === "authorization_code") {
1944
+ response = await oauthProxy.exchangeAuthorizationCode({
1945
+ client_id: clientId,
1946
+ client_secret: clientSecret,
1947
+ code: params.get("code") || "",
1948
+ code_verifier: params.get("code_verifier") || void 0,
1949
+ grant_type: "authorization_code",
1950
+ redirect_uri: params.get("redirect_uri") || ""
1951
+ });
1952
+ } else if (grantType === "refresh_token") {
1953
+ response = await oauthProxy.exchangeRefreshToken({
1954
+ client_id: clientId,
1955
+ client_secret: clientSecret,
1956
+ grant_type: "refresh_token",
1957
+ refresh_token: params.get("refresh_token") || "",
1958
+ scope: params.get("scope") || void 0
1959
+ });
1960
+ } else {
1961
+ throw {
1962
+ statusCode: 400,
1963
+ toJSON: () => ({ error: "unsupported_grant_type" })
1964
+ };
1965
+ }
1966
+ res.writeHead(200, { "Content-Type": "application/json" }).end(JSON.stringify(response));
1967
+ } catch (error) {
1968
+ const statusCode = error.statusCode || 400;
1969
+ res.writeHead(statusCode, { "Content-Type": "application/json" }).end(
1970
+ JSON.stringify(
1971
+ error.toJSON?.() || {
1972
+ error: "invalid_request"
1973
+ }
1974
+ )
1975
+ );
1953
1976
  }
1954
- res.writeHead(200, { "Content-Type": "application/json" }).end(JSON.stringify(response));
1955
- } catch (error) {
1956
- const statusCode = error.statusCode || 400;
1957
- res.writeHead(statusCode, { "Content-Type": "application/json" }).end(
1958
- JSON.stringify(
1959
- error.toJSON?.() || {
1960
- error: "invalid_request"
1961
- }
1962
- )
1963
- );
1964
- }
1977
+ resolve();
1978
+ });
1965
1979
  });
1966
1980
  return;
1967
1981
  }
@@ -1971,7 +1985,6 @@ var FastMCP = class extends FastMCPEventEmitter {
1971
1985
  return;
1972
1986
  }
1973
1987
  }
1974
- res.writeHead(404).end();
1975
1988
  };
1976
1989
  /**
1977
1990
  * Converts Node.js IncomingMessage to Web Request for Hono
@@ -2107,4 +2120,4 @@ export {
2107
2120
  FastMCPSession,
2108
2121
  FastMCP
2109
2122
  };
2110
- //# sourceMappingURL=chunk-UVX47AE5.js.map
2123
+ //# sourceMappingURL=chunk-TNX4H4LB.js.map