rfhub-mcp 0.16.0 → 0.17.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.
@@ -1,5 +1,6 @@
1
1
  import * as z from "zod/v4";
2
2
  import { mcpExResponse } from "../utils/response.js";
3
+ import { executeGetResult } from "../utils/executeGetResult.js";
3
4
  export const registerComputeTool = (mcpServer, getResult) => {
4
5
  const ModeEnum = z.enum(["n", "f"]);
5
6
  const DirectionEnum = z.enum(["uplink", "downlink"]);
@@ -81,8 +82,7 @@ export const registerComputeTool = (mcpServer, getResult) => {
81
82
  FERF: input.FREF?.toString() ?? null,
82
83
  Bandwidth: input.Bandwidth?.toString() ?? null,
83
84
  };
84
- const result = await getResult("/api/arfcn-calculator-4g/compute", apiRequest);
85
- // const result = await safeApiPost("/api/arfcn-calculator-4g/compute", apiRequest);
85
+ const result = await executeGetResult(getResult, "/api/arfcn-calculator-4g/compute", apiRequest);
86
86
  const apiResult = apiResultSchema.parse(result);
87
87
  const structuredContent = {
88
88
  Mode: apiResult.Mode ?? null,
@@ -1,5 +1,6 @@
1
1
  import * as z from "zod/v4";
2
2
  import { mcpExResponse } from "../utils/response.js";
3
+ import { executeGetResult } from "../utils/executeGetResult.js";
3
4
  const registerComputeTool = (mcpServer, getResult) => {
4
5
  const ModeEnum = z.enum(["n", "f"]);
5
6
  const DirectionEnum = z.enum(["uplink", "downlink"]);
@@ -178,7 +179,7 @@ const registerComputeTool = (mcpServer, getResult) => {
178
179
  N: input.N?.toString() ?? null,
179
180
  M: input.M?.toString() ?? null,
180
181
  };
181
- const result = await getResult("/api/arfcn-calculator-5g/compute", apiRequest);
182
+ const result = await executeGetResult(getResult, "/api/arfcn-calculator-5g/compute", apiRequest);
182
183
  const apiResult = apiResultSchema.parse(result);
183
184
  return {
184
185
  content: [
@@ -1,5 +1,6 @@
1
1
  import * as z from "zod/v4";
2
2
  import { mcpExResponse } from "../utils/response.js";
3
+ import { executeGetResult } from "../utils/executeGetResult.js";
3
4
  const registerComputeTool = (mcpServer, getResult) => {
4
5
  const ModeEnum = z.enum(["n", "f"]);
5
6
  const DirectionEnum = z.enum(["uplink", "downlink"]);
@@ -178,7 +179,7 @@ const registerComputeTool = (mcpServer, getResult) => {
178
179
  N: input.N?.toString() ?? null,
179
180
  M: input.M?.toString() ?? null,
180
181
  };
181
- const result = await getResult("/api/arfcn-calculator-ntn/compute", apiRequest);
182
+ const result = await executeGetResult(getResult, "/api/arfcn-calculator-ntn/compute", apiRequest);
182
183
  const apiResult = apiResultSchema.parse(result);
183
184
  return {
184
185
  content: [
@@ -1,7 +1,8 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
- export declare const registerComputeTool: (mcpServer: McpServer, getResult: (endpoint: string, data: any) => Promise<object | null>) => void;
2
+ import { GetResult } from "../utils/executeGetResult.js";
3
+ export declare const registerComputeTool: (mcpServer: McpServer, getResult: GetResult) => void;
3
4
  declare const _default: {
4
- registerComputeTool: (mcpServer: McpServer, getResult: (endpoint: string, data: any) => Promise<object | null>) => void;
5
+ registerComputeTool: (mcpServer: McpServer, getResult: GetResult) => void;
5
6
  };
6
7
  export default _default;
7
8
  //# sourceMappingURL=arfcn-calculator-4g.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"arfcn-calculator-4g.d.ts","sourceRoot":"","sources":["../../../src/tools/arfcn-calculator-4g.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,eAAO,MAAM,mBAAmB,GAAI,WAAW,SAAS,EAAE,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,SAiJ3H,CAAC;;qCAjJ6C,SAAS,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;;AAmJ5H,wBAEE"}
1
+ {"version":3,"file":"arfcn-calculator-4g.d.ts","sourceRoot":"","sources":["../../../src/tools/arfcn-calculator-4g.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,SAAS,EAAoB,MAAM,8BAA8B,CAAC;AAE3E,eAAO,MAAM,mBAAmB,GAAI,WAAW,SAAS,EAAE,WAAW,SAAS,SAiJ7E,CAAC;;qCAjJ6C,SAAS,aAAa,SAAS;;AAmJ9E,wBAEE"}
@@ -1,6 +1,7 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { GetResult } from "../utils/executeGetResult.js";
2
3
  declare const _default: {
3
- registerComputeTool: (mcpServer: McpServer, getResult: (endpoint: string, data: any) => Promise<object | null>) => void;
4
+ registerComputeTool: (mcpServer: McpServer, getResult: GetResult) => void;
4
5
  };
5
6
  export default _default;
6
7
  //# sourceMappingURL=arfcn-calculator-5g.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"arfcn-calculator-5g.d.ts","sourceRoot":"","sources":["../../../src/tools/arfcn-calculator-5g.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;;qCAE5B,SAAS,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;;AAqNrH,wBAEE"}
1
+ {"version":3,"file":"arfcn-calculator-5g.d.ts","sourceRoot":"","sources":["../../../src/tools/arfcn-calculator-5g.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,SAAS,EAAoB,MAAM,8BAA8B,CAAC;;qCAEnC,SAAS,aAAa,SAAS;;AAqNvE,wBAEE"}
@@ -1,6 +1,7 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { GetResult } from "../utils/executeGetResult.js";
2
3
  declare const _default: {
3
- registerComputeTool: (mcpServer: McpServer, getResult: (endpoint: string, data: any) => Promise<object | null>) => void;
4
+ registerComputeTool: (mcpServer: McpServer, getResult: GetResult) => void;
4
5
  };
5
6
  export default _default;
6
7
  //# sourceMappingURL=arfcn-calculator-ntn.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"arfcn-calculator-ntn.d.ts","sourceRoot":"","sources":["../../../src/tools/arfcn-calculator-ntn.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;;qCAE5B,SAAS,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;;AAqNrH,wBAEE"}
1
+ {"version":3,"file":"arfcn-calculator-ntn.d.ts","sourceRoot":"","sources":["../../../src/tools/arfcn-calculator-ntn.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,SAAS,EAAoB,MAAM,8BAA8B,CAAC;;qCAEnC,SAAS,aAAa,SAAS;;AAqNvE,wBAEE"}
@@ -0,0 +1,12 @@
1
+ export type SafeApiPost = (endpoint: string, data: any) => Promise<object | null>;
2
+ export type InternalCompute = (data: any) => object | null;
3
+ export type GetResult = SafeApiPost | InternalCompute;
4
+ /**
5
+ * 自动判断 GetResult 的类型并执行相应操作的函数。
6
+ *
7
+ * @param operation - 一个 SafeApiPost 或 InternalCompute 类型的函数。
8
+ * @param args - 传递给操作函数的参数。对于 SafeApiPost,需要提供 [endpoint, data];对于 InternalCompute,只需要提供 [data]。
9
+ * @returns 返回操作结果的 Promise。对于 SafeApiPost,返回其原始 Promise 结果;对于 InternalCompute,返回一个 Resolved 的 Promise 包含其结果。
10
+ */
11
+ export declare function executeGetResult(operation: GetResult, ...args: any[]): Promise<object | null>;
12
+ //# sourceMappingURL=executeGetResult.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executeGetResult.d.ts","sourceRoot":"","sources":["../../../src/utils/executeGetResult.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,WAAW,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;AAClF,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,GAAG,KAAK,MAAM,GAAG,IAAI,CAAC;AAC3D,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG,eAAe,CAAC;AAEtD;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CAAC,SAAS,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA6BnG"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * 自动判断 GetResult 的类型并执行相应操作的函数。
3
+ *
4
+ * @param operation - 一个 SafeApiPost 或 InternalCompute 类型的函数。
5
+ * @param args - 传递给操作函数的参数。对于 SafeApiPost,需要提供 [endpoint, data];对于 InternalCompute,只需要提供 [data]。
6
+ * @returns 返回操作结果的 Promise。对于 SafeApiPost,返回其原始 Promise 结果;对于 InternalCompute,返回一个 Resolved 的 Promise 包含其结果。
7
+ */
8
+ export async function executeGetResult(operation, ...args) {
9
+ // 类型谓词函数,用于判断 operation 是否为 SafeApiPost 类型
10
+ function isSafeApiPost(op) {
11
+ // 基于函数参数数量或更复杂的运行时检查进行判断
12
+ // 由于函数签名在运行时难以精确区分,这里采用一种启发式方法:
13
+ // 通常 SafeApiPost 接受两个参数 (endpoint, data),而 InternalCompute 只接受一个 (data)
14
+ return op.length === 2;
15
+ }
16
+ if (isSafeApiPost(operation)) {
17
+ // 如果类型守卫确认是 SafeApiPost,则调用它
18
+ // 需要确保传入的 args 符合 (endpoint, data) 的格式
19
+ if (args.length < 2) {
20
+ console.warn("Warning: SafeApiPost expects at least 2 arguments (endpoint, data).");
21
+ // 根据需要处理参数不足的情况,例如提供默认值或抛出错误
22
+ // 这里假设 args[0] 是 endpoint, args[1] 是 data
23
+ }
24
+ const [endpoint, data] = args;
25
+ return await operation(endpoint, data);
26
+ }
27
+ else {
28
+ // 否则,它是 InternalCompute 类型
29
+ // 需要确保传入的 args 符合 (data) 的格式
30
+ if (args.length < 1) {
31
+ console.warn("Warning: InternalCompute expects at least 1 argument (data).");
32
+ // 根据需要处理参数不足的情况
33
+ }
34
+ const [data] = args;
35
+ return operation(data); // InternalCompute 是同步的,直接返回结果
36
+ }
37
+ }
38
+ // 使用示例
39
+ // (async () => {
40
+ // console.log("--- 执行 SafeApiPost ---");
41
+ // try {
42
+ // const apiResult = await executeGetResult(mockApiPost, "/api/users", { name: "Alice" });
43
+ // console.log("API Result:", apiResult);
44
+ // } catch (error) {
45
+ // console.error("API Error:", error);
46
+ // }
47
+ // console.log("\n--- 执行 InternalCompute ---");
48
+ // const computeResult = await executeGetResult(mockCompute, { value: 5 });
49
+ // console.log("Compute Result:", computeResult);
50
+ // })();
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "rfhub-mcp",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "title": "RFHub MCP Server",
5
5
  "description": "RFHub MCP Server",
6
6
  "websiteUrl": "https://rfhub.cn/mcp-server",
7
- "types": "./dist/types/index.d.ts",
8
7
  "type": "module",
9
8
  "exports": {
10
9
  ".": {