@atlisp/mcp 1.3.7 → 1.3.8

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.
Files changed (2) hide show
  1. package/dist/atlisp-mcp.js +68 -12
  2. package/package.json +1 -1
@@ -730,6 +730,17 @@ function getCached(key) {
730
730
  function setCache(key, data) {
731
731
  resourceCache.set(key, { data, timestamp: Date.now() });
732
732
  }
733
+ function clearCache(uri) {
734
+ if (uri) {
735
+ for (const key of resourceCache.keys()) {
736
+ if (key.startsWith(uri.split("://")[1]?.split("/")[0] + ":")) {
737
+ resourceCache.delete(key);
738
+ }
739
+ }
740
+ } else {
741
+ resourceCache.clear();
742
+ }
743
+ }
733
744
  function parseLispList(str) {
734
745
  if (!str || typeof str !== "string") return null;
735
746
  const trimmed = str.trim();
@@ -1015,17 +1026,60 @@ async function getDwgPath() {
1015
1026
  }
1016
1027
  }
1017
1028
  async function getPackages(filterName = null) {
1018
- const packages = MOCK_PACKAGES.map((p) => ({
1019
- name: p.name,
1020
- version: p.version,
1021
- description: p.description,
1022
- loaded: true
1023
- }));
1024
- if (filterName) {
1025
- const pkg = packages.find((p) => p.name === filterName);
1026
- return pkg ? [pkg] : [];
1029
+ const cacheKey = filterName ? `packages:${filterName}` : "packages:all";
1030
+ const cached = getCached(cacheKey);
1031
+ if (cached) return cached;
1032
+ if (!cad.connected) await cad.connect();
1033
+ if (!cad.connected) return [];
1034
+ try {
1035
+ const code = `(mapcar 'cdr @::*local-pkgs*)`;
1036
+ const result = await cad.sendCommandWithResult(code);
1037
+ if (!result || result === "" || result === "nil") {
1038
+ setCache(cacheKey, []);
1039
+ return [];
1040
+ }
1041
+ let raw = [];
1042
+ try {
1043
+ raw = JSON.parse(result);
1044
+ } catch {
1045
+ raw = parseLispList(result) || [];
1046
+ }
1047
+ if (!Array.isArray(raw)) raw = [];
1048
+ const packages = raw.map((item) => {
1049
+ if (Array.isArray(item)) {
1050
+ const pkg = { name: "", version: "0.0.0", description: "", loaded: true };
1051
+ for (const entry of item) {
1052
+ if (entry && typeof entry === "object" && !Array.isArray(entry)) {
1053
+ const [[key, val]] = Object.entries(entry);
1054
+ const k = String(key);
1055
+ const v = String(val);
1056
+ if (k === ":NAME") pkg.name = v;
1057
+ else if (k === ":VERSION") pkg.version = v;
1058
+ else if (k === ":DESCRIPTION") pkg.description = v;
1059
+ else if (k === ":FULL-NAME") pkg.fullName = v;
1060
+ else if (k === ":AUTHOR") pkg.author = v;
1061
+ else if (k === ":CATEGORY") pkg.category = v;
1062
+ else if (k === ":URL") pkg.url = v;
1063
+ }
1064
+ }
1065
+ return pkg;
1066
+ }
1067
+ if (typeof item === "string" || typeof item === "number") {
1068
+ return { name: String(item), version: "0.0.0", loaded: true };
1069
+ }
1070
+ return null;
1071
+ }).filter(Boolean);
1072
+ if (filterName) {
1073
+ const filtered = packages.filter((p) => p.name === filterName);
1074
+ setCache(cacheKey, filtered);
1075
+ return filtered;
1076
+ }
1077
+ setCache(cacheKey, packages);
1078
+ return packages;
1079
+ } catch (e) {
1080
+ setCache(cacheKey, []);
1081
+ return [];
1027
1082
  }
1028
- return packages;
1029
1083
  }
1030
1084
  function getPlatforms() {
1031
1085
  return CAD_PLATFORMS.map((name) => ({
@@ -2563,14 +2617,16 @@ async function handleToolCall(name, args) {
2563
2617
  }
2564
2618
  function notifyResourceChanges(toolName) {
2565
2619
  const resourceMap = {
2566
- connect_cad: ["atlisp://cad/info"],
2620
+ connect_cad: ["atlisp://cad/info", "atlisp://cad/layers", "atlisp://dwg/name", "atlisp://dwg/path", "atlisp://packages"],
2567
2621
  new_document: ["atlisp://dwg/name", "atlisp://dwg/path", "atlisp://cad/layers", "atlisp://cad/entities"],
2568
2622
  install_package: ["atlisp://packages"],
2569
- install_atlisp: ["atlisp://packages"]
2623
+ install_atlisp: ["atlisp://packages", "atlisp://cad/info"],
2624
+ init_atlisp: ["atlisp://packages", "atlisp://cad/info"]
2570
2625
  };
2571
2626
  const uris = resourceMap[toolName];
2572
2627
  if (uris) {
2573
2628
  for (const uri of uris) {
2629
+ clearCache(uri);
2574
2630
  if (isSubscribed(uri)) {
2575
2631
  notify(uri, null);
2576
2632
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlisp/mcp",
3
- "version": "1.3.7",
3
+ "version": "1.3.8",
4
4
  "description": "MCP Server for @lisp on CAD",
5
5
  "type": "module",
6
6
  "bin": {