@jsswift/knowledge-mcp 0.1.5 → 0.1.7

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/server.mjs +22 -7
  2. package/package.json +1 -1
package/dist/server.mjs CHANGED
@@ -116,10 +116,25 @@ async function loadKnowledge(root = defaultRoot) {
116
116
  }).filter((entry) => entry.score > 0).sort((a, b) => b.score - a.score || a.id.localeCompare(b.id));
117
117
  return ranked.slice(0, limit);
118
118
  },
119
- async read(id) {
119
+ async read(id, selection = {}) {
120
120
  const entry = entries.get(id);
121
121
  if (!entry) throw new Error("Unknown document ID; use jsswift_search to find a documented ID");
122
- return { id, path: entry.path, text: await readFile(await safePath(entry.path), "utf8") };
122
+ const text = await readFile(await safePath(entry.path), "utf8");
123
+ if (selection.keys && !selection.section) throw new Error("keys requires a section");
124
+ if (!selection.section) return { id, path: entry.path, text };
125
+ if (entry.kind !== "component" || !["props", "events", "methods", "slots"].includes(selection.section)) throw new Error("Select a component contract section");
126
+ const metadata = JSON.parse(text.match(/```json\s*([\s\S]*?)```/)[1]);
127
+ let values = { ...metadata[selection.section] ?? {} };
128
+ if (selection.section === "props" && metadata.commonProps) {
129
+ const sharedText = await readFile(await safePath(metadata.commonProps.path), "utf8");
130
+ const shared = JSON.parse(sharedText.match(/```json\s*([\s\S]*?)```/)[1]);
131
+ values = { ...Object.fromEntries(metadata.commonProps.keys.map((key) => [key, shared.props[key]])), ...values };
132
+ }
133
+ if (selection.keys) {
134
+ if (!Array.isArray(selection.keys) || !selection.keys.length || selection.keys.length > 30 || selection.keys.some((key) => typeof key !== "string" || !Object.hasOwn(values, key))) throw new Error("Unknown or invalid contract keys");
135
+ values = Object.fromEntries(selection.keys.map((key) => [key, values[key]]));
136
+ }
137
+ return { id, path: entry.path, section: selection.section, text: JSON.stringify({ signature: metadata.signature, [selection.section]: values }, null, 2) };
123
138
  }
124
139
  };
125
140
  }
@@ -174,14 +189,14 @@ server.registerTool("jsswift_search", {
174
189
  }, async ({ query, limit }) => jsonResult({ project: context.project, version: context.version, results: knowledge.search(query, limit) }));
175
190
  server.registerTool("jsswift_read", {
176
191
  title: "Read a JSswift guide or exact component contract",
177
- description: "Read one complete indexed application document using its ID from jsswift_search or the resource list. Does not accept filesystem paths.",
178
- inputSchema: z.object({ id: z.string().min(1).max(200) }),
192
+ description: "Read an indexed document, or only a component section and named keys. Prefer section/keys for missing APIs; inherited props are resolved. Does not accept filesystem paths.",
193
+ inputSchema: z.object({ id: z.string().min(1).max(200), section: z.enum(["props", "events", "methods", "slots"]).optional(), keys: z.array(z.string().min(1).max(100)).min(1).max(30).optional() }),
179
194
  annotations
180
- }, async ({ id }) => {
195
+ }, async ({ id, section, keys }) => {
181
196
  try {
182
- return jsonResult({ project: context.project, version: context.version, ...await knowledge.read(id) });
197
+ return jsonResult({ project: context.project, version: context.version, ...await knowledge.read(id, { section, keys }) });
183
198
  } catch {
184
- return { isError: true, content: [{ type: "text", text: "Document unavailable or unknown ID. Use jsswift_search to select an indexed document." }] };
199
+ return { isError: true, content: [{ type: "text", text: "Document, section or keys unavailable. Use jsswift_search to select a document; omit section/keys for the full contract." }] };
185
200
  }
186
201
  });
187
202
  server.registerResource("knowledge-map", "jsswift://knowledge/map", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsswift/knowledge-mcp",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Read-only MCP for the installed JSswift version's documentation",
5
5
  "type": "module",
6
6
  "engines": {