@hubex/mcp 0.14.20261126 → 0.15.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.
@@ -5,7 +5,9 @@
5
5
  * the token never passes through the model's context. Clients without that
6
6
  * capability fall back to the `hubex_set_token` tool.
7
7
  */
8
+ import { ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js";
8
9
  export const SET_TOKEN_TOOL = "hubex_set_token";
10
+ const TOKEN_PROMPT_TIMEOUT_MS = 30_000;
9
11
  const PROMPT_MESSAGE = "Нужен доступ к HubEx. Вставь access-токен (JWT без префикса «Bearer ») — " +
10
12
  "по нему будет получен refresh-токен, дальше сессия продлевается сама.";
11
13
  export function createElicitPrompter(server) {
@@ -28,6 +30,11 @@ export function createElicitPrompter(server) {
28
30
  },
29
31
  required: ["token"],
30
32
  },
33
+ }, { timeout: TOKEN_PROMPT_TIMEOUT_MS }).catch((error) => {
34
+ if (error instanceof McpError && error.code === ErrorCode.RequestTimeout) {
35
+ throw new Error("Время ожидания ввода токена HubEx истекло. Когда будете готовы ввести токен, повторите вызов.", { cause: error });
36
+ }
37
+ throw error;
31
38
  });
32
39
  if (result.action !== "accept") {
33
40
  throw new Error("Ввод токена отменён — авторизоваться в HubEx не удалось. " +
@@ -7,6 +7,7 @@ import { SET_TOKEN_TOOL } from "../token-prompt.js";
7
7
  import { okResult, failResult } from "./registry.js";
8
8
  /** Marker prepended to test data so it is easy to find and clean up later. */
9
9
  export const TEST_MARKER = "[MCP-TEST]";
10
+ const WHOAMI_AUTH_TIMEOUT_MS = 45_000;
10
11
  function whoami(config, auth) {
11
12
  return {
12
13
  definition: {
@@ -15,8 +16,16 @@ function whoami(config, auth) {
15
16
  inputSchema: { type: "object", properties: {} },
16
17
  },
17
18
  async execute(_args, signal) {
19
+ const authorizationWait = new AbortController();
20
+ const abortWithCaller = () => authorizationWait.abort(signal?.reason);
21
+ signal?.addEventListener("abort", abortWithCaller, { once: true });
22
+ const timeout = setTimeout(() => {
23
+ authorizationWait.abort(new Error(`Не удалось завершить авторизацию HubEx за ${WHOAMI_AUTH_TIMEOUT_MS / 1000} секунд. ` +
24
+ "Если форма входа ещё открыта, завершите вход и повторите вызов."));
25
+ }, WHOAMI_AUTH_TIMEOUT_MS);
18
26
  try {
19
- const token = await auth.getAccessToken(signal);
27
+ signal?.throwIfAborted();
28
+ const token = await auth.getAccessToken(authorizationWait.signal);
20
29
  const claims = decodeJwt(token);
21
30
  const exp = claims?.exp ? new Date(claims.exp * 1000).toISOString() : undefined;
22
31
  return okResult({
@@ -37,6 +46,10 @@ function whoami(config, auth) {
37
46
  catch (err) {
38
47
  return failResult(err);
39
48
  }
49
+ finally {
50
+ clearTimeout(timeout);
51
+ signal?.removeEventListener("abort", abortWithCaller);
52
+ }
40
53
  },
41
54
  };
42
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubex/mcp",
3
- "version": "0.14.20261126",
3
+ "version": "0.15.0",
4
4
  "type": "module",
5
5
  "description": "MCP server for managing HubEx test data (tasks, assets, companies, users) via the HubEx REST API",
6
6
  "author": "HubEx Team",