@skills-hub-ai/mcp 0.1.8 → 0.1.10
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/api.d.ts +24 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +52 -3
- package/dist/api.js.map +1 -1
- package/dist/installer.d.ts.map +1 -1
- package/dist/installer.js +71 -54
- package/dist/installer.js.map +1 -1
- package/package.json +6 -4
- package/src/api.ts +83 -4
- package/src/installer.test.ts +19 -1
- package/src/installer.ts +112 -57
package/dist/api.d.ts
CHANGED
|
@@ -43,4 +43,28 @@ export interface SkillDetailResult {
|
|
|
43
43
|
}
|
|
44
44
|
export declare function searchSkills(query: string, category?: string, limit?: number, org?: string): Promise<SkillSearchResult[]>;
|
|
45
45
|
export declare function getSkillDetail(slug: string): Promise<SkillDetailResult>;
|
|
46
|
+
export interface SkillFileManifestEntry {
|
|
47
|
+
relativePath: string;
|
|
48
|
+
bytes: number;
|
|
49
|
+
lines: number;
|
|
50
|
+
sha256: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Fetch the full file manifest for a skill version. Returns null when the
|
|
54
|
+
* version has no file tree (skills synced before multi-file ingest). Callers
|
|
55
|
+
* should fall back to the `instructions` field in that case.
|
|
56
|
+
*/
|
|
57
|
+
export declare function fetchSkillFileManifest(slug: string, version: string): Promise<SkillFileManifestEntry[] | null>;
|
|
58
|
+
/**
|
|
59
|
+
* Fetch the content of a single file from a skill version. The relativePath
|
|
60
|
+
* must match exactly what the manifest returned.
|
|
61
|
+
*/
|
|
62
|
+
export declare function fetchSkillFile(slug: string, version: string, relativePath: string): Promise<string>;
|
|
63
|
+
/**
|
|
64
|
+
* Record a completed install so it counts toward the skill's installCount and
|
|
65
|
+
* shows up as an MCP install in analytics. Best-effort: a tracking failure must
|
|
66
|
+
* never break an install that already wrote files locally, so this swallows all
|
|
67
|
+
* errors. Anonymous (no API token) installs are deduped server-side by IP.
|
|
68
|
+
*/
|
|
69
|
+
export declare function recordInstall(slug: string, target: "claude-code" | "cursor"): Promise<void>;
|
|
46
70
|
//# sourceMappingURL=api.d.ts.map
|
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAqBA,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACzC,aAAa,EAAE,OAAO,CAAC;IACvB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACzC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,EAAE;QACX,QAAQ,EAAE,KAAK,CAAC;YACd,KAAK,EAAE;gBAAE,IAAI,EAAE,MAAM,CAAC;gBAAC,IAAI,EAAE,MAAM,CAAC;gBAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;aAAE,CAAC;YACnE,SAAS,EAAE,MAAM,CAAC;YAClB,UAAU,EAAE,OAAO,CAAC;SACrB,CAAC,CAAC;KACJ,GAAG,IAAI,CAAC;CACV;AAED,wBAAsB,YAAY,CAChC,KAAK,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,MAAM,EACjB,KAAK,SAAK,EACV,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAgB9B;AAED,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAS7E;AAED,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,sBAAsB,EAAE,GAAG,IAAI,CAAC,CAU1C;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,MAAM,CAAC,CAYjB;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,aAAa,GAAG,QAAQ,GAC/B,OAAO,CAAC,IAAI,CAAC,CAcf"}
|
package/dist/api.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
const API_URL = process.env.SKILLS_HUB_API_URL || "https://api.skills-hub.ai";
|
|
2
2
|
const API_TOKEN = process.env.SKILLS_HUB_API_TOKEN || "";
|
|
3
3
|
const TIMEOUT_MS = 30_000;
|
|
4
|
-
function fetchWithTimeout(url) {
|
|
4
|
+
function fetchWithTimeout(url, init = {}) {
|
|
5
5
|
const controller = new AbortController();
|
|
6
6
|
const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);
|
|
7
|
-
const headers = {
|
|
7
|
+
const headers = {
|
|
8
|
+
...(init.headers ?? {}),
|
|
9
|
+
};
|
|
8
10
|
if (API_TOKEN) {
|
|
9
11
|
headers["Authorization"] = `ApiKey ${API_TOKEN}`;
|
|
10
12
|
}
|
|
11
|
-
return fetch(url, { signal: controller.signal, headers }).finally(() => clearTimeout(timer));
|
|
13
|
+
return fetch(url, { ...init, signal: controller.signal, headers }).finally(() => clearTimeout(timer));
|
|
12
14
|
}
|
|
13
15
|
export async function searchSkills(query, category, limit = 10, org) {
|
|
14
16
|
const params = new URLSearchParams({
|
|
@@ -34,4 +36,51 @@ export async function getSkillDetail(slug) {
|
|
|
34
36
|
}
|
|
35
37
|
return (await res.json());
|
|
36
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Fetch the full file manifest for a skill version. Returns null when the
|
|
41
|
+
* version has no file tree (skills synced before multi-file ingest). Callers
|
|
42
|
+
* should fall back to the `instructions` field in that case.
|
|
43
|
+
*/
|
|
44
|
+
export async function fetchSkillFileManifest(slug, version) {
|
|
45
|
+
const res = await fetchWithTimeout(`${API_URL}/api/v1/skills/${encodeURIComponent(slug)}/versions/${encodeURIComponent(version)}/files`);
|
|
46
|
+
if (res.status === 404)
|
|
47
|
+
return null;
|
|
48
|
+
if (!res.ok) {
|
|
49
|
+
throw new Error(`Manifest fetch failed: ${res.status} ${res.statusText}`);
|
|
50
|
+
}
|
|
51
|
+
const data = (await res.json());
|
|
52
|
+
return data.files;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Fetch the content of a single file from a skill version. The relativePath
|
|
56
|
+
* must match exactly what the manifest returned.
|
|
57
|
+
*/
|
|
58
|
+
export async function fetchSkillFile(slug, version, relativePath) {
|
|
59
|
+
const encoded = relativePath.split("/").map(encodeURIComponent).join("/");
|
|
60
|
+
const res = await fetchWithTimeout(`${API_URL}/api/v1/skills/${encodeURIComponent(slug)}/versions/${encodeURIComponent(version)}/files/${encoded}`);
|
|
61
|
+
if (!res.ok) {
|
|
62
|
+
throw new Error(`File fetch failed: ${relativePath} (${res.status} ${res.statusText})`);
|
|
63
|
+
}
|
|
64
|
+
const data = (await res.json());
|
|
65
|
+
return data.content;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Record a completed install so it counts toward the skill's installCount and
|
|
69
|
+
* shows up as an MCP install in analytics. Best-effort: a tracking failure must
|
|
70
|
+
* never break an install that already wrote files locally, so this swallows all
|
|
71
|
+
* errors. Anonymous (no API token) installs are deduped server-side by IP.
|
|
72
|
+
*/
|
|
73
|
+
export async function recordInstall(slug, target) {
|
|
74
|
+
const platform = target === "cursor" ? "CURSOR" : "CLAUDE_CODE";
|
|
75
|
+
try {
|
|
76
|
+
await fetchWithTimeout(`${API_URL}/api/v1/skills/${encodeURIComponent(slug)}/install`, {
|
|
77
|
+
method: "POST",
|
|
78
|
+
headers: { "Content-Type": "application/json" },
|
|
79
|
+
body: JSON.stringify({ platform }),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
// Swallow — install already succeeded locally; tracking is best-effort.
|
|
84
|
+
}
|
|
85
|
+
}
|
|
37
86
|
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,2BAA2B,CAAC;AAC9E,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,EAAE,CAAC;AACzD,MAAM,UAAU,GAAG,MAAM,CAAC;AAE1B,SAAS,gB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;IAAC,MAAM,CAAC;QACP,wEAAwE;IAC1E,CAAC;AACH,CAAC"}
|
package/dist/installer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installer.d.ts","sourceRoot":"","sources":["../src/installer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"installer.d.ts","sourceRoot":"","sources":["../src/installer.ts"],"names":[],"mappings":"AA2DA,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAsDD,wEAAwE;AACxE,wBAAsB,YAAY,CAChC,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,aAAa,GAAG,QAAwB,GAC/C,OAAO,CAAC,aAAa,CAAC,CAkCxB"}
|
package/dist/installer.js
CHANGED
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
import { existsSync
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
throw new Error(`Invalid slug: ${slug}`);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
function yamlEscape(value) {
|
|
11
|
-
if (!value)
|
|
12
|
-
return value ?? "";
|
|
13
|
-
if (/[:\-#{}\[\]&*!|>'"%@`]/.test(value) || value.includes("\n")) {
|
|
14
|
-
return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
15
|
-
}
|
|
16
|
-
return value;
|
|
17
|
-
}
|
|
4
|
+
import { atomicWriteSkillFiles, buildSkillMarkdown, readLocalFile, validateSlug, writeSkillFiles, } from "@skills-hub-ai/installer";
|
|
5
|
+
import { fetchSkillFile, fetchSkillFileManifest, getSkillDetail, recordInstall, } from "./api.js";
|
|
6
|
+
const LEARNINGS_PATTERN = /^LEARNINGS(\.md)?$/i;
|
|
18
7
|
function getSkillsDir(target) {
|
|
19
8
|
const home = homedir();
|
|
20
9
|
return target === "cursor"
|
|
@@ -27,40 +16,80 @@ function getCommandsDir(target) {
|
|
|
27
16
|
? join(home, ".cursor", "skills")
|
|
28
17
|
: join(home, ".claude", "commands");
|
|
29
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Build the slash command body for claude-code. The format differs from
|
|
21
|
+
* SKILL.md: no `---` delimiters, just frontmatter style fields followed
|
|
22
|
+
* by the body. Kept inline here because it is claude-code specific and
|
|
23
|
+
* not part of the shared installer API.
|
|
24
|
+
*/
|
|
25
|
+
function buildClaudeCommandContent(skill) {
|
|
26
|
+
return [
|
|
27
|
+
`name: ${skill.name}`,
|
|
28
|
+
`description: ${skill.description}`,
|
|
29
|
+
`version: ${skill.latestVersion}`,
|
|
30
|
+
`category: ${skill.category.slug}`,
|
|
31
|
+
"",
|
|
32
|
+
skill.instructions,
|
|
33
|
+
"",
|
|
34
|
+
].join("\n");
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Write a skill's file tree to `skillDir`.
|
|
38
|
+
*
|
|
39
|
+
* Prefers the multi-file manifest when available (fetches every file and
|
|
40
|
+
* writes atomically). Falls back to a single generated SKILL.md for older
|
|
41
|
+
* skills that pre-date multi-file ingest. Preserves any existing LEARNINGS.md
|
|
42
|
+
* in both paths — it is user state, not part of the published skill.
|
|
43
|
+
*/
|
|
44
|
+
async function writeSkillTree(skill, skillDir) {
|
|
45
|
+
const manifest = await fetchSkillFileManifest(skill.slug, skill.latestVersion);
|
|
46
|
+
if (manifest && manifest.length > 0) {
|
|
47
|
+
const learnings = readLocalFile(skillDir, "LEARNINGS.md");
|
|
48
|
+
const files = await Promise.all(manifest
|
|
49
|
+
.filter((entry) => !LEARNINGS_PATTERN.test(entry.relativePath))
|
|
50
|
+
.map(async (entry) => ({
|
|
51
|
+
relativePath: entry.relativePath,
|
|
52
|
+
content: await fetchSkillFile(skill.slug, skill.latestVersion, entry.relativePath),
|
|
53
|
+
})));
|
|
54
|
+
if (learnings !== null) {
|
|
55
|
+
files.push({ relativePath: "LEARNINGS.md", content: learnings });
|
|
56
|
+
}
|
|
57
|
+
atomicWriteSkillFiles(skillDir, files);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const skillMd = buildSkillMarkdown({
|
|
61
|
+
name: skill.name,
|
|
62
|
+
description: skill.description,
|
|
63
|
+
version: skill.latestVersion,
|
|
64
|
+
category: skill.category.slug,
|
|
65
|
+
}, skill.instructions);
|
|
66
|
+
writeSkillFiles(skillDir, [{ relativePath: "SKILL.md", content: skillMd }]);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
30
69
|
/** Install a single skill from the API to the local skills directory */
|
|
31
70
|
export async function installSkill(slug, target = "claude-code") {
|
|
32
71
|
validateSlug(slug);
|
|
33
72
|
const skill = await getSkillDetail(slug);
|
|
34
73
|
const skillDir = join(getSkillsDir(target), slug);
|
|
35
|
-
|
|
36
|
-
const content = `---
|
|
37
|
-
name: ${yamlEscape(skill.name)}
|
|
38
|
-
description: ${yamlEscape(skill.description)}
|
|
39
|
-
version: ${yamlEscape(skill.latestVersion)}
|
|
40
|
-
category: ${yamlEscape(skill.category.slug)}
|
|
41
|
-
---
|
|
42
|
-
|
|
43
|
-
${skill.instructions}
|
|
44
|
-
`;
|
|
45
|
-
writeFileSync(join(skillDir, "SKILL.md"), content);
|
|
74
|
+
await writeSkillTree(skill, skillDir);
|
|
46
75
|
// Register as slash command (Claude Code reads from ~/.claude/commands/)
|
|
47
76
|
if (target === "claude-code") {
|
|
48
77
|
const commandsDir = getCommandsDir(target);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
${skill.instructions}
|
|
56
|
-
`;
|
|
57
|
-
writeFileSync(join(commandsDir, `${slug}.md`), commandContent);
|
|
78
|
+
writeSkillFiles(commandsDir, [
|
|
79
|
+
{
|
|
80
|
+
relativePath: `${slug}.md`,
|
|
81
|
+
content: buildClaudeCommandContent(skill),
|
|
82
|
+
},
|
|
83
|
+
]);
|
|
58
84
|
}
|
|
59
85
|
// Install composition dependencies
|
|
60
86
|
const deps = [];
|
|
61
87
|
if (skill.composition?.children.length) {
|
|
62
88
|
await installDependencies(skill, target, deps);
|
|
63
89
|
}
|
|
90
|
+
// Record the install so it counts toward installCount and shows up as an MCP
|
|
91
|
+
// install in analytics. Best-effort — never blocks a successful local write.
|
|
92
|
+
await recordInstall(slug, target);
|
|
64
93
|
return {
|
|
65
94
|
slug,
|
|
66
95
|
version: skill.latestVersion,
|
|
@@ -90,28 +119,16 @@ async function installDependencies(skill, target, installed, visited = new Set()
|
|
|
90
119
|
try {
|
|
91
120
|
const childDetail = await getSkillDetail(childSlug);
|
|
92
121
|
const childDir = join(skillsDir, childSlug);
|
|
93
|
-
|
|
94
|
-
const content = `---
|
|
95
|
-
name: ${yamlEscape(childDetail.name)}
|
|
96
|
-
description: ${yamlEscape(childDetail.description)}
|
|
97
|
-
version: ${yamlEscape(childDetail.latestVersion)}
|
|
98
|
-
category: ${yamlEscape(childDetail.category.slug)}
|
|
99
|
-
---
|
|
100
|
-
|
|
101
|
-
${childDetail.instructions}
|
|
102
|
-
`;
|
|
103
|
-
writeFileSync(join(childDir, "SKILL.md"), content);
|
|
122
|
+
await writeSkillTree(childDetail, childDir);
|
|
104
123
|
// Register child as slash command too
|
|
105
124
|
if (target === "claude-code") {
|
|
106
125
|
const commandsDir = getCommandsDir(target);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
`;
|
|
114
|
-
writeFileSync(join(commandsDir, `${childSlug}.md`), commandContent);
|
|
126
|
+
writeSkillFiles(commandsDir, [
|
|
127
|
+
{
|
|
128
|
+
relativePath: `${childSlug}.md`,
|
|
129
|
+
content: buildClaudeCommandContent(childDetail),
|
|
130
|
+
},
|
|
131
|
+
]);
|
|
115
132
|
}
|
|
116
133
|
installed.push(childSlug);
|
|
117
134
|
// Recurse if this child is also a composition
|
package/dist/installer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installer.js","sourceRoot":"","sources":["../src/installer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"installer.js","sourceRoot":"","sources":["../src/installer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,eAAe,GAEhB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,cAAc,EACd,aAAa,GAEd,MAAM,UAAU,CAAC;AAElB,MAAM,iBAAiB,GAAG,qBAAqB,CAAC;AAEhD,SAAS,YAAY,CAAC,MAAgC;IACpD,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;IACvB,OAAO,MAAM,KAAK,QAAQ;QACxB,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,CAAC;QACjC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;AACtC,CAAC;AAED,SAAS,cAAc,CAAC,MAAgC;IACtD,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;IACvB,OAAO,MAAM,KAAK,QAAQ;QACxB,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,CAAC;QACjC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AACxC,CAAC;AAED;;;;;GAKG;AACH,SAAS,yBAAyB,CAAC,KAMlC;IACC,O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G,SAAS,KAAK;wBAC/B,OAAO,EAAE,yBAAyB,CAAC,WAAW,CAAC;qBAChD;iBACF,CAAC,CAAC;YACL,CAAC;YAED,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAE1B,8CAA8C;YAC9C,MAAM,mBAAmB,CACvB,WAAW,EACX,MAAM,EACN,SAAS,EACT,OAAO,EACP,KAAK,GAAG,CAAC,CACV,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACP,uDAAuD;QACzD,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skills-hub-ai/mcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "MCP server for skills-hub.ai — serve installed skills as prompts in any MCP-compatible AI tool",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"mcpName": "io.github.tinh2/skills-hub",
|
|
6
7
|
"keywords": [
|
|
7
8
|
"mcp",
|
|
8
9
|
"model-context-protocol",
|
|
@@ -39,13 +40,14 @@
|
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
42
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
42
|
-
"@skills-hub-ai/
|
|
43
|
+
"@skills-hub-ai/installer": "0.1.0",
|
|
44
|
+
"@skills-hub-ai/skill-parser": "0.2.3"
|
|
43
45
|
},
|
|
44
46
|
"devDependencies": {
|
|
45
47
|
"@types/node": "^25.6.0",
|
|
46
|
-
"tsx": "^4.
|
|
48
|
+
"tsx": "^4.22.4",
|
|
47
49
|
"typescript": "^6.0.3",
|
|
48
|
-
"vitest": "^4.1.
|
|
50
|
+
"vitest": "^4.1.8"
|
|
49
51
|
},
|
|
50
52
|
"scripts": {
|
|
51
53
|
"dev": "tsx src/index.ts",
|
package/src/api.ts
CHANGED
|
@@ -2,15 +2,20 @@ const API_URL = process.env.SKILLS_HUB_API_URL || "https://api.skills-hub.ai";
|
|
|
2
2
|
const API_TOKEN = process.env.SKILLS_HUB_API_TOKEN || "";
|
|
3
3
|
const TIMEOUT_MS = 30_000;
|
|
4
4
|
|
|
5
|
-
function fetchWithTimeout(
|
|
5
|
+
function fetchWithTimeout(
|
|
6
|
+
url: string,
|
|
7
|
+
init: RequestInit = {},
|
|
8
|
+
): Promise<Response> {
|
|
6
9
|
const controller = new AbortController();
|
|
7
10
|
const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);
|
|
8
|
-
const headers: Record<string, string> = {
|
|
11
|
+
const headers: Record<string, string> = {
|
|
12
|
+
...((init.headers as Record<string, string>) ?? {}),
|
|
13
|
+
};
|
|
9
14
|
if (API_TOKEN) {
|
|
10
15
|
headers["Authorization"] = `ApiKey ${API_TOKEN}`;
|
|
11
16
|
}
|
|
12
|
-
return fetch(url, { signal: controller.signal, headers }).finally(
|
|
13
|
-
clearTimeout(timer),
|
|
17
|
+
return fetch(url, { ...init, signal: controller.signal, headers }).finally(
|
|
18
|
+
() => clearTimeout(timer),
|
|
14
19
|
);
|
|
15
20
|
}
|
|
16
21
|
|
|
@@ -82,3 +87,77 @@ export async function getSkillDetail(slug: string): Promise<SkillDetailResult> {
|
|
|
82
87
|
|
|
83
88
|
return (await res.json()) as SkillDetailResult;
|
|
84
89
|
}
|
|
90
|
+
|
|
91
|
+
export interface SkillFileManifestEntry {
|
|
92
|
+
relativePath: string;
|
|
93
|
+
bytes: number;
|
|
94
|
+
lines: number;
|
|
95
|
+
sha256: string;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Fetch the full file manifest for a skill version. Returns null when the
|
|
100
|
+
* version has no file tree (skills synced before multi-file ingest). Callers
|
|
101
|
+
* should fall back to the `instructions` field in that case.
|
|
102
|
+
*/
|
|
103
|
+
export async function fetchSkillFileManifest(
|
|
104
|
+
slug: string,
|
|
105
|
+
version: string,
|
|
106
|
+
): Promise<SkillFileManifestEntry[] | null> {
|
|
107
|
+
const res = await fetchWithTimeout(
|
|
108
|
+
`${API_URL}/api/v1/skills/${encodeURIComponent(slug)}/versions/${encodeURIComponent(version)}/files`,
|
|
109
|
+
);
|
|
110
|
+
if (res.status === 404) return null;
|
|
111
|
+
if (!res.ok) {
|
|
112
|
+
throw new Error(`Manifest fetch failed: ${res.status} ${res.statusText}`);
|
|
113
|
+
}
|
|
114
|
+
const data = (await res.json()) as { files: SkillFileManifestEntry[] };
|
|
115
|
+
return data.files;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Fetch the content of a single file from a skill version. The relativePath
|
|
120
|
+
* must match exactly what the manifest returned.
|
|
121
|
+
*/
|
|
122
|
+
export async function fetchSkillFile(
|
|
123
|
+
slug: string,
|
|
124
|
+
version: string,
|
|
125
|
+
relativePath: string,
|
|
126
|
+
): Promise<string> {
|
|
127
|
+
const encoded = relativePath.split("/").map(encodeURIComponent).join("/");
|
|
128
|
+
const res = await fetchWithTimeout(
|
|
129
|
+
`${API_URL}/api/v1/skills/${encodeURIComponent(slug)}/versions/${encodeURIComponent(version)}/files/${encoded}`,
|
|
130
|
+
);
|
|
131
|
+
if (!res.ok) {
|
|
132
|
+
throw new Error(
|
|
133
|
+
`File fetch failed: ${relativePath} (${res.status} ${res.statusText})`,
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
const data = (await res.json()) as { content: string };
|
|
137
|
+
return data.content;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Record a completed install so it counts toward the skill's installCount and
|
|
142
|
+
* shows up as an MCP install in analytics. Best-effort: a tracking failure must
|
|
143
|
+
* never break an install that already wrote files locally, so this swallows all
|
|
144
|
+
* errors. Anonymous (no API token) installs are deduped server-side by IP.
|
|
145
|
+
*/
|
|
146
|
+
export async function recordInstall(
|
|
147
|
+
slug: string,
|
|
148
|
+
target: "claude-code" | "cursor",
|
|
149
|
+
): Promise<void> {
|
|
150
|
+
const platform = target === "cursor" ? "CURSOR" : "CLAUDE_CODE";
|
|
151
|
+
try {
|
|
152
|
+
await fetchWithTimeout(
|
|
153
|
+
`${API_URL}/api/v1/skills/${encodeURIComponent(slug)}/install`,
|
|
154
|
+
{
|
|
155
|
+
method: "POST",
|
|
156
|
+
headers: { "Content-Type": "application/json" },
|
|
157
|
+
body: JSON.stringify({ platform }),
|
|
158
|
+
},
|
|
159
|
+
);
|
|
160
|
+
} catch {
|
|
161
|
+
// Swallow — install already succeeded locally; tracking is best-effort.
|
|
162
|
+
}
|
|
163
|
+
}
|
package/src/installer.test.ts
CHANGED
|
@@ -10,11 +10,22 @@ vi.mock("node:fs", () => ({
|
|
|
10
10
|
|
|
11
11
|
vi.mock("./api.js", () => ({
|
|
12
12
|
getSkillDetail: vi.fn(),
|
|
13
|
+
recordInstall: vi.fn(),
|
|
14
|
+
fetchSkillFileManifest: vi.fn(),
|
|
15
|
+
fetchSkillFile: vi.fn(),
|
|
13
16
|
}));
|
|
14
17
|
|
|
15
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
getSkillDetail,
|
|
20
|
+
recordInstall,
|
|
21
|
+
fetchSkillFileManifest,
|
|
22
|
+
fetchSkillFile,
|
|
23
|
+
} from "./api.js";
|
|
16
24
|
|
|
17
25
|
const mockGetSkillDetail = vi.mocked(getSkillDetail);
|
|
26
|
+
const mockRecordInstall = vi.mocked(recordInstall);
|
|
27
|
+
const mockFetchSkillFileManifest = vi.mocked(fetchSkillFileManifest);
|
|
28
|
+
vi.mocked(fetchSkillFile);
|
|
18
29
|
const mockExistsSync = vi.mocked(existsSync);
|
|
19
30
|
const mockMkdirSync = vi.mocked(mkdirSync);
|
|
20
31
|
const mockWriteFileSync = vi.mocked(writeFileSync);
|
|
@@ -38,6 +49,8 @@ const baseSkill = {
|
|
|
38
49
|
beforeEach(() => {
|
|
39
50
|
vi.clearAllMocks();
|
|
40
51
|
mockExistsSync.mockReturnValue(false);
|
|
52
|
+
// Default: no multi-file manifest, fall back to single SKILL.md path
|
|
53
|
+
mockFetchSkillFileManifest.mockResolvedValue(null);
|
|
41
54
|
});
|
|
42
55
|
|
|
43
56
|
describe("installSkill", () => {
|
|
@@ -57,6 +70,11 @@ describe("installSkill", () => {
|
|
|
57
70
|
expect(result.slug).toBe("review-code");
|
|
58
71
|
expect(result.version).toBe("1.2.0");
|
|
59
72
|
expect(result.dependencies).toEqual([]);
|
|
73
|
+
// Records the install so it counts toward installCount + MCP analytics.
|
|
74
|
+
expect(mockRecordInstall).toHaveBeenCalledWith(
|
|
75
|
+
"review-code",
|
|
76
|
+
"claude-code",
|
|
77
|
+
);
|
|
60
78
|
});
|
|
61
79
|
|
|
62
80
|
it("writes SKILL.md and command file", async () => {
|
package/src/installer.ts
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import { existsSync
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
4
|
+
import {
|
|
5
|
+
atomicWriteSkillFiles,
|
|
6
|
+
buildSkillMarkdown,
|
|
7
|
+
readLocalFile,
|
|
8
|
+
validateSlug,
|
|
9
|
+
writeSkillFiles,
|
|
10
|
+
type SkillFileEntry,
|
|
11
|
+
} from "@skills-hub-ai/installer";
|
|
12
|
+
import {
|
|
13
|
+
fetchSkillFile,
|
|
14
|
+
fetchSkillFileManifest,
|
|
15
|
+
getSkillDetail,
|
|
16
|
+
recordInstall,
|
|
17
|
+
type SkillDetailResult,
|
|
18
|
+
} from "./api.js";
|
|
19
|
+
|
|
20
|
+
const LEARNINGS_PATTERN = /^LEARNINGS(\.md)?$/i;
|
|
19
21
|
|
|
20
22
|
function getSkillsDir(target: "claude-code" | "cursor"): string {
|
|
21
23
|
const home = homedir();
|
|
@@ -31,6 +33,30 @@ function getCommandsDir(target: "claude-code" | "cursor"): string {
|
|
|
31
33
|
: join(home, ".claude", "commands");
|
|
32
34
|
}
|
|
33
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Build the slash command body for claude-code. The format differs from
|
|
38
|
+
* SKILL.md: no `---` delimiters, just frontmatter style fields followed
|
|
39
|
+
* by the body. Kept inline here because it is claude-code specific and
|
|
40
|
+
* not part of the shared installer API.
|
|
41
|
+
*/
|
|
42
|
+
function buildClaudeCommandContent(skill: {
|
|
43
|
+
name: string;
|
|
44
|
+
description: string;
|
|
45
|
+
latestVersion: string;
|
|
46
|
+
category: { slug: string };
|
|
47
|
+
instructions: string;
|
|
48
|
+
}): string {
|
|
49
|
+
return [
|
|
50
|
+
`name: ${skill.name}`,
|
|
51
|
+
`description: ${skill.description}`,
|
|
52
|
+
`version: ${skill.latestVersion}`,
|
|
53
|
+
`category: ${skill.category.slug}`,
|
|
54
|
+
"",
|
|
55
|
+
skill.instructions,
|
|
56
|
+
"",
|
|
57
|
+
].join("\n");
|
|
58
|
+
}
|
|
59
|
+
|
|
34
60
|
export interface InstallResult {
|
|
35
61
|
slug: string;
|
|
36
62
|
version: string;
|
|
@@ -38,6 +64,58 @@ export interface InstallResult {
|
|
|
38
64
|
dependencies: string[];
|
|
39
65
|
}
|
|
40
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Write a skill's file tree to `skillDir`.
|
|
69
|
+
*
|
|
70
|
+
* Prefers the multi-file manifest when available (fetches every file and
|
|
71
|
+
* writes atomically). Falls back to a single generated SKILL.md for older
|
|
72
|
+
* skills that pre-date multi-file ingest. Preserves any existing LEARNINGS.md
|
|
73
|
+
* in both paths — it is user state, not part of the published skill.
|
|
74
|
+
*/
|
|
75
|
+
async function writeSkillTree(
|
|
76
|
+
skill: SkillDetailResult,
|
|
77
|
+
skillDir: string,
|
|
78
|
+
): Promise<void> {
|
|
79
|
+
const manifest = await fetchSkillFileManifest(
|
|
80
|
+
skill.slug,
|
|
81
|
+
skill.latestVersion,
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
if (manifest && manifest.length > 0) {
|
|
85
|
+
const learnings = readLocalFile(skillDir, "LEARNINGS.md");
|
|
86
|
+
|
|
87
|
+
const files: SkillFileEntry[] = await Promise.all(
|
|
88
|
+
manifest
|
|
89
|
+
.filter((entry) => !LEARNINGS_PATTERN.test(entry.relativePath))
|
|
90
|
+
.map(async (entry) => ({
|
|
91
|
+
relativePath: entry.relativePath,
|
|
92
|
+
content: await fetchSkillFile(
|
|
93
|
+
skill.slug,
|
|
94
|
+
skill.latestVersion,
|
|
95
|
+
entry.relativePath,
|
|
96
|
+
),
|
|
97
|
+
})),
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
if (learnings !== null) {
|
|
101
|
+
files.push({ relativePath: "LEARNINGS.md", content: learnings });
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
atomicWriteSkillFiles(skillDir, files);
|
|
105
|
+
} else {
|
|
106
|
+
const skillMd = buildSkillMarkdown(
|
|
107
|
+
{
|
|
108
|
+
name: skill.name,
|
|
109
|
+
description: skill.description,
|
|
110
|
+
version: skill.latestVersion,
|
|
111
|
+
category: skill.category.slug,
|
|
112
|
+
},
|
|
113
|
+
skill.instructions,
|
|
114
|
+
);
|
|
115
|
+
writeSkillFiles(skillDir, [{ relativePath: "SKILL.md", content: skillMd }]);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
41
119
|
/** Install a single skill from the API to the local skills directory */
|
|
42
120
|
export async function installSkill(
|
|
43
121
|
slug: string,
|
|
@@ -47,32 +125,17 @@ export async function installSkill(
|
|
|
47
125
|
const skill = await getSkillDetail(slug);
|
|
48
126
|
const skillDir = join(getSkillsDir(target), slug);
|
|
49
127
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const content = `---
|
|
53
|
-
name: ${yamlEscape(skill.name)}
|
|
54
|
-
description: ${yamlEscape(skill.description)}
|
|
55
|
-
version: ${yamlEscape(skill.latestVersion)}
|
|
56
|
-
category: ${yamlEscape(skill.category.slug)}
|
|
57
|
-
---
|
|
58
|
-
|
|
59
|
-
${skill.instructions}
|
|
60
|
-
`;
|
|
61
|
-
|
|
62
|
-
writeFileSync(join(skillDir, "SKILL.md"), content);
|
|
128
|
+
await writeSkillTree(skill, skillDir);
|
|
63
129
|
|
|
64
130
|
// Register as slash command (Claude Code reads from ~/.claude/commands/)
|
|
65
131
|
if (target === "claude-code") {
|
|
66
132
|
const commandsDir = getCommandsDir(target);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
${skill.instructions}
|
|
74
|
-
`;
|
|
75
|
-
writeFileSync(join(commandsDir, `${slug}.md`), commandContent);
|
|
133
|
+
writeSkillFiles(commandsDir, [
|
|
134
|
+
{
|
|
135
|
+
relativePath: `${slug}.md`,
|
|
136
|
+
content: buildClaudeCommandContent(skill),
|
|
137
|
+
},
|
|
138
|
+
]);
|
|
76
139
|
}
|
|
77
140
|
|
|
78
141
|
// Install composition dependencies
|
|
@@ -81,6 +144,10 @@ ${skill.instructions}
|
|
|
81
144
|
await installDependencies(skill, target, deps);
|
|
82
145
|
}
|
|
83
146
|
|
|
147
|
+
// Record the install so it counts toward installCount and shows up as an MCP
|
|
148
|
+
// install in analytics. Best-effort — never blocks a successful local write.
|
|
149
|
+
await recordInstall(slug, target);
|
|
150
|
+
|
|
84
151
|
return {
|
|
85
152
|
slug,
|
|
86
153
|
version: skill.latestVersion,
|
|
@@ -118,30 +185,18 @@ async function installDependencies(
|
|
|
118
185
|
try {
|
|
119
186
|
const childDetail = await getSkillDetail(childSlug);
|
|
120
187
|
const childDir = join(skillsDir, childSlug);
|
|
121
|
-
mkdirSync(childDir, { recursive: true });
|
|
122
|
-
|
|
123
|
-
const content = `---
|
|
124
|
-
name: ${yamlEscape(childDetail.name)}
|
|
125
|
-
description: ${yamlEscape(childDetail.description)}
|
|
126
|
-
version: ${yamlEscape(childDetail.latestVersion)}
|
|
127
|
-
category: ${yamlEscape(childDetail.category.slug)}
|
|
128
|
-
---
|
|
129
188
|
|
|
130
|
-
|
|
131
|
-
`;
|
|
132
|
-
writeFileSync(join(childDir, "SKILL.md"), content);
|
|
189
|
+
await writeSkillTree(childDetail, childDir);
|
|
133
190
|
|
|
134
191
|
// Register child as slash command too
|
|
135
192
|
if (target === "claude-code") {
|
|
136
193
|
const commandsDir = getCommandsDir(target);
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
`;
|
|
144
|
-
writeFileSync(join(commandsDir, `${childSlug}.md`), commandContent);
|
|
194
|
+
writeSkillFiles(commandsDir, [
|
|
195
|
+
{
|
|
196
|
+
relativePath: `${childSlug}.md`,
|
|
197
|
+
content: buildClaudeCommandContent(childDetail),
|
|
198
|
+
},
|
|
199
|
+
]);
|
|
145
200
|
}
|
|
146
201
|
|
|
147
202
|
installed.push(childSlug);
|