@punica/components-mcp 0.5.0 → 0.7.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/dist/bundled.json CHANGED
@@ -1 +1 @@
1
- {"version":"2.5.0"}
1
+ {"version":"2.5.2"}
package/dist/server.mjs CHANGED
@@ -211,11 +211,25 @@ function closest(name, names) {
211
211
  }
212
212
  function createKnowledge(manifest2) {
213
213
  const elements = /* @__PURE__ */ new Map();
214
+ const functions = /* @__PURE__ */ new Map();
214
215
  for (const mod of manifest2.modules || []) {
215
- for (const d of mod.declarations || []) {
216
+ const declarations = mod.declarations || [];
217
+ for (const d of declarations) {
216
218
  if (d.kind === "class" && d.tagName) elements.set(d.tagName, normalize(d, mod.path));
217
219
  }
220
+ if (!declarations.some((d) => d.kind === "class" && d.tagName)) continue;
221
+ const folder = mod.path.replace(/[^/]*$/, "");
222
+ for (const d of declarations) {
223
+ if (d.kind !== "function" || !d.description) continue;
224
+ const params = (d.parameters || []).map((p) => `${p.name}${p.optional ? "?" : ""}: ${p.type?.text || "unknown"}`);
225
+ const notes = (d.parameters || []).filter((p) => p.description).map((p) => `\`${p.name}\`: ${p.description}`);
226
+ functions.set(folder, [
227
+ ...functions.get(folder) || [],
228
+ { name: d.name, signature: `${d.name}(${params.join(", ")}): ${d.return?.type?.text || "void"}`, description: [d.description, ...notes].join("\n\n") }
229
+ ]);
230
+ }
218
231
  }
232
+ for (const element of elements.values()) element.functions = functions.get(`src/${element.module}`.replace(/[^/]*$/, "")) || [];
219
233
  const tags = [...elements.keys()].sort();
220
234
  const allEvents = new Set([...elements.values()].flatMap((e) => e.events.map((ev) => ev.name)));
221
235
  const icons2 = Object.keys(icons);
@@ -237,7 +251,7 @@ function createKnowledge(manifest2) {
237
251
  for (const element of elements.values()) {
238
252
  const tagWords = element.tag.replace(/^punica-/, "").split("-");
239
253
  const text2 = element.description.toLowerCase();
240
- const api = [...element.attributes.map((a) => a.name), ...element.events.map((e) => e.name), ...element.slots.map((s) => s.name)].join(" ");
254
+ const api = [...element.attributes.map((a) => a.name), ...element.events.map((e) => e.name), ...element.slots.map((s) => s.name), ...element.functions.map((f) => f.name.toLowerCase())].join(" ");
241
255
  let score = 0;
242
256
  for (const { word, weight } of words) {
243
257
  let s = 0;
@@ -251,7 +265,7 @@ function createKnowledge(manifest2) {
251
265
  const typed = new Set(words.filter((w) => w.weight === 1).map((w) => w.word.replace(/s$/, "")));
252
266
  if (tagWords.every((t) => typed.has(t.replace(/s$/, "")))) score += 5 * tagWords.length;
253
267
  const part = /^(?:the |one |a |an )?[^.]*?\b(?:of|in|for|inside) (?:a|an|the) `punica-/i.test(firstSentence(element.description)) ? 4 : 0;
254
- scored.push({ tag: element.tag, description: firstSentence(element.description), score: score - part - tagWords.length * 0.1 });
268
+ scored.push({ tag: element.tag, description: firstSentence(element.description), functions: element.functions.map((f) => f.name), score: score - part - tagWords.length * 0.1 });
255
269
  }
256
270
  return scored.sort((a, b) => b.score - a.score).slice(0, limit);
257
271
  }
@@ -272,6 +286,10 @@ function createKnowledge(manifest2) {
272
286
  else table("Attributes", ["Attribute", "Property", "Type", "Description"], e.attributes.map((a) => [`\`${a.name}\``, `\`${a.property}\``, `\`${a.type}\``, a.description]));
273
287
  table("Properties (no attribute)", ["Property", "Type", "Description"], e.properties.map((p) => [`\`${p.name}\``, p.type ? `\`${p.type}\`` : "", (p.readonly ? "Read-only. " : "") + p.description]));
274
288
  table("Methods", ["Method", "Description"], e.methods.map((m) => [`\`${m.signature}\``, m.description]));
289
+ if (e.functions.length) {
290
+ lines.push("", "### Functions", "", `\`import { ${e.functions.map((f) => f.name).join(", ")} } from '@punica/components';\``);
291
+ for (const f of e.functions) lines.push("", "```ts", f.signature, "```", "", f.description);
292
+ }
275
293
  table("Events", ["Event", "Description"], e.events.map((ev) => [`\`${ev.name}\``, ev.description]));
276
294
  table("Slots", ["Slot", "Description"], e.slots.map((s) => [s.name ? `\`${s.name}\`` : "(default)", s.description]));
277
295
  if (!brief) {
@@ -712,7 +730,8 @@ function createPunicaServer({ manifest: manifest2, guide: guide2, version: versi
712
730
  async ({ query, limit }) => {
713
731
  const results = knowledge.search(query, limit || 10);
714
732
  if (!results.length) return text(`Nothing matches "${query}". Elements: ${knowledge.tags.join(", ")}`);
715
- return text(results.map((r) => `${r.tag}: ${r.description}`).join("\n"));
733
+ const also = (r) => r.functions?.length ? ` Script: ${r.functions.map((name) => `\`${name}()\``).join(", ")} from '@punica/components'.` : "";
734
+ return text(results.map((r) => `${r.tag}: ${r.description}${also(r)}`).join("\n"));
716
735
  }
717
736
  );
718
737
  server2.registerTool(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@punica/components-mcp",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "MCP server for @punica/components: find elements, read their API and examples, validate markup.",
5
5
  "keywords": [
6
6
  "mcp",