@casys/mcp-openems 0.1.0 → 0.2.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.
package/mcp-openems.mjs CHANGED
@@ -8740,11 +8740,24 @@ import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
8740
8740
  import { tmpdir } from "node:os";
8741
8741
  import { join } from "node:path";
8742
8742
  import process2 from "node:process";
8743
+
8744
+ // src/qualification.ts
8745
+ var ANTENNA_S11_MAX_DB = -10;
8746
+ var ANTENNA_VSWR_MAX = 2;
8747
+ var RADOME_LOSS_MAX_DB = 1.5;
8748
+ function pythonFloat(value) {
8749
+ return Number.isInteger(value) ? value.toFixed(1) : String(value);
8750
+ }
8751
+
8752
+ // src/openems-runner.ts
8743
8753
  var RADOME_MATERIAL_PRESETS = {
8744
8754
  aramid: { epsR: 3.5, conductivitySm: 1e-3 },
8745
8755
  fiberglass: { epsR: 4.2, conductivitySm: 2e-3 },
8746
8756
  carbon: { epsR: 1, conductivitySm: 3e4 }
8747
8757
  };
8758
+ var PY_S11_MAX = pythonFloat(ANTENNA_S11_MAX_DB);
8759
+ var PY_VSWR_MAX = pythonFloat(ANTENNA_VSWR_MAX);
8760
+ var PY_LOSS_MAX = pythonFloat(RADOME_LOSS_MAX_DB);
8748
8761
  var DEFAULT_TIMEOUT_MS = 12e4;
8749
8762
  var decoder = new TextDecoder();
8750
8763
  var cachedOpenEmsVersion;
@@ -8924,7 +8937,7 @@ min_s11_db = float(s11_db[min_idx])
8924
8937
 
8925
8938
  # 10 dB return-loss bandwidth around resonance
8926
8939
  bw_10db_mhz = 0.0
8927
- below = s11_db <= -10.0
8940
+ below = s11_db <= ${PY_S11_MAX}
8928
8941
  if bool(below[min_idx]):
8929
8942
  lo = min_idx
8930
8943
  while lo > 0 and bool(below[lo - 1]):
@@ -8935,7 +8948,7 @@ if bool(below[min_idx]):
8935
8948
  bw_10db_mhz = float((freq[hi] - freq[lo]) / 1e6)
8936
8949
 
8937
8950
  wall_time_sec = time.monotonic() - t0
8938
- antenna_qualified = bool(s11_target_db <= -10.0 and vswr_target <= 2.0)
8951
+ antenna_qualified = bool(s11_target_db <= ${PY_S11_MAX} and vswr_target <= ${PY_VSWR_MAX})
8939
8952
 
8940
8953
  payload = {
8941
8954
  "s11Db": round(s11_target_db, 3),
@@ -9083,7 +9096,7 @@ s21_loss_db = float(max(0.0, -s21_tx_db))
9083
9096
  s11_refl_db = float(20.0 * math.log10(s11_mag))
9084
9097
 
9085
9098
  wall_time_sec = time.monotonic() - t0
9086
- radome_qualified = bool(s21_loss_db <= 1.5)
9099
+ radome_qualified = bool(s21_loss_db <= ${PY_LOSS_MAX})
9087
9100
 
9088
9101
  payload = {
9089
9102
  "s21LossDb": round(s21_loss_db, 3),
@@ -54871,7 +54884,7 @@ var McpApp = class {
54871
54884
  continue;
54872
54885
  }
54873
54886
  const resourceUri = `ui://${config2.prefix}/${viewerName}`;
54874
- const readFile4 = config2.readFile;
54887
+ const readFile5 = config2.readFile;
54875
54888
  const currentDistPath = distPath;
54876
54889
  this.registerResource({
54877
54890
  uri: resourceUri,
@@ -54879,7 +54892,7 @@ var McpApp = class {
54879
54892
  description: `MCP App: ${viewerName}`,
54880
54893
  mimeType: MCP_APP_MIME_TYPE
54881
54894
  }, async () => {
54882
- const html = await Promise.resolve(readFile4(currentDistPath));
54895
+ const html = await Promise.resolve(readFile5(currentDistPath));
54883
54896
  const content = {
54884
54897
  uri: resourceUri,
54885
54898
  mimeType: MCP_APP_MIME_TYPE,
@@ -56671,8 +56684,104 @@ import { link, mkdir as mkdir4, open as open2, readdir as readdir2, readFile as
56671
56684
  import { join as join2, resolve } from "node:path";
56672
56685
  var encoder3 = new TextEncoder();
56673
56686
 
56687
+ // src/viewer.ts
56688
+ import { readFile as readFile4 } from "node:fs/promises";
56689
+ import { statSync } from "node:fs";
56690
+ import { fileURLToPath } from "node:url";
56691
+
56692
+ // src/widgets.ts
56693
+ var RF_VERDICT_WIDGET = {
56694
+ key: "rf-verdict",
56695
+ uri: "ui://mcp-openems/rf-verdict",
56696
+ kind: "stat",
56697
+ title: "RF verdict",
56698
+ description: "PASS or FAIL of the antenna or radome qualification with its headline numbers.",
56699
+ supportedWidths: [280, 380, 520]
56700
+ };
56701
+ var RF_GATES_WIDGET = {
56702
+ key: "rf-gates",
56703
+ uri: "ui://mcp-openems/rf-gates",
56704
+ kind: "table",
56705
+ title: "Qualification gates",
56706
+ description: "Each qualification gate: its requirement, the reported value and pass or fail.",
56707
+ supportedWidths: [320, 440, 600]
56708
+ };
56709
+ var RF_MARGIN_WIDGET = {
56710
+ key: "rf-margin",
56711
+ uri: "ui://mcp-openems/rf-margin",
56712
+ kind: "chart",
56713
+ title: "Margin to limit",
56714
+ description: "Each gated RF quantity against its qualification limit.",
56715
+ supportedWidths: [320, 440, 640]
56716
+ };
56717
+ var RF_CASE_WIDGET = {
56718
+ key: "rf-case",
56719
+ uri: "ui://mcp-openems/rf-case",
56720
+ kind: "table",
56721
+ title: "Simulation case",
56722
+ description: "Inputs and solver results of the openEMS case, one row per quantity.",
56723
+ supportedWidths: [340, 480, 680]
56724
+ };
56725
+ var OPENEMS_WIDGETS = [
56726
+ RF_VERDICT_WIDGET,
56727
+ RF_GATES_WIDGET,
56728
+ RF_MARGIN_WIDGET,
56729
+ RF_CASE_WIDGET
56730
+ ];
56731
+ var OPENEMS_DEFAULT_WIDGET = RF_VERDICT_WIDGET;
56732
+ function openEmsWidgetByKey(key) {
56733
+ return OPENEMS_WIDGETS.find((widget) => widget.key === key);
56734
+ }
56735
+ function openEmsDeclaredViews(registeredKeys) {
56736
+ return OPENEMS_WIDGETS.filter((widget) => registeredKeys === void 0 || registeredKeys.includes(widget.key)).map((widget) => ({
56737
+ name: widget.key,
56738
+ resourceUri: widget.uri,
56739
+ title: widget.title,
56740
+ supportedWidths: widget.supportedWidths
56741
+ }));
56742
+ }
56743
+
56744
+ // src/viewer.ts
56745
+ var DENO_RELATIVE = `./ui/dist/${OPENEMS_WIDGETS[0].key}/index.html`;
56746
+ function isRemote(path) {
56747
+ return path.startsWith("https://") || path.startsWith("http://");
56748
+ }
56749
+ function isFile(path) {
56750
+ try {
56751
+ return statSync(path).isFile();
56752
+ } catch {
56753
+ return false;
56754
+ }
56755
+ }
56756
+ function viewerModuleUrl(moduleUrl = import.meta.url) {
56757
+ const denoLayout = isRemote(moduleUrl) || isFile(fileURLToPath(new URL(DENO_RELATIVE, moduleUrl)));
56758
+ return denoLayout ? new URL("../server.ts", moduleUrl).href : moduleUrl;
56759
+ }
56760
+ function registerOpenEmsWidgets(app, moduleUrl = viewerModuleUrl()) {
56761
+ return app.registerViewers({
56762
+ prefix: "mcp-openems",
56763
+ viewers: OPENEMS_WIDGETS.map((widget) => widget.key),
56764
+ moduleUrl,
56765
+ exists: (path) => isRemote(path) || isFile(path),
56766
+ readFile: async (path) => {
56767
+ if (!isRemote(path)) return await readFile4(path, "utf8");
56768
+ const response = await fetch(path);
56769
+ if (!response.ok) {
56770
+ throw new Error(
56771
+ `Unable to fetch openEMS widget from ${path}: HTTP ${response.status}.`
56772
+ );
56773
+ }
56774
+ return await response.text();
56775
+ },
56776
+ humanName: (name) => `openEMS ${openEmsWidgetByKey(name)?.title.toLowerCase() ?? name}`
56777
+ });
56778
+ }
56779
+
56674
56780
  // src/server.ts
56675
- var MCP_OPENEMS_VERSION = "0.1.0";
56781
+ var MCP_OPENEMS_VERSION = "0.2.0";
56782
+ function errorMessage(error2) {
56783
+ return error2 instanceof Error ? error2.message : String(error2);
56784
+ }
56676
56785
  var BLADE_ANTENNA_INPUT_SCHEMA = {
56677
56786
  type: "object",
56678
56787
  properties: {
@@ -56709,9 +56818,6 @@ function asFiniteNumber(value) {
56709
56818
  function asNonEmptyString(value) {
56710
56819
  return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
56711
56820
  }
56712
- function errorMessage(error2) {
56713
- return error2 instanceof Error ? error2.message : String(error2);
56714
- }
56715
56821
  function toolError(code, message2) {
56716
56822
  return {
56717
56823
  isError: true,
@@ -56813,11 +56919,16 @@ function createMcpOpenEmsServer(options = {}) {
56813
56919
  "(or Level-2 snippets `simulate_blade_antenna`, `simulate_radome_patch` via `list_snippets` / `run_snippet`)."
56814
56920
  ].join(" ")
56815
56921
  });
56922
+ const registeredWidgets = registerOpenEmsWidgets(app, options.viewerModuleUrl).registered.filter((key) => OPENEMS_WIDGETS.some((widget) => widget.key === key));
56923
+ const hasDefaultWidget = registeredWidgets.includes(OPENEMS_DEFAULT_WIDGET.key);
56924
+ const declaredViews = openEmsDeclaredViews(registeredWidgets);
56925
+ const viewerMeta = hasDefaultWidget ? { _meta: { ui: { resourceUri: OPENEMS_DEFAULT_WIDGET.uri } } } : {};
56816
56926
  app.registerTool(
56817
56927
  {
56818
56928
  name: "openems_simulate_blade_antenna",
56819
56929
  description: "Run a real 3D FDTD openEMS Maxwell simulation of a quarter-wave blade monopole antenna mounted on a conductive carbon-fiber fuselage ground plane, returning verified return loss (s11Db), VSWR, resonant frequency, 10 dB bandwidth, FDTD timestep count, and qualification status (s11Db <= -10 dB, vswr <= 2.0).",
56820
56930
  inputSchema: BLADE_ANTENNA_INPUT_SCHEMA,
56931
+ ...viewerMeta,
56821
56932
  annotations: {
56822
56933
  readOnlyHint: true,
56823
56934
  destructiveHint: false,
@@ -56846,6 +56957,7 @@ function createMcpOpenEmsServer(options = {}) {
56846
56957
  name: "openems_simulate_radome_patch",
56847
56958
  description: "Run a real 3D FDTD openEMS Maxwell transmission / RF-shielding simulation of a 1575.42 MHz (GPS L1 / Galileo E1) wave passing through a dorsal Canopy radome (aramid, fiberglass, or conductive carbon-fiber), returning verified insertion loss (s21LossDb), reflection (s11ReflectionDb), FDTD timestep count, and radome qualification (s21LossDb <= 1.5 dB).",
56848
56959
  inputSchema: RADOME_PATCH_INPUT_SCHEMA,
56960
+ ...viewerMeta,
56849
56961
  annotations: {
56850
56962
  readOnlyHint: true,
56851
56963
  destructiveHint: false,
@@ -56870,6 +56982,7 @@ function createMcpOpenEmsServer(options = {}) {
56870
56982
  }
56871
56983
  );
56872
56984
  registerSnippetProvider(app, {
56985
+ ...hasDefaultWidget ? { runResourceUri: OPENEMS_DEFAULT_WIDGET.uri } : {},
56873
56986
  runAnnotations: {
56874
56987
  readOnlyHint: true,
56875
56988
  destructiveHint: false,
@@ -56893,7 +57006,8 @@ function createMcpOpenEmsServer(options = {}) {
56893
57006
  structuredContent: { value },
56894
57007
  _meta: {
56895
57008
  "io.casys/provenance": "verified-solver",
56896
- "io.casys/case-sha256": value.caseSha256
57009
+ "io.casys/case-sha256": value.caseSha256,
57010
+ ...declaredViews.length > 0 ? { "io.mcpview/views": declaredViews } : {}
56897
57011
  }
56898
57012
  };
56899
57013
  } catch (error2) {
@@ -56917,7 +57031,8 @@ function createMcpOpenEmsServer(options = {}) {
56917
57031
  structuredContent: { value },
56918
57032
  _meta: {
56919
57033
  "io.casys/provenance": "verified-solver",
56920
- "io.casys/case-sha256": value.caseSha256
57034
+ "io.casys/case-sha256": value.caseSha256,
57035
+ ...declaredViews.length > 0 ? { "io.mcpview/views": declaredViews } : {}
56921
57036
  }
56922
57037
  };
56923
57038
  } catch (error2) {
@@ -56928,7 +57043,7 @@ function createMcpOpenEmsServer(options = {}) {
56928
57043
  ]
56929
57044
  });
56930
57045
  void detectOpenEmsVersion(runnerOptionsFrom(options));
56931
- return { app };
57046
+ return { app, registeredWidgets, hasDefaultWidget };
56932
57047
  }
56933
57048
 
56934
57049
  // server.ts
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@casys/mcp-openems",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Casys MCP server: openEMS 3D FDTD electromagnetic & antenna simulation (MCP tools + @mcpview Code Mode snippets)",
5
5
  "type": "module",
6
6
  "bin": { "mcp-openems": "mcp-openems.mjs" },
7
- "files": ["mcp-openems.mjs","LICENSE","README.md"],
7
+ "files": ["mcp-openems.mjs","LICENSE","README.md","ui-dist/rf-case/index.html","ui-dist/rf-gates/index.html","ui-dist/rf-margin/index.html","ui-dist/rf-verdict/index.html","THIRD_PARTY_NOTICES.txt"],
8
8
  "engines": { "node": ">=20.0.0" },
9
9
  "license": "MIT",
10
10
  "repository": { "type": "git", "url": "git+https://github.com/superWorldSavior/mcp-openems.git" },