claudepluginhub 0.16.1 → 0.18.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/README.md +36 -2
- package/dist/args.js +0 -6
- package/dist/collection-install.d.ts +4 -23
- package/dist/collection-install.js +9 -45
- package/dist/component-install.js +7 -29
- package/dist/detect.d.ts +0 -2
- package/dist/detect.js +3 -7
- package/dist/doctor/claude-source.d.ts +4 -6
- package/dist/doctor/claude-source.js +1 -2
- package/dist/doctor/color.d.ts +0 -1
- package/dist/doctor/color.js +0 -1
- package/dist/doctor/equivalence.d.ts +1 -1
- package/dist/doctor/equivalence.js +68 -149
- package/dist/doctor/estimate.js +12 -61
- package/dist/doctor/html-report.d.ts +1 -6
- package/dist/doctor/html-report.js +43 -116
- package/dist/doctor/inventory.d.ts +10 -24
- package/dist/doctor/inventory.js +29 -63
- package/dist/doctor/overlap.d.ts +3 -6
- package/dist/doctor/render.js +20 -38
- package/dist/doctor/report.d.ts +7 -16
- package/dist/doctor/report.js +3 -6
- package/dist/doctor/rules.d.ts +29 -16
- package/dist/doctor/rules.js +86 -26
- package/dist/doctor/run.d.ts +1 -1
- package/dist/doctor/run.js +13 -8
- package/dist/doctor/sanitize.d.ts +0 -8
- package/dist/doctor/sanitize.js +1 -6
- package/dist/doctor/select.d.ts +10 -25
- package/dist/doctor/select.js +2 -3
- package/dist/download.d.ts +1 -6
- package/dist/download.js +4 -14
- package/dist/fetch.d.ts +2 -8
- package/dist/fetch.js +6 -21
- package/dist/github-install.js +1 -12
- package/dist/index.js +14 -22
- package/dist/install.js +1 -2
- package/dist/mcp/server.d.ts +25 -0
- package/dist/mcp/server.js +103 -0
- package/dist/mcp/tools.d.ts +73 -0
- package/dist/mcp/tools.js +231 -0
- package/dist/output.d.ts +0 -5
- package/dist/output.js +0 -12
- package/dist/prompts.d.ts +3 -10
- package/dist/prompts.js +5 -20
- package/dist/recommend.d.ts +51 -66
- package/dist/recommend.js +59 -132
- package/dist/remove.d.ts +1 -1
- package/dist/remove.js +5 -10
- package/dist/update.js +1 -5
- package/dist/validation.d.ts +0 -5
- package/dist/validation.js +3 -10
- package/dist/wrapper.d.ts +0 -1
- package/dist/wrapper.js +1 -8
- package/package.json +1 -1
package/dist/github-install.js
CHANGED
|
@@ -30,7 +30,6 @@ async function installMarketplace(ownerRepo, detection, yes, scopeOverride, plug
|
|
|
30
30
|
printError('No valid plugins found in marketplace.');
|
|
31
31
|
process.exit(1);
|
|
32
32
|
}
|
|
33
|
-
// Plugin selection
|
|
34
33
|
let selectedPlugins = manifest.plugins;
|
|
35
34
|
if (pluginName) {
|
|
36
35
|
const match = manifest.plugins.find((p) => p.name === pluginName);
|
|
@@ -59,7 +58,6 @@ async function installMarketplace(ownerRepo, detection, yes, scopeOverride, plug
|
|
|
59
58
|
process.exit(0);
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
|
-
// Scope picker
|
|
63
61
|
let scope = scopeOverride ?? 'project';
|
|
64
62
|
if (!yes && !scopeOverride) {
|
|
65
63
|
print('');
|
|
@@ -70,7 +68,6 @@ async function installMarketplace(ownerRepo, detection, yes, scopeOverride, plug
|
|
|
70
68
|
}
|
|
71
69
|
scope = chosenScope;
|
|
72
70
|
}
|
|
73
|
-
// Add marketplace
|
|
74
71
|
print('');
|
|
75
72
|
printStep(`Adding marketplace from ${ownerRepo}...`);
|
|
76
73
|
const addResult = claudeMarketplaceAdd(ownerRepo, scope);
|
|
@@ -79,7 +76,6 @@ async function installMarketplace(ownerRepo, detection, yes, scopeOverride, plug
|
|
|
79
76
|
process.exit(1);
|
|
80
77
|
}
|
|
81
78
|
printSuccess('Marketplace added');
|
|
82
|
-
// Install each selected plugin
|
|
83
79
|
let failures = 0;
|
|
84
80
|
for (const plugin of selectedPlugins) {
|
|
85
81
|
printStep(`Installing ${plugin.name}...`);
|
|
@@ -104,7 +100,6 @@ async function installMarketplace(ownerRepo, detection, yes, scopeOverride, plug
|
|
|
104
100
|
}
|
|
105
101
|
async function installStandalone(ownerRepo, detection, yes, scopeOverride) {
|
|
106
102
|
printSuccess(`Plugin "${detection.name}" (strict: ${detection.strict})`);
|
|
107
|
-
// Scope picker
|
|
108
103
|
let scope = scopeOverride ?? 'project';
|
|
109
104
|
if (!yes && !scopeOverride) {
|
|
110
105
|
print('');
|
|
@@ -115,7 +110,6 @@ async function installStandalone(ownerRepo, detection, yes, scopeOverride) {
|
|
|
115
110
|
}
|
|
116
111
|
scope = chosenScope;
|
|
117
112
|
}
|
|
118
|
-
// Write wrapper marketplace
|
|
119
113
|
print('');
|
|
120
114
|
printStep('Creating wrapper marketplace...');
|
|
121
115
|
const { wrapperDir, marketplaceName } = writeWrapperMarketplace({
|
|
@@ -125,7 +119,6 @@ async function installStandalone(ownerRepo, detection, yes, scopeOverride) {
|
|
|
125
119
|
strict: detection.strict,
|
|
126
120
|
});
|
|
127
121
|
printSuccess(`Wrapper at ${DIM}${wrapperDir}${RESET}`);
|
|
128
|
-
// Add wrapper marketplace
|
|
129
122
|
printStep('Adding marketplace...');
|
|
130
123
|
const addResult = claudeMarketplaceAdd(wrapperDir, scope);
|
|
131
124
|
if (!addResult.ok) {
|
|
@@ -133,7 +126,6 @@ async function installStandalone(ownerRepo, detection, yes, scopeOverride) {
|
|
|
133
126
|
process.exit(1);
|
|
134
127
|
}
|
|
135
128
|
printSuccess('Marketplace added');
|
|
136
|
-
// Install the plugin
|
|
137
129
|
printStep(`Installing ${detection.name}...`);
|
|
138
130
|
const installResult = claudePluginInstall(detection.name, marketplaceName, scope);
|
|
139
131
|
if (!installResult.ok) {
|
|
@@ -175,7 +167,6 @@ export async function runGithubRemove(ownerRepo, scopeOverride) {
|
|
|
175
167
|
}
|
|
176
168
|
printStep(`Removing ${ownerRepo} (scope: ${scope})...`);
|
|
177
169
|
let anyFailed = false;
|
|
178
|
-
// Best-effort: uninstall plugin
|
|
179
170
|
const uninstallResult = claudePluginUninstall(meta.pluginName, scope);
|
|
180
171
|
if (uninstallResult.ok) {
|
|
181
172
|
printSuccess(`Uninstalled plugin ${meta.pluginName}`);
|
|
@@ -184,7 +175,6 @@ export async function runGithubRemove(ownerRepo, scopeOverride) {
|
|
|
184
175
|
printWarning(`Could not uninstall plugin: ${uninstallResult.output}`);
|
|
185
176
|
anyFailed = true;
|
|
186
177
|
}
|
|
187
|
-
// Best-effort: remove marketplace
|
|
188
178
|
const removeResult = claudeMarketplaceRemove(meta.marketplaceName, scope);
|
|
189
179
|
if (removeResult.ok) {
|
|
190
180
|
printSuccess(`Removed marketplace ${meta.marketplaceName}`);
|
|
@@ -194,7 +184,7 @@ export async function runGithubRemove(ownerRepo, scopeOverride) {
|
|
|
194
184
|
anyFailed = true;
|
|
195
185
|
}
|
|
196
186
|
if (anyFailed) {
|
|
197
|
-
// Keep wrapper metadata so
|
|
187
|
+
// Keep the wrapper metadata so a retry can finish the cleanup.
|
|
198
188
|
print('');
|
|
199
189
|
print(`${YELLOW}${BOLD}Partially removed.${RESET} Some cleanup steps failed.`);
|
|
200
190
|
const wrapperDir = getWrapperDir(ownerRepo, scope);
|
|
@@ -203,7 +193,6 @@ export async function runGithubRemove(ownerRepo, scopeOverride) {
|
|
|
203
193
|
print(`Retry with ${DIM}npx claudepluginhub remove ${ownerRepo} --scope ${scope}${RESET}`);
|
|
204
194
|
}
|
|
205
195
|
else {
|
|
206
|
-
// All native cleanup succeeded — safe to delete wrapper
|
|
207
196
|
removeWrapperDir(ownerRepo, scope);
|
|
208
197
|
printSuccess('Removed wrapper directory');
|
|
209
198
|
print('');
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { runInstall } from './install.js';
|
|
|
5
5
|
import { runUpdate } from './update.js';
|
|
6
6
|
import { runRemove, runDirectRemove } from './remove.js';
|
|
7
7
|
import { runList } from './list.js';
|
|
8
|
-
import { isOwnerRepo } from './
|
|
8
|
+
import { isOwnerRepo } from './validation.js';
|
|
9
9
|
import { runGithubInstall, runGithubRemove } from './github-install.js';
|
|
10
10
|
import { findWrapperScopes } from './wrapper.js';
|
|
11
11
|
import { findDirectInstallScopes } from './scope-detect.js';
|
|
@@ -31,6 +31,8 @@ Commands:
|
|
|
31
31
|
recommend Recommend plugins for the current project
|
|
32
32
|
doctor Diagnose the Claude Code plugin setup (read-only,
|
|
33
33
|
offline; see \`doctor --help\`)
|
|
34
|
+
mcp Run as an MCP server for Claude Code (stdio):
|
|
35
|
+
claude mcp add claudepluginhub -- npx -y claudepluginhub mcp
|
|
34
36
|
|
|
35
37
|
Identifiers:
|
|
36
38
|
owner/repo GitHub plugin or marketplace (via Claude Code)
|
|
@@ -77,14 +79,19 @@ Options:
|
|
|
77
79
|
}
|
|
78
80
|
async function main() {
|
|
79
81
|
const args = process.argv.slice(2);
|
|
80
|
-
// doctor owns its
|
|
81
|
-
//
|
|
82
|
-
// intercept and parseArgs. It also owns its banner and exit codes (0/1/2).
|
|
82
|
+
// doctor owns its flags (incl. `--scope all`, which parseArgs rejects), help,
|
|
83
|
+
// banner and exit codes, so it must route before the global help and parseArgs.
|
|
83
84
|
if (args[0] === 'doctor') {
|
|
84
85
|
const { runDoctor } = await import('./doctor/run.js');
|
|
85
86
|
await runDoctor(args.slice(1));
|
|
86
87
|
return;
|
|
87
88
|
}
|
|
89
|
+
// stdout belongs to the MCP protocol: no banner, nothing printed before the server starts.
|
|
90
|
+
if (args[0] === 'mcp') {
|
|
91
|
+
const { runMcpServer } = await import('./mcp/server.js');
|
|
92
|
+
runMcpServer();
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
88
95
|
if (args.length === 0 || args.includes('--help') || args.includes('-h')) {
|
|
89
96
|
printBanner();
|
|
90
97
|
printUsage();
|
|
@@ -101,7 +108,6 @@ async function main() {
|
|
|
101
108
|
process.exit(0);
|
|
102
109
|
}
|
|
103
110
|
printBanner();
|
|
104
|
-
// Handle non-install commands
|
|
105
111
|
if (command === 'list') {
|
|
106
112
|
runList();
|
|
107
113
|
process.exit(0);
|
|
@@ -116,7 +122,6 @@ async function main() {
|
|
|
116
122
|
process.exit(1);
|
|
117
123
|
}
|
|
118
124
|
if (isOwnerRepo(identifier)) {
|
|
119
|
-
// Scope-aware remove: check both direct installs and wrapper installs
|
|
120
125
|
const directScopes = findDirectInstallScopes(identifier);
|
|
121
126
|
const wrapperScopes = findWrapperScopes(identifier);
|
|
122
127
|
const allMatches = [
|
|
@@ -126,24 +131,21 @@ async function main() {
|
|
|
126
131
|
const filtered = scopeOverride
|
|
127
132
|
? allMatches.filter((m) => m.scope === scopeOverride)
|
|
128
133
|
: allMatches;
|
|
129
|
-
//
|
|
134
|
+
// Nothing found: runGithubRemove prints the marketplace guidance.
|
|
130
135
|
if (allMatches.length === 0) {
|
|
131
136
|
await runGithubRemove(identifier, scopeOverride);
|
|
132
137
|
process.exit(0);
|
|
133
138
|
}
|
|
134
|
-
// Case 2: Found in other scopes but not the requested one
|
|
135
139
|
if (filtered.length === 0) {
|
|
136
140
|
const scopeList = [...new Set(allMatches.map((m) => m.scope))].join(', ');
|
|
137
141
|
printError(`"${identifier}" not found in ${scopeOverride} scope (found in: ${scopeList})`);
|
|
138
142
|
process.exit(1);
|
|
139
143
|
}
|
|
140
|
-
// Case 3: Multiple scopes without --scope
|
|
141
144
|
const uniqueScopes = [...new Set(filtered.map((m) => m.scope))];
|
|
142
145
|
if (uniqueScopes.length > 1) {
|
|
143
146
|
printError(`"${identifier}" found in multiple scopes: ${uniqueScopes.join(', ')}. Use --scope to specify.`);
|
|
144
147
|
process.exit(1);
|
|
145
148
|
}
|
|
146
|
-
// Case 4: Single scope — remove all matching kinds
|
|
147
149
|
const targetScope = uniqueScopes[0];
|
|
148
150
|
if (filtered.some((m) => m.kind === 'direct')) {
|
|
149
151
|
await runDirectRemove(identifier, targetScope);
|
|
@@ -167,23 +169,19 @@ async function main() {
|
|
|
167
169
|
await runRemove(identifier);
|
|
168
170
|
process.exit(0);
|
|
169
171
|
}
|
|
170
|
-
// Install flow
|
|
171
172
|
if (!identifier) {
|
|
172
173
|
printUsage();
|
|
173
174
|
process.exit(1);
|
|
174
175
|
}
|
|
175
|
-
// Direct component install: owner/repo + --skill/--command/--agent
|
|
176
176
|
if (componentFlag && isOwnerRepo(identifier)) {
|
|
177
177
|
const { runDirectComponentInstall } = await import('./component-install.js');
|
|
178
178
|
await runDirectComponentInstall(identifier, componentFlag.type, componentFlag.repoPath, componentFlag.pluginPath, yes, scopeOverride);
|
|
179
179
|
process.exit(0);
|
|
180
180
|
}
|
|
181
|
-
// owner/repo → native Claude Code install
|
|
182
181
|
if (isOwnerRepo(identifier)) {
|
|
183
182
|
await runGithubInstall(identifier, yes, scopeOverride, plugin);
|
|
184
183
|
process.exit(0);
|
|
185
184
|
}
|
|
186
|
-
// Resolve identifier to API URL
|
|
187
185
|
const url = resolveMarketplaceUrl(identifier);
|
|
188
186
|
if (!url) {
|
|
189
187
|
printError(`Invalid identifier: ${identifier}`);
|
|
@@ -191,23 +189,21 @@ async function main() {
|
|
|
191
189
|
print(`Expected: owner/repo, u/<userId>/<slug>, c/<userId>/<slug>, p/<slug>, or a claudepluginhub.com URL`);
|
|
192
190
|
process.exit(1);
|
|
193
191
|
}
|
|
194
|
-
//
|
|
192
|
+
// Collections and wrapper marketplaces reference whole plugins, so they
|
|
193
|
+
// install via native delegation rather than the component downloader.
|
|
195
194
|
if (isCollectionUrl(url)) {
|
|
196
195
|
const { runCollectionInstall } = await import('./collection-install.js');
|
|
197
196
|
await runCollectionInstall(url, yes, scopeOverride);
|
|
198
197
|
process.exit(0);
|
|
199
198
|
}
|
|
200
|
-
// Single-plugin wrapper marketplaces likewise install via native delegation
|
|
201
199
|
if (isPluginWrapperUrl(url)) {
|
|
202
200
|
const { runWrapperPluginInstall } = await import('./collection-install.js');
|
|
203
201
|
await runWrapperPluginInstall(url, yes, scopeOverride);
|
|
204
202
|
process.exit(0);
|
|
205
203
|
}
|
|
206
|
-
// Derive the collection identifier from the input
|
|
207
204
|
const collectionId = identifier.startsWith('http')
|
|
208
205
|
? extractIdentifierFromUrl(identifier)
|
|
209
206
|
: identifier;
|
|
210
|
-
// Fetch manifest
|
|
211
207
|
printStep('Fetching collection...');
|
|
212
208
|
const manifest = await fetchMarketplace(url);
|
|
213
209
|
if (!manifest) {
|
|
@@ -219,7 +215,6 @@ async function main() {
|
|
|
219
215
|
printError('No components found in this collection.');
|
|
220
216
|
process.exit(0);
|
|
221
217
|
}
|
|
222
|
-
// Component selection (interactive)
|
|
223
218
|
let selectedComponents = allComponents;
|
|
224
219
|
if (!yes && allComponents.length > 1) {
|
|
225
220
|
print('');
|
|
@@ -239,7 +234,6 @@ async function main() {
|
|
|
239
234
|
process.exit(0);
|
|
240
235
|
}
|
|
241
236
|
}
|
|
242
|
-
// Scope selection
|
|
243
237
|
let scope = scopeOverride ?? 'project';
|
|
244
238
|
if (!yes && !scopeOverride) {
|
|
245
239
|
print('');
|
|
@@ -250,7 +244,6 @@ async function main() {
|
|
|
250
244
|
}
|
|
251
245
|
scope = chosenScope;
|
|
252
246
|
}
|
|
253
|
-
// Safety warning for hooks/mcp/lsp
|
|
254
247
|
const hasUnsafe = selectedComponents.some((c) => c.type === 'hook' || c.type === 'mcp' || c.type === 'lsp');
|
|
255
248
|
if (hasUnsafe) {
|
|
256
249
|
print('');
|
|
@@ -269,7 +262,6 @@ async function main() {
|
|
|
269
262
|
await runInstall(collectionId, url, selectedComponents, scope);
|
|
270
263
|
}
|
|
271
264
|
function extractIdentifierFromUrl(url) {
|
|
272
|
-
// Extract u/<userId>/<slug> from URL path
|
|
273
265
|
const match = url.match(/\/api\/user-plugins\/([^/]+)\/([^/]+)/);
|
|
274
266
|
if (match) {
|
|
275
267
|
return `u/${match[1]}/${match[2]}`;
|
package/dist/install.js
CHANGED
|
@@ -2,7 +2,6 @@ import { installComponent } from './download.js';
|
|
|
2
2
|
import { readLock, writeLock, addCollection, componentKey } from './lock.js';
|
|
3
3
|
import { print, printStep, printSuccess, printFail, printError, BOLD, RESET, DIM, GREEN, } from './output.js';
|
|
4
4
|
export async function runInstall(identifier, apiUrl, components, scope) {
|
|
5
|
-
// Check if already installed
|
|
6
5
|
const lock = readLock(scope);
|
|
7
6
|
if (lock.collections[identifier]) {
|
|
8
7
|
printError(`Collection "${identifier}" is already installed.`);
|
|
@@ -32,7 +31,7 @@ export async function runInstall(identifier, apiUrl, components, scope) {
|
|
|
32
31
|
printFail(`${component.componentName} (${component.type})`, 'download failed');
|
|
33
32
|
}
|
|
34
33
|
}
|
|
35
|
-
//
|
|
34
|
+
// Partial success still records what was installed.
|
|
36
35
|
if (succeeded > 0) {
|
|
37
36
|
addCollection(lock, identifier, apiUrl, scope, installed);
|
|
38
37
|
writeLock(scope, lock);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zero-dependency MCP server over stdio: newline-delimited JSON-RPC 2.0. stdout carries protocol
|
|
3
|
+
* messages only; anything else (including a stray console.log from reused CLI code) goes to stderr.
|
|
4
|
+
*/
|
|
5
|
+
/** Newest first; an unsupported client version gets our newest, per the spec's negotiation. */
|
|
6
|
+
export declare const SUPPORTED_PROTOCOL_VERSIONS: string[];
|
|
7
|
+
type Id = string | number | null;
|
|
8
|
+
type JsonRpcResponse = {
|
|
9
|
+
jsonrpc: '2.0';
|
|
10
|
+
id: Id;
|
|
11
|
+
result: unknown;
|
|
12
|
+
} | {
|
|
13
|
+
jsonrpc: '2.0';
|
|
14
|
+
id: Id;
|
|
15
|
+
error: {
|
|
16
|
+
code: number;
|
|
17
|
+
message: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/** Handles one parsed message. Returns null for notifications, which never get a response. */
|
|
21
|
+
export declare function handleMessage(message: unknown): Promise<JsonRpcResponse | null>;
|
|
22
|
+
/** Handles one raw stdin line. Returns the serialized response, or null when there is none. */
|
|
23
|
+
export declare function handleLine(line: string): Promise<string | null>;
|
|
24
|
+
export declare function runMcpServer(): void;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { createInterface } from 'node:readline';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { TOOL_DEFINITIONS, callTool, hasTool } from './tools.js';
|
|
4
|
+
/**
|
|
5
|
+
* Zero-dependency MCP server over stdio: newline-delimited JSON-RPC 2.0. stdout carries protocol
|
|
6
|
+
* messages only; anything else (including a stray console.log from reused CLI code) goes to stderr.
|
|
7
|
+
*/
|
|
8
|
+
/** Newest first; an unsupported client version gets our newest, per the spec's negotiation. */
|
|
9
|
+
export const SUPPORTED_PROTOCOL_VERSIONS = ['2025-11-25', '2025-06-18', '2025-03-26', '2024-11-05'];
|
|
10
|
+
const PARSE_ERROR = -32700;
|
|
11
|
+
const INVALID_REQUEST = -32600;
|
|
12
|
+
const METHOD_NOT_FOUND = -32601;
|
|
13
|
+
const INVALID_PARAMS = -32602;
|
|
14
|
+
const INTERNAL_ERROR = -32603;
|
|
15
|
+
const packageVersion = createRequire(import.meta.url)('../../package.json').version;
|
|
16
|
+
const result = (id, value) => ({ jsonrpc: '2.0', id, result: value });
|
|
17
|
+
const error = (id, code, message) => ({
|
|
18
|
+
jsonrpc: '2.0',
|
|
19
|
+
id,
|
|
20
|
+
error: { code, message },
|
|
21
|
+
});
|
|
22
|
+
function isObject(value) {
|
|
23
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
24
|
+
}
|
|
25
|
+
/** Handles one parsed message. Returns null for notifications, which never get a response. */
|
|
26
|
+
export async function handleMessage(message) {
|
|
27
|
+
if (!isObject(message) || message.jsonrpc !== '2.0' || typeof message.method !== 'string') {
|
|
28
|
+
const id = isObject(message) && (typeof message.id === 'string' || typeof message.id === 'number') ? message.id : null;
|
|
29
|
+
return error(id, INVALID_REQUEST, 'Invalid Request');
|
|
30
|
+
}
|
|
31
|
+
if (!('id' in message))
|
|
32
|
+
return null; // notification (initialized, cancelled, ...)
|
|
33
|
+
const { id, method } = message;
|
|
34
|
+
if (typeof id !== 'string' && typeof id !== 'number')
|
|
35
|
+
return error(null, INVALID_REQUEST, 'Invalid Request');
|
|
36
|
+
const params = isObject(message.params) ? message.params : {};
|
|
37
|
+
switch (method) {
|
|
38
|
+
case 'initialize': {
|
|
39
|
+
const requested = params.protocolVersion;
|
|
40
|
+
const protocolVersion = typeof requested === 'string' && SUPPORTED_PROTOCOL_VERSIONS.includes(requested)
|
|
41
|
+
? requested
|
|
42
|
+
: SUPPORTED_PROTOCOL_VERSIONS[0];
|
|
43
|
+
return result(id, {
|
|
44
|
+
protocolVersion,
|
|
45
|
+
capabilities: { tools: {} },
|
|
46
|
+
serverInfo: { name: 'claudepluginhub', version: packageVersion },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
case 'ping':
|
|
50
|
+
return result(id, {});
|
|
51
|
+
case 'tools/list':
|
|
52
|
+
return result(id, { tools: TOOL_DEFINITIONS });
|
|
53
|
+
case 'tools/call': {
|
|
54
|
+
const name = params.name;
|
|
55
|
+
if (typeof name !== 'string' || !hasTool(name)) {
|
|
56
|
+
return error(id, INVALID_PARAMS, `Unknown tool: ${String(name)}`);
|
|
57
|
+
}
|
|
58
|
+
if (params.arguments !== undefined && !isObject(params.arguments)) {
|
|
59
|
+
return error(id, INVALID_PARAMS, 'Tool arguments must be an object');
|
|
60
|
+
}
|
|
61
|
+
return result(id, await callTool(name, params.arguments ?? {}));
|
|
62
|
+
}
|
|
63
|
+
default:
|
|
64
|
+
return error(id, METHOD_NOT_FOUND, `Method not found: ${method}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** Handles one raw stdin line. Returns the serialized response, or null when there is none. */
|
|
68
|
+
export async function handleLine(line) {
|
|
69
|
+
if (line.trim() === '')
|
|
70
|
+
return null;
|
|
71
|
+
let message;
|
|
72
|
+
try {
|
|
73
|
+
message = JSON.parse(line);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return JSON.stringify(error(null, PARSE_ERROR, 'Parse error'));
|
|
77
|
+
}
|
|
78
|
+
let response;
|
|
79
|
+
try {
|
|
80
|
+
response = await handleMessage(message);
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
const id = isObject(message) && (typeof message.id === 'string' || typeof message.id === 'number') ? message.id : null;
|
|
84
|
+
process.stderr.write(`[claudepluginhub mcp] ${err.stack ?? String(err)}\n`);
|
|
85
|
+
response = error(id, INTERNAL_ERROR, 'Internal error');
|
|
86
|
+
}
|
|
87
|
+
return response ? JSON.stringify(response) : null;
|
|
88
|
+
}
|
|
89
|
+
export function runMcpServer() {
|
|
90
|
+
// Reused CLI modules print with console.log; stdout must stay protocol-only.
|
|
91
|
+
console.log = console.error;
|
|
92
|
+
console.info = console.error;
|
|
93
|
+
// The client closing stdio mid-response raises EPIPE on stdout; exit instead of crashing.
|
|
94
|
+
process.stdout.on('error', () => process.exit(0));
|
|
95
|
+
const rl = createInterface({ input: process.stdin, crlfDelay: Infinity });
|
|
96
|
+
rl.on('line', (line) => {
|
|
97
|
+
// Requests run concurrently; each response is written whole, on one line.
|
|
98
|
+
void handleLine(line).then((out) => {
|
|
99
|
+
if (out !== null)
|
|
100
|
+
process.stdout.write(`${out}\n`);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export declare const TOOL_DEFINITIONS: readonly [{
|
|
2
|
+
readonly name: "search_plugins";
|
|
3
|
+
readonly description: "Search Claude Code plugins on ClaudePluginHub";
|
|
4
|
+
readonly inputSchema: {
|
|
5
|
+
readonly type: "object";
|
|
6
|
+
readonly properties: {
|
|
7
|
+
readonly query: {
|
|
8
|
+
readonly type: "string";
|
|
9
|
+
};
|
|
10
|
+
readonly type: {
|
|
11
|
+
readonly type: "string";
|
|
12
|
+
readonly enum: string[];
|
|
13
|
+
};
|
|
14
|
+
readonly maxTokens: {
|
|
15
|
+
readonly type: "integer";
|
|
16
|
+
readonly description: "Max always-on tokens";
|
|
17
|
+
};
|
|
18
|
+
readonly noHooks: {
|
|
19
|
+
readonly type: "boolean";
|
|
20
|
+
};
|
|
21
|
+
readonly limit: {
|
|
22
|
+
readonly type: "integer";
|
|
23
|
+
readonly maximum: 10;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
readonly required: readonly ["query"];
|
|
27
|
+
};
|
|
28
|
+
}, {
|
|
29
|
+
readonly name: "inspect_plugin";
|
|
30
|
+
readonly description: "Plugin details: components, always-on tokens, code it runs, install command";
|
|
31
|
+
readonly inputSchema: {
|
|
32
|
+
readonly type: "object";
|
|
33
|
+
readonly properties: {
|
|
34
|
+
readonly slug: {
|
|
35
|
+
readonly type: "string";
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
readonly required: readonly ["slug"];
|
|
39
|
+
};
|
|
40
|
+
}, {
|
|
41
|
+
readonly name: "recommend_for_project";
|
|
42
|
+
readonly description: "Recommend plugins for a project's stack";
|
|
43
|
+
readonly inputSchema: {
|
|
44
|
+
readonly type: "object";
|
|
45
|
+
readonly properties: {
|
|
46
|
+
readonly projectDir: {
|
|
47
|
+
type: string;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
}, {
|
|
52
|
+
readonly name: "doctor_setup";
|
|
53
|
+
readonly description: "Offline health check of installed plugins";
|
|
54
|
+
readonly inputSchema: {
|
|
55
|
+
readonly type: "object";
|
|
56
|
+
readonly properties: {
|
|
57
|
+
readonly projectDir: {
|
|
58
|
+
type: string;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
}];
|
|
63
|
+
export type ToolResult = {
|
|
64
|
+
content: Array<{
|
|
65
|
+
type: 'text';
|
|
66
|
+
text: string;
|
|
67
|
+
}>;
|
|
68
|
+
isError?: true;
|
|
69
|
+
};
|
|
70
|
+
type Args = Record<string, unknown>;
|
|
71
|
+
export declare function hasTool(name: string): boolean;
|
|
72
|
+
export declare function callTool(name: string, args: Args): Promise<ToolResult>;
|
|
73
|
+
export {};
|