@mcp-z/cli 1.0.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/LICENSE +21 -0
- package/README.md +166 -0
- package/bin/cli.js +5 -0
- package/dist/cjs/cli.d.cts +1 -0
- package/dist/cjs/cli.d.ts +1 -0
- package/dist/cjs/cli.js +576 -0
- package/dist/cjs/cli.js.map +1 -0
- package/dist/cjs/commands/call-tool.d.cts +26 -0
- package/dist/cjs/commands/call-tool.d.ts +26 -0
- package/dist/cjs/commands/call-tool.js +362 -0
- package/dist/cjs/commands/call-tool.js.map +1 -0
- package/dist/cjs/commands/get-prompt.d.cts +26 -0
- package/dist/cjs/commands/get-prompt.d.ts +26 -0
- package/dist/cjs/commands/get-prompt.js +335 -0
- package/dist/cjs/commands/get-prompt.js.map +1 -0
- package/dist/cjs/commands/inspect.d.cts +35 -0
- package/dist/cjs/commands/inspect.d.ts +35 -0
- package/dist/cjs/commands/inspect.js +896 -0
- package/dist/cjs/commands/inspect.js.map +1 -0
- package/dist/cjs/commands/manifest/env-prompting.d.cts +21 -0
- package/dist/cjs/commands/manifest/env-prompting.d.ts +21 -0
- package/dist/cjs/commands/manifest/env-prompting.js +657 -0
- package/dist/cjs/commands/manifest/env-prompting.js.map +1 -0
- package/dist/cjs/commands/manifest/generate.d.cts +124 -0
- package/dist/cjs/commands/manifest/generate.d.ts +124 -0
- package/dist/cjs/commands/manifest/generate.js +2541 -0
- package/dist/cjs/commands/manifest/generate.js.map +1 -0
- package/dist/cjs/commands/manifest/index.d.cts +2 -0
- package/dist/cjs/commands/manifest/index.d.ts +2 -0
- package/dist/cjs/commands/manifest/index.js +229 -0
- package/dist/cjs/commands/manifest/index.js.map +1 -0
- package/dist/cjs/commands/manifest/metadata-reader.d.cts +71 -0
- package/dist/cjs/commands/manifest/metadata-reader.d.ts +71 -0
- package/dist/cjs/commands/manifest/metadata-reader.js +441 -0
- package/dist/cjs/commands/manifest/metadata-reader.js.map +1 -0
- package/dist/cjs/commands/manifest/validate.d.cts +1 -0
- package/dist/cjs/commands/manifest/validate.d.ts +1 -0
- package/dist/cjs/commands/manifest/validate.js +525 -0
- package/dist/cjs/commands/manifest/validate.js.map +1 -0
- package/dist/cjs/commands/read-resource.d.cts +24 -0
- package/dist/cjs/commands/read-resource.d.ts +24 -0
- package/dist/cjs/commands/read-resource.js +311 -0
- package/dist/cjs/commands/read-resource.js.map +1 -0
- package/dist/cjs/commands/search.d.cts +31 -0
- package/dist/cjs/commands/search.d.ts +31 -0
- package/dist/cjs/commands/search.js +464 -0
- package/dist/cjs/commands/search.js.map +1 -0
- package/dist/cjs/commands/up.d.cts +49 -0
- package/dist/cjs/commands/up.d.ts +49 -0
- package/dist/cjs/commands/up.js +235 -0
- package/dist/cjs/commands/up.js.map +1 -0
- package/dist/cjs/index.d.cts +7 -0
- package/dist/cjs/index.d.ts +7 -0
- package/dist/cjs/index.js +85 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/lib/find-config.d.cts +14 -0
- package/dist/cjs/lib/find-config.d.ts +14 -0
- package/dist/cjs/lib/find-config.js +93 -0
- package/dist/cjs/lib/find-config.js.map +1 -0
- package/dist/cjs/lib/json-schema.d.cts +18 -0
- package/dist/cjs/lib/json-schema.d.ts +18 -0
- package/dist/cjs/lib/json-schema.js +306 -0
- package/dist/cjs/lib/json-schema.js.map +1 -0
- package/dist/cjs/lib/resolve-server-config.d.cts +50 -0
- package/dist/cjs/lib/resolve-server-config.d.ts +50 -0
- package/dist/cjs/lib/resolve-server-config.js +214 -0
- package/dist/cjs/lib/resolve-server-config.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types.d.cts +21 -0
- package/dist/cjs/types.d.ts +21 -0
- package/dist/cjs/types.js +32 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/cli.d.ts +1 -0
- package/dist/esm/cli.js +129 -0
- package/dist/esm/cli.js.map +1 -0
- package/dist/esm/commands/call-tool.d.ts +26 -0
- package/dist/esm/commands/call-tool.js +151 -0
- package/dist/esm/commands/call-tool.js.map +1 -0
- package/dist/esm/commands/get-prompt.d.ts +26 -0
- package/dist/esm/commands/get-prompt.js +118 -0
- package/dist/esm/commands/get-prompt.js.map +1 -0
- package/dist/esm/commands/inspect.d.ts +35 -0
- package/dist/esm/commands/inspect.js +438 -0
- package/dist/esm/commands/inspect.js.map +1 -0
- package/dist/esm/commands/manifest/env-prompting.d.ts +21 -0
- package/dist/esm/commands/manifest/env-prompting.js +213 -0
- package/dist/esm/commands/manifest/env-prompting.js.map +1 -0
- package/dist/esm/commands/manifest/generate.d.ts +124 -0
- package/dist/esm/commands/manifest/generate.js +1087 -0
- package/dist/esm/commands/manifest/generate.js.map +1 -0
- package/dist/esm/commands/manifest/index.d.ts +2 -0
- package/dist/esm/commands/manifest/index.js +23 -0
- package/dist/esm/commands/manifest/index.js.map +1 -0
- package/dist/esm/commands/manifest/metadata-reader.d.ts +71 -0
- package/dist/esm/commands/manifest/metadata-reader.js +143 -0
- package/dist/esm/commands/manifest/metadata-reader.js.map +1 -0
- package/dist/esm/commands/manifest/validate.d.ts +1 -0
- package/dist/esm/commands/manifest/validate.js +167 -0
- package/dist/esm/commands/manifest/validate.js.map +1 -0
- package/dist/esm/commands/read-resource.d.ts +24 -0
- package/dist/esm/commands/read-resource.js +95 -0
- package/dist/esm/commands/read-resource.js.map +1 -0
- package/dist/esm/commands/search.d.ts +31 -0
- package/dist/esm/commands/search.js +145 -0
- package/dist/esm/commands/search.js.map +1 -0
- package/dist/esm/commands/up.d.ts +49 -0
- package/dist/esm/commands/up.js +74 -0
- package/dist/esm/commands/up.js.map +1 -0
- package/dist/esm/index.d.ts +7 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/find-config.d.ts +14 -0
- package/dist/esm/lib/find-config.js +42 -0
- package/dist/esm/lib/find-config.js.map +1 -0
- package/dist/esm/lib/json-schema.d.ts +18 -0
- package/dist/esm/lib/json-schema.js +66 -0
- package/dist/esm/lib/json-schema.js.map +1 -0
- package/dist/esm/lib/resolve-server-config.d.ts +50 -0
- package/dist/esm/lib/resolve-server-config.js +154 -0
- package/dist/esm/lib/resolve-server-config.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/types.d.ts +21 -0
- package/dist/esm/types.js +11 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +99 -0
- package/schemas/server.schema.json +489 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/cli/src/commands/up.ts"],"sourcesContent":["import { createServerRegistry, type Dialect, type ServerRegistry } from '@mcp-z/client';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { findConfigPath } from '../lib/find-config.ts';\nimport { hasStartBlock, type ServerConfig } from '../types.ts';\n\n/**\n * Configuration options for the upCommand function\n * @public\n */\nexport interface UpOptions {\n /** Optional path to custom .mcp.json configuration file */\n config?: string;\n /** Start only stdio servers (Claude Code compatible mode) */\n stdioOnly?: boolean;\n /** Start only HTTP servers with start blocks (for Claude Code Desktop) */\n httpOnly?: boolean;\n}\n\n/**\n * MCP server configuration entry per MCP specification.\n *\n * Supports two transport types:\n * - stdio (default if no type): spawned process with stdin/stdout\n * - http: remote HTTP server\n *\n * Transport can be inferred from URL protocol:\n * - http:// or https:// → http\n *\n * @see https://modelcontextprotocol.io/specification/2025-06-18/basic/transports\n */\n\n/**\n * Start a cluster of MCP servers from a configuration file or object.\n *\n * @param opts - Configuration options\n * @param opts.config - Optional path to custom .mcp.json file\n * @returns ServerRegistry with servers map, config, connect method, and close function\n *\n * @example\n * // Auto-discover .mcp.json in current directory\n * const registry = await upCommand();\n *\n * @example\n * // Load from specific config\n * const registry = await upCommand({ config: '/path/to/.mcp.json' });\n *\n * @example\n * // Use in-memory config\n * const registry = await upCommand({\n * mcpServers: {\n * 'echo-stdio': { command: 'node', args: ['test/lib/servers/echo-stdio.ts'] }\n * }\n * });\n */\nexport async function upCommand(opts: UpOptions = {}): Promise<ServerRegistry> {\n const configPath = findConfigPath(opts.config);\n const raw = JSON.parse(fs.readFileSync(configPath, 'utf8'));\n const servers = raw.mcpServers ?? raw.servers ?? raw;\n const configDir = path.dirname(configPath);\n\n // Determine dialects based on flags\n // Default is ['servers', 'start'] (spawns everything)\n let dialects: Dialect[] = ['servers', 'start'];\n if (opts.stdioOnly) {\n dialects = ['servers'];\n } else if (opts.httpOnly) {\n dialects = ['start'];\n // In http-only mode, check if there are any servers with start blocks\n const hasStartBlocks = Object.values(servers || {}).some((entry) => entry && hasStartBlock(entry as ServerConfig));\n if (!hasStartBlocks) {\n console.log(' No HTTP servers found with start configuration');\n console.log(' (stdio servers are spawned automatically by Claude Code)');\n // Return empty registry\n return createServerRegistry({}, { cwd: configDir });\n }\n }\n\n return createServerRegistry(servers, {\n cwd: configDir,\n dialects,\n });\n}\n"],"names":["createServerRegistry","fs","path","findConfigPath","hasStartBlock","upCommand","opts","raw","configPath","config","JSON","parse","readFileSync","servers","mcpServers","configDir","dirname","dialects","stdioOnly","httpOnly","hasStartBlocks","Object","values","some","entry","console","log","cwd"],"mappings":"AAAA,SAASA,oBAAoB,QAA2C,gBAAgB;AACxF,YAAYC,QAAQ,KAAK;AACzB,YAAYC,UAAU,OAAO;AAC7B,SAASC,cAAc,QAAQ,wBAAwB;AACvD,SAASC,aAAa,QAA2B,cAAc;AAe/D;;;;;;;;;;;CAWC,GAED;;;;;;;;;;;;;;;;;;;;;;CAsBC,GACD,OAAO,eAAeC,UAAUC,OAAkB,CAAC,CAAC;QAGlCC,MAAAA;IAFhB,MAAMC,aAAaL,eAAeG,KAAKG,MAAM;IAC7C,MAAMF,MAAMG,KAAKC,KAAK,CAACV,GAAGW,YAAY,CAACJ,YAAY;IACnD,MAAMK,WAAUN,QAAAA,kBAAAA,IAAIO,UAAU,cAAdP,6BAAAA,kBAAkBA,IAAIM,OAAO,cAA7BN,kBAAAA,OAAiCA;IACjD,MAAMQ,YAAYb,KAAKc,OAAO,CAACR;IAE/B,oCAAoC;IACpC,sDAAsD;IACtD,IAAIS,WAAsB;QAAC;QAAW;KAAQ;IAC9C,IAAIX,KAAKY,SAAS,EAAE;QAClBD,WAAW;YAAC;SAAU;IACxB,OAAO,IAAIX,KAAKa,QAAQ,EAAE;QACxBF,WAAW;YAAC;SAAQ;QACpB,sEAAsE;QACtE,MAAMG,iBAAiBC,OAAOC,MAAM,CAACT,WAAW,CAAC,GAAGU,IAAI,CAAC,CAACC,QAAUA,SAASpB,cAAcoB;QAC3F,IAAI,CAACJ,gBAAgB;YACnBK,QAAQC,GAAG,CAAC;YACZD,QAAQC,GAAG,CAAC;YACZ,wBAAwB;YACxB,OAAO1B,qBAAqB,CAAC,GAAG;gBAAE2B,KAAKZ;YAAU;QACnD;IACF;IAEA,OAAOf,qBAAqBa,SAAS;QACnCc,KAAKZ;QACLE;IACF;AACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { type Combination, type ConfigChoice, type ConfigurationMode, createConfigChoices, type Dimension, discoverServerJson, extractServerName, filterConfigChoices, generateConditionalCombinations, generateConfigFile, generateConfigObject, generateMatrixCombinations, shouldPromptEnvVar, TRANSPORT_MAP, } from './commands/manifest/generate.js';
|
|
2
|
+
export { type CliArgMetadata, type EnvVarMetadata, MetadataReader, type ServerMetadata } from './commands/manifest/metadata-reader.js';
|
|
3
|
+
export { validateCommand } from './commands/manifest/validate.js';
|
|
4
|
+
export { upCommand } from './commands/up.js';
|
|
5
|
+
export { getSchema, SCHEMA_URL, validateSchema } from './lib/json-schema.js';
|
|
6
|
+
export { type InlineConfigOptions, type ResolvedServerConfig, resolveServerConfig } from './lib/resolve-server-config.js';
|
|
7
|
+
export * from './types.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Base types and type guards
|
|
2
|
+
export { createConfigChoices, discoverServerJson, extractServerName, filterConfigChoices, generateConditionalCombinations, generateConfigFile, generateConfigObject, generateMatrixCombinations, shouldPromptEnvVar, TRANSPORT_MAP } from './commands/manifest/generate.js';
|
|
3
|
+
export { MetadataReader } from './commands/manifest/metadata-reader.js';
|
|
4
|
+
// Manifest commands
|
|
5
|
+
export { validateCommand } from './commands/manifest/validate.js';
|
|
6
|
+
// Commands
|
|
7
|
+
export { upCommand } from './commands/up.js';
|
|
8
|
+
// Library utilities
|
|
9
|
+
export { getSchema, SCHEMA_URL, validateSchema } from './lib/json-schema.js';
|
|
10
|
+
export { resolveServerConfig } from './lib/resolve-server-config.js';
|
|
11
|
+
export * from './types.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/cli/src/index.ts"],"sourcesContent":["// Base types and type guards\n\nexport {\n type Combination,\n type ConfigChoice,\n type ConfigurationMode,\n createConfigChoices,\n type Dimension,\n discoverServerJson,\n extractServerName,\n filterConfigChoices,\n generateConditionalCombinations,\n generateConfigFile,\n generateConfigObject,\n generateMatrixCombinations,\n shouldPromptEnvVar,\n TRANSPORT_MAP,\n} from './commands/manifest/generate.ts';\nexport { type CliArgMetadata, type EnvVarMetadata, MetadataReader, type ServerMetadata } from './commands/manifest/metadata-reader.ts';\n\n// Manifest commands\nexport { validateCommand } from './commands/manifest/validate.ts';\n// Commands\nexport { upCommand } from './commands/up.ts';\n// Library utilities\nexport { getSchema, SCHEMA_URL, validateSchema } from './lib/json-schema.ts';\nexport { type InlineConfigOptions, type ResolvedServerConfig, resolveServerConfig } from './lib/resolve-server-config.ts';\nexport * from './types.ts';\n"],"names":["createConfigChoices","discoverServerJson","extractServerName","filterConfigChoices","generateConditionalCombinations","generateConfigFile","generateConfigObject","generateMatrixCombinations","shouldPromptEnvVar","TRANSPORT_MAP","MetadataReader","validateCommand","upCommand","getSchema","SCHEMA_URL","validateSchema","resolveServerConfig"],"mappings":"AAAA,6BAA6B;AAE7B,SAIEA,mBAAmB,EAEnBC,kBAAkB,EAClBC,iBAAiB,EACjBC,mBAAmB,EACnBC,+BAA+B,EAC/BC,kBAAkB,EAClBC,oBAAoB,EACpBC,0BAA0B,EAC1BC,kBAAkB,EAClBC,aAAa,QACR,kCAAkC;AACzC,SAAmDC,cAAc,QAA6B,yCAAyC;AAEvI,oBAAoB;AACpB,SAASC,eAAe,QAAQ,kCAAkC;AAClE,WAAW;AACX,SAASC,SAAS,QAAQ,mBAAmB;AAC7C,oBAAoB;AACpB,SAASC,SAAS,EAAEC,UAAU,EAAEC,cAAc,QAAQ,uBAAuB;AAC7E,SAA8DC,mBAAmB,QAAQ,iCAAiC;AAC1H,cAAc,aAAa"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* find-config.ts
|
|
3
|
+
*
|
|
4
|
+
* Find .mcp.json config file by searching up the directory tree.
|
|
5
|
+
* Searches from cwd up to home directory (like Claude Code).
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Find .mcp.json by searching up directory tree from cwd to home directory.
|
|
9
|
+
*
|
|
10
|
+
* @param explicitPath - If provided, validates and returns this path (for --config flag)
|
|
11
|
+
* @returns The resolved path to the config file
|
|
12
|
+
* @throws Error if config file not found
|
|
13
|
+
*/
|
|
14
|
+
export declare function findConfigPath(explicitPath?: string): string;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* find-config.ts
|
|
3
|
+
*
|
|
4
|
+
* Find .mcp.json config file by searching up the directory tree.
|
|
5
|
+
* Searches from cwd up to home directory (like Claude Code).
|
|
6
|
+
*/ import * as fs from 'fs';
|
|
7
|
+
import moduleRoot from 'module-root-sync';
|
|
8
|
+
import * as os from 'os';
|
|
9
|
+
import * as path from 'path';
|
|
10
|
+
const CONFIG_NAME = '.mcp.json';
|
|
11
|
+
/**
|
|
12
|
+
* Find .mcp.json by searching up directory tree from cwd to home directory.
|
|
13
|
+
*
|
|
14
|
+
* @param explicitPath - If provided, validates and returns this path (for --config flag)
|
|
15
|
+
* @returns The resolved path to the config file
|
|
16
|
+
* @throws Error if config file not found
|
|
17
|
+
*/ export function findConfigPath(explicitPath) {
|
|
18
|
+
// If explicit path provided, validate it exists
|
|
19
|
+
if (explicitPath) {
|
|
20
|
+
const resolvedPath = path.resolve(explicitPath);
|
|
21
|
+
if (!fs.existsSync(resolvedPath)) {
|
|
22
|
+
throw new Error(`Config file not found: ${resolvedPath}`);
|
|
23
|
+
}
|
|
24
|
+
return resolvedPath;
|
|
25
|
+
}
|
|
26
|
+
const cwd = process.cwd();
|
|
27
|
+
const homeDir = os.homedir();
|
|
28
|
+
// Use module-root-sync with custom file name to search up
|
|
29
|
+
try {
|
|
30
|
+
const configDir = moduleRoot(cwd, {
|
|
31
|
+
name: CONFIG_NAME
|
|
32
|
+
});
|
|
33
|
+
const configPath = path.join(configDir, CONFIG_NAME);
|
|
34
|
+
// Ensure we haven't gone above home directory
|
|
35
|
+
if (!configPath.startsWith(homeDir)) {
|
|
36
|
+
throw new Error(`Config file not found in directory tree (searched from ${cwd} to ${homeDir})`);
|
|
37
|
+
}
|
|
38
|
+
return configPath;
|
|
39
|
+
} catch (_) {
|
|
40
|
+
throw new Error(`Config file not found: ${CONFIG_NAME}\n\nSearched from ${cwd} up to ${homeDir}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/cli/src/lib/find-config.ts"],"sourcesContent":["/**\n * find-config.ts\n *\n * Find .mcp.json config file by searching up the directory tree.\n * Searches from cwd up to home directory (like Claude Code).\n */\n\nimport * as fs from 'fs';\nimport moduleRoot from 'module-root-sync';\nimport * as os from 'os';\nimport * as path from 'path';\n\nconst CONFIG_NAME = '.mcp.json';\n\n/**\n * Find .mcp.json by searching up directory tree from cwd to home directory.\n *\n * @param explicitPath - If provided, validates and returns this path (for --config flag)\n * @returns The resolved path to the config file\n * @throws Error if config file not found\n */\nexport function findConfigPath(explicitPath?: string): string {\n // If explicit path provided, validate it exists\n if (explicitPath) {\n const resolvedPath = path.resolve(explicitPath);\n if (!fs.existsSync(resolvedPath)) {\n throw new Error(`Config file not found: ${resolvedPath}`);\n }\n return resolvedPath;\n }\n\n const cwd = process.cwd();\n const homeDir = os.homedir();\n\n // Use module-root-sync with custom file name to search up\n try {\n const configDir = moduleRoot(cwd, { name: CONFIG_NAME });\n const configPath = path.join(configDir, CONFIG_NAME);\n\n // Ensure we haven't gone above home directory\n if (!configPath.startsWith(homeDir)) {\n throw new Error(`Config file not found in directory tree (searched from ${cwd} to ${homeDir})`);\n }\n\n return configPath;\n } catch (_) {\n throw new Error(`Config file not found: ${CONFIG_NAME}\\n\\nSearched from ${cwd} up to ${homeDir}`);\n }\n}\n"],"names":["fs","moduleRoot","os","path","CONFIG_NAME","findConfigPath","explicitPath","resolvedPath","resolve","existsSync","Error","cwd","process","homeDir","homedir","configDir","name","configPath","join","startsWith","_"],"mappings":"AAAA;;;;;CAKC,GAED,YAAYA,QAAQ,KAAK;AACzB,OAAOC,gBAAgB,mBAAmB;AAC1C,YAAYC,QAAQ,KAAK;AACzB,YAAYC,UAAU,OAAO;AAE7B,MAAMC,cAAc;AAEpB;;;;;;CAMC,GACD,OAAO,SAASC,eAAeC,YAAqB;IAClD,gDAAgD;IAChD,IAAIA,cAAc;QAChB,MAAMC,eAAeJ,KAAKK,OAAO,CAACF;QAClC,IAAI,CAACN,GAAGS,UAAU,CAACF,eAAe;YAChC,MAAM,IAAIG,MAAM,CAAC,uBAAuB,EAAEH,cAAc;QAC1D;QACA,OAAOA;IACT;IAEA,MAAMI,MAAMC,QAAQD,GAAG;IACvB,MAAME,UAAUX,GAAGY,OAAO;IAE1B,0DAA0D;IAC1D,IAAI;QACF,MAAMC,YAAYd,WAAWU,KAAK;YAAEK,MAAMZ;QAAY;QACtD,MAAMa,aAAad,KAAKe,IAAI,CAACH,WAAWX;QAExC,8CAA8C;QAC9C,IAAI,CAACa,WAAWE,UAAU,CAACN,UAAU;YACnC,MAAM,IAAIH,MAAM,CAAC,uDAAuD,EAAEC,IAAI,IAAI,EAAEE,QAAQ,CAAC,CAAC;QAChG;QAEA,OAAOI;IACT,EAAE,OAAOG,GAAG;QACV,MAAM,IAAIV,MAAM,CAAC,uBAAuB,EAAEN,YAAY,kBAAkB,EAAEO,IAAI,OAAO,EAAEE,SAAS;IAClG;AACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const SCHEMA_URL = "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json";
|
|
2
|
+
/**
|
|
3
|
+
* Get MCP server.json schema (fetches once, then caches)
|
|
4
|
+
*
|
|
5
|
+
* Strategy:
|
|
6
|
+
* 1. Return cached schema if available
|
|
7
|
+
* 2. Try fetching latest schema from URL
|
|
8
|
+
* 3. Fall back to bundled schema if network fails
|
|
9
|
+
*/
|
|
10
|
+
export declare function getSchema(): Promise<object>;
|
|
11
|
+
/**
|
|
12
|
+
* Validate server.json against MCP schema
|
|
13
|
+
*
|
|
14
|
+
* @param serverJson - Parsed server.json content to validate
|
|
15
|
+
* @param serverName - Server name for error messages
|
|
16
|
+
* @throws Error with detailed validation messages if invalid
|
|
17
|
+
*/
|
|
18
|
+
export declare function validateSchema(serverJson: unknown, serverName: string): Promise<void>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Ajv } from 'ajv';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import { createRequire } from 'module';
|
|
4
|
+
import * as path from 'path';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
// ESM-compatible __dirname equivalent
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = path.dirname(__filename);
|
|
9
|
+
// Import ajv-formats (CommonJS module - use createRequire for ESM compatibility)
|
|
10
|
+
const require = createRequire(import.meta.url);
|
|
11
|
+
const addFormats = require('ajv-formats');
|
|
12
|
+
export const SCHEMA_URL = 'https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json';
|
|
13
|
+
let schemaCache = null;
|
|
14
|
+
/**
|
|
15
|
+
* Get MCP server.json schema (fetches once, then caches)
|
|
16
|
+
*
|
|
17
|
+
* Strategy:
|
|
18
|
+
* 1. Return cached schema if available
|
|
19
|
+
* 2. Try fetching latest schema from URL
|
|
20
|
+
* 3. Fall back to bundled schema if network fails
|
|
21
|
+
*/ export async function getSchema() {
|
|
22
|
+
// Return cached schema
|
|
23
|
+
if (schemaCache) {
|
|
24
|
+
return schemaCache;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
// Try fetching latest schema
|
|
28
|
+
const response = await fetch(SCHEMA_URL);
|
|
29
|
+
if (response.ok) {
|
|
30
|
+
schemaCache = await response.json();
|
|
31
|
+
return schemaCache;
|
|
32
|
+
}
|
|
33
|
+
} catch {
|
|
34
|
+
// Network error - fall through to bundled version
|
|
35
|
+
}
|
|
36
|
+
// Fallback to bundled schema
|
|
37
|
+
const bundledPath = path.join(__dirname, '../../schemas/server.schema.json');
|
|
38
|
+
if (!fs.existsSync(bundledPath)) {
|
|
39
|
+
throw new Error('Failed to fetch MCP schema from URL and no bundled schema found. ' + 'Check network connection or report this as a bug.');
|
|
40
|
+
}
|
|
41
|
+
schemaCache = JSON.parse(fs.readFileSync(bundledPath, 'utf8'));
|
|
42
|
+
return schemaCache;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Validate server.json against MCP schema
|
|
46
|
+
*
|
|
47
|
+
* @param serverJson - Parsed server.json content to validate
|
|
48
|
+
* @param serverName - Server name for error messages
|
|
49
|
+
* @throws Error with detailed validation messages if invalid
|
|
50
|
+
*/ export async function validateSchema(serverJson, serverName) {
|
|
51
|
+
const schema = await getSchema();
|
|
52
|
+
const ajv = new Ajv({
|
|
53
|
+
allErrors: true,
|
|
54
|
+
verbose: true,
|
|
55
|
+
strictSchema: false
|
|
56
|
+
});
|
|
57
|
+
// Add format validators (uri, email, etc.) to silence warnings
|
|
58
|
+
addFormats(ajv);
|
|
59
|
+
const validate = ajv.compile(schema);
|
|
60
|
+
const valid = validate(serverJson);
|
|
61
|
+
if (!valid) {
|
|
62
|
+
var _validate_errors;
|
|
63
|
+
const errors = ((_validate_errors = validate.errors) === null || _validate_errors === void 0 ? void 0 : _validate_errors.map((e)=>` - ${e.instancePath || '(root)'} ${e.message}`).join('\n')) || 'Unknown validation error';
|
|
64
|
+
throw new Error(`Invalid server.json for '${serverName}':\n${errors}\n\nThe server.json file does not conform to the MCP specification.\nSee: https://modelcontextprotocol.io/specification/server\n\nTo fix: Update the server.json file to match the schema requirements above.`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/cli/src/lib/json-schema.ts"],"sourcesContent":["import { Ajv, type ErrorObject } from 'ajv';\nimport * as fs from 'fs';\nimport { createRequire } from 'module';\nimport * as path from 'path';\nimport { fileURLToPath } from 'url';\n\n// ESM-compatible __dirname equivalent\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\n// Import ajv-formats (CommonJS module - use createRequire for ESM compatibility)\nconst require = createRequire(import.meta.url);\nconst addFormats = require('ajv-formats');\n\nexport const SCHEMA_URL = 'https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json';\n\nlet schemaCache: object | null = null;\n\n/**\n * Get MCP server.json schema (fetches once, then caches)\n *\n * Strategy:\n * 1. Return cached schema if available\n * 2. Try fetching latest schema from URL\n * 3. Fall back to bundled schema if network fails\n */\nexport async function getSchema(): Promise<object> {\n // Return cached schema\n if (schemaCache) {\n return schemaCache;\n }\n\n try {\n // Try fetching latest schema\n const response = await fetch(SCHEMA_URL);\n if (response.ok) {\n schemaCache = (await response.json()) as object;\n return schemaCache;\n }\n } catch {\n // Network error - fall through to bundled version\n }\n\n // Fallback to bundled schema\n const bundledPath = path.join(__dirname, '../../schemas/server.schema.json');\n if (!fs.existsSync(bundledPath)) {\n throw new Error('Failed to fetch MCP schema from URL and no bundled schema found. ' + 'Check network connection or report this as a bug.');\n }\n\n schemaCache = JSON.parse(fs.readFileSync(bundledPath, 'utf8')) as object;\n return schemaCache;\n}\n\n/**\n * Validate server.json against MCP schema\n *\n * @param serverJson - Parsed server.json content to validate\n * @param serverName - Server name for error messages\n * @throws Error with detailed validation messages if invalid\n */\nexport async function validateSchema(serverJson: unknown, serverName: string): Promise<void> {\n const schema = await getSchema();\n\n const ajv = new Ajv({\n allErrors: true,\n verbose: true,\n strictSchema: false, // Allow non-standard keywords like \"example\", \"choices\"\n });\n\n // Add format validators (uri, email, etc.) to silence warnings\n addFormats(ajv);\n\n const validate = ajv.compile(schema);\n const valid = validate(serverJson);\n\n if (!valid) {\n const errors = validate.errors?.map((e: ErrorObject) => ` - ${e.instancePath || '(root)'} ${e.message}`).join('\\n') || 'Unknown validation error';\n\n throw new Error(`Invalid server.json for '${serverName}':\\n${errors}\\n\\nThe server.json file does not conform to the MCP specification.\\nSee: https://modelcontextprotocol.io/specification/server\\n\\nTo fix: Update the server.json file to match the schema requirements above.`);\n }\n}\n"],"names":["Ajv","fs","createRequire","path","fileURLToPath","__filename","url","__dirname","dirname","require","addFormats","SCHEMA_URL","schemaCache","getSchema","response","fetch","ok","json","bundledPath","join","existsSync","Error","JSON","parse","readFileSync","validateSchema","serverJson","serverName","schema","ajv","allErrors","verbose","strictSchema","validate","compile","valid","errors","map","e","instancePath","message"],"mappings":"AAAA,SAASA,GAAG,QAA0B,MAAM;AAC5C,YAAYC,QAAQ,KAAK;AACzB,SAASC,aAAa,QAAQ,SAAS;AACvC,YAAYC,UAAU,OAAO;AAC7B,SAASC,aAAa,QAAQ,MAAM;AAEpC,sCAAsC;AACtC,MAAMC,aAAaD,cAAc,YAAYE,GAAG;AAChD,MAAMC,YAAYJ,KAAKK,OAAO,CAACH;AAE/B,iFAAiF;AACjF,MAAMI,UAAUP,cAAc,YAAYI,GAAG;AAC7C,MAAMI,aAAaD,QAAQ;AAE3B,OAAO,MAAME,aAAa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LI commands.
|
|
5
|
+
* Supports both config file-based and inline server configurations.
|
|
6
|
+
*/
|
|
7
|
+
import type { ServersConfig } from '@mcp-z/client';
|
|
8
|
+
import type { ServerConfig } from '../types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Options for inline server configuration.
|
|
11
|
+
*/
|
|
12
|
+
export interface InlineConfigOptions {
|
|
13
|
+
/** Server name (optional when inline config provided) */
|
|
14
|
+
server?: string;
|
|
15
|
+
/** Config file path (mutually exclusive with inline options) */
|
|
16
|
+
config?: string;
|
|
17
|
+
/** Stdio run command string (e.g., "npx -y @echo/server") */
|
|
18
|
+
run?: string;
|
|
19
|
+
/** HTTP server URL */
|
|
20
|
+
url?: string;
|
|
21
|
+
/** Full server config as JSON string */
|
|
22
|
+
serverConfig?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Resolved server configuration.
|
|
26
|
+
*/
|
|
27
|
+
export interface ResolvedServerConfig {
|
|
28
|
+
/** Server name for display purposes */
|
|
29
|
+
serverName: string;
|
|
30
|
+
/** The server configuration object */
|
|
31
|
+
serverConfig: ServerConfig;
|
|
32
|
+
/** Working directory for the server (cwd for inline, config dir for file) */
|
|
33
|
+
configDir: string;
|
|
34
|
+
/** Full servers config (for HTTP auth flow that needs full config) */
|
|
35
|
+
fullConfig: ServersConfig;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Resolve server configuration from CLI options.
|
|
39
|
+
*
|
|
40
|
+
* Supports three modes:
|
|
41
|
+
* 1. Config file: --config path + server positional
|
|
42
|
+
* 2. Inline stdio: --run "npx server"
|
|
43
|
+
* 3. Inline HTTP: --url "https://..."
|
|
44
|
+
* 4. Full JSON: --server '{"command":"npx",...}'
|
|
45
|
+
*
|
|
46
|
+
* @param opts - CLI options for config resolution
|
|
47
|
+
* @returns Resolved server configuration
|
|
48
|
+
* @throws Error if configuration is invalid
|
|
49
|
+
*/
|
|
50
|
+
export declare function resolveServerConfig(opts: InlineConfigOptions): ResolvedServerConfig;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* resolve-server-config.ts
|
|
3
|
+
*
|
|
4
|
+
* Shared config resolution for CLI commands.
|
|
5
|
+
* Supports both config file-based and inline server configurations.
|
|
6
|
+
*/ import { validateServers } from '@mcp-z/client';
|
|
7
|
+
import * as fs from 'fs';
|
|
8
|
+
import * as path from 'path';
|
|
9
|
+
import { findConfigPath } from './find-config.js';
|
|
10
|
+
/**
|
|
11
|
+
* Resolve server configuration from CLI options.
|
|
12
|
+
*
|
|
13
|
+
* Supports three modes:
|
|
14
|
+
* 1. Config file: --config path + server positional
|
|
15
|
+
* 2. Inline stdio: --run "npx server"
|
|
16
|
+
* 3. Inline HTTP: --url "https://..."
|
|
17
|
+
* 4. Full JSON: --server '{"command":"npx",...}'
|
|
18
|
+
*
|
|
19
|
+
* @param opts - CLI options for config resolution
|
|
20
|
+
* @returns Resolved server configuration
|
|
21
|
+
* @throws Error if configuration is invalid
|
|
22
|
+
*/ export function resolveServerConfig(opts) {
|
|
23
|
+
// Validate mutual exclusivity of inline options
|
|
24
|
+
const inlineOptions = [
|
|
25
|
+
opts.run,
|
|
26
|
+
opts.url,
|
|
27
|
+
opts.serverConfig
|
|
28
|
+
].filter(Boolean);
|
|
29
|
+
if (inlineOptions.length > 1) {
|
|
30
|
+
throw new Error('Cannot use multiple inline config options. Use only one of: --run, --url, or --server');
|
|
31
|
+
}
|
|
32
|
+
const hasInlineConfig = inlineOptions.length > 0;
|
|
33
|
+
// Validate mutual exclusivity with config file
|
|
34
|
+
if (hasInlineConfig && opts.config) {
|
|
35
|
+
throw new Error('Cannot use --config with inline config options (--run, --url, --server)');
|
|
36
|
+
}
|
|
37
|
+
// Handle inline configuration
|
|
38
|
+
if (hasInlineConfig) {
|
|
39
|
+
return resolveInlineConfig(opts);
|
|
40
|
+
}
|
|
41
|
+
// Handle config file-based configuration
|
|
42
|
+
return resolveFileConfig(opts);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Resolve inline server configuration.
|
|
46
|
+
*/ function resolveInlineConfig(opts) {
|
|
47
|
+
const serverName = opts.server || 'inline';
|
|
48
|
+
const configDir = process.cwd();
|
|
49
|
+
let serverConfig;
|
|
50
|
+
if (opts.run) {
|
|
51
|
+
// Parse run string into command + args (simple helper, no schema validation needed)
|
|
52
|
+
serverConfig = parseRunString(opts.run);
|
|
53
|
+
} else if (opts.url) {
|
|
54
|
+
// Create HTTP server config (simple helper, no schema validation needed)
|
|
55
|
+
serverConfig = {
|
|
56
|
+
type: 'http',
|
|
57
|
+
url: opts.url
|
|
58
|
+
};
|
|
59
|
+
} else if (opts.serverConfig) {
|
|
60
|
+
// Parse full JSON config with schema validation
|
|
61
|
+
serverConfig = parseServerConfigJson(opts.serverConfig, serverName);
|
|
62
|
+
} else {
|
|
63
|
+
throw new Error('No inline config provided');
|
|
64
|
+
}
|
|
65
|
+
// Create a minimal servers config for the resolved server
|
|
66
|
+
const fullConfig = {
|
|
67
|
+
[serverName]: serverConfig
|
|
68
|
+
};
|
|
69
|
+
return {
|
|
70
|
+
serverName,
|
|
71
|
+
serverConfig,
|
|
72
|
+
configDir,
|
|
73
|
+
fullConfig
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Resolve config file-based server configuration.
|
|
78
|
+
*/ function resolveFileConfig(opts) {
|
|
79
|
+
var _ref, _raw_mcpServers;
|
|
80
|
+
if (!opts.server) {
|
|
81
|
+
throw new Error('Server name is required when using config file');
|
|
82
|
+
}
|
|
83
|
+
const cfgPath = findConfigPath(opts.config);
|
|
84
|
+
const raw = JSON.parse(fs.readFileSync(cfgPath, 'utf8'));
|
|
85
|
+
const servers = (_ref = (_raw_mcpServers = raw.mcpServers) !== null && _raw_mcpServers !== void 0 ? _raw_mcpServers : raw.servers) !== null && _ref !== void 0 ? _ref : raw;
|
|
86
|
+
const serverNames = Object.keys(servers || {});
|
|
87
|
+
if (!serverNames.includes(opts.server)) {
|
|
88
|
+
throw new Error(`Server '${opts.server}' not found in config\n\nAvailable servers: ${serverNames.join(', ')}`);
|
|
89
|
+
}
|
|
90
|
+
const serverConfig = servers[opts.server];
|
|
91
|
+
if (!serverConfig) {
|
|
92
|
+
throw new Error(`Server ${opts.server} not found in config`);
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
serverName: opts.server,
|
|
96
|
+
serverConfig: serverConfig,
|
|
97
|
+
configDir: path.dirname(cfgPath),
|
|
98
|
+
fullConfig: servers
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Parse a run string into a ServerConfigStdio.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* parseRunString("npx -y @echo/server")
|
|
106
|
+
* // => { command: "npx", args: ["-y", "@echo/server"] }
|
|
107
|
+
*/ function parseRunString(runStr) {
|
|
108
|
+
const parts = runStr.trim().split(/\s+/);
|
|
109
|
+
if (parts.length === 0 || !parts[0]) {
|
|
110
|
+
throw new Error('Run string cannot be empty');
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
command: parts[0],
|
|
114
|
+
args: parts.slice(1)
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Parse and validate a full server config JSON string against the MCP schema.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* parseServerConfigJson('{"command":"npx","args":["-y","@echo/server"]}')
|
|
122
|
+
* parseServerConfigJson('{"url":"https://example.com/mcp","type":"http"}')
|
|
123
|
+
*/ function parseServerConfigJson(jsonStr, serverName) {
|
|
124
|
+
let parsed;
|
|
125
|
+
try {
|
|
126
|
+
parsed = JSON.parse(jsonStr);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
throw new Error(`Failed to parse server config JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
129
|
+
}
|
|
130
|
+
if (typeof parsed !== 'object' || parsed === null) {
|
|
131
|
+
throw new Error('Server config must be a JSON object');
|
|
132
|
+
}
|
|
133
|
+
const config = parsed;
|
|
134
|
+
// Validate: must have either 'command' (stdio) or 'url' (http)
|
|
135
|
+
if (!config.command && !config.url) {
|
|
136
|
+
throw new Error('Server config must have either "command" (for stdio) or "url" (for http)');
|
|
137
|
+
}
|
|
138
|
+
// Normalize: if url is present without explicit type, set type to 'http'
|
|
139
|
+
if (config.url && !config.type) {
|
|
140
|
+
config.type = 'http';
|
|
141
|
+
}
|
|
142
|
+
// Validate against the MCP servers schema
|
|
143
|
+
const serversMap = {
|
|
144
|
+
[serverName]: config
|
|
145
|
+
};
|
|
146
|
+
const validation = validateServers(serversMap);
|
|
147
|
+
if (!validation.valid) {
|
|
148
|
+
var _validation_errors;
|
|
149
|
+
const errorDetails = ((_validation_errors = validation.errors) === null || _validation_errors === void 0 ? void 0 : _validation_errors.join('\n ')) || 'Unknown validation error';
|
|
150
|
+
throw new Error(`Invalid server config:\n ${errorDetails}`);
|
|
151
|
+
}
|
|
152
|
+
// Return as ServerConfig (compatible with McpServerEntry)
|
|
153
|
+
return config;
|
|
154
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/cli/src/lib/resolve-server-config.ts"],"sourcesContent":["/**\n * resolve-server-config.ts\n *\n * Shared config resolution for CLI commands.\n * Supports both config file-based and inline server configurations.\n */\n\nimport type { McpServerEntry, ServersConfig } from '@mcp-z/client';\nimport { validateServers } from '@mcp-z/client';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport type { ServerConfig } from '../types.ts';\nimport { findConfigPath } from './find-config.ts';\n\n/**\n * Options for inline server configuration.\n */\nexport interface InlineConfigOptions {\n /** Server name (optional when inline config provided) */\n server?: string;\n /** Config file path (mutually exclusive with inline options) */\n config?: string;\n /** Stdio run command string (e.g., \"npx -y @echo/server\") */\n run?: string;\n /** HTTP server URL */\n url?: string;\n /** Full server config as JSON string */\n serverConfig?: string;\n}\n\n/**\n * Resolved server configuration.\n */\nexport interface ResolvedServerConfig {\n /** Server name for display purposes */\n serverName: string;\n /** The server configuration object */\n serverConfig: ServerConfig;\n /** Working directory for the server (cwd for inline, config dir for file) */\n configDir: string;\n /** Full servers config (for HTTP auth flow that needs full config) */\n fullConfig: ServersConfig;\n}\n\n/**\n * Resolve server configuration from CLI options.\n *\n * Supports three modes:\n * 1. Config file: --config path + server positional\n * 2. Inline stdio: --run \"npx server\"\n * 3. Inline HTTP: --url \"https://...\"\n * 4. Full JSON: --server '{\"command\":\"npx\",...}'\n *\n * @param opts - CLI options for config resolution\n * @returns Resolved server configuration\n * @throws Error if configuration is invalid\n */\nexport function resolveServerConfig(opts: InlineConfigOptions): ResolvedServerConfig {\n // Validate mutual exclusivity of inline options\n const inlineOptions = [opts.run, opts.url, opts.serverConfig].filter(Boolean);\n if (inlineOptions.length > 1) {\n throw new Error('Cannot use multiple inline config options. Use only one of: --run, --url, or --server');\n }\n\n const hasInlineConfig = inlineOptions.length > 0;\n\n // Validate mutual exclusivity with config file\n if (hasInlineConfig && opts.config) {\n throw new Error('Cannot use --config with inline config options (--run, --url, --server)');\n }\n\n // Handle inline configuration\n if (hasInlineConfig) {\n return resolveInlineConfig(opts);\n }\n\n // Handle config file-based configuration\n return resolveFileConfig(opts);\n}\n\n/**\n * Resolve inline server configuration.\n */\nfunction resolveInlineConfig(opts: InlineConfigOptions): ResolvedServerConfig {\n const serverName = opts.server || 'inline';\n const configDir = process.cwd();\n let serverConfig: ServerConfig;\n\n if (opts.run) {\n // Parse run string into command + args (simple helper, no schema validation needed)\n serverConfig = parseRunString(opts.run);\n } else if (opts.url) {\n // Create HTTP server config (simple helper, no schema validation needed)\n serverConfig = {\n type: 'http',\n url: opts.url,\n };\n } else if (opts.serverConfig) {\n // Parse full JSON config with schema validation\n serverConfig = parseServerConfigJson(opts.serverConfig, serverName);\n } else {\n throw new Error('No inline config provided');\n }\n\n // Create a minimal servers config for the resolved server\n const fullConfig: ServersConfig = {\n [serverName]: serverConfig,\n };\n\n return {\n serverName,\n serverConfig,\n configDir,\n fullConfig,\n };\n}\n\n/**\n * Resolve config file-based server configuration.\n */\nfunction resolveFileConfig(opts: InlineConfigOptions): ResolvedServerConfig {\n if (!opts.server) {\n throw new Error('Server name is required when using config file');\n }\n\n const cfgPath = findConfigPath(opts.config);\n const raw = JSON.parse(fs.readFileSync(cfgPath, 'utf8'));\n const servers: ServersConfig = raw.mcpServers ?? raw.servers ?? raw;\n\n const serverNames = Object.keys(servers || {});\n if (!serverNames.includes(opts.server)) {\n throw new Error(`Server '${opts.server}' not found in config\\n\\nAvailable servers: ${serverNames.join(', ')}`);\n }\n\n const serverConfig = servers[opts.server];\n if (!serverConfig) {\n throw new Error(`Server ${opts.server} not found in config`);\n }\n\n return {\n serverName: opts.server,\n serverConfig: serverConfig as ServerConfig,\n configDir: path.dirname(cfgPath),\n fullConfig: servers,\n };\n}\n\n/**\n * Parse a run string into a ServerConfigStdio.\n *\n * @example\n * parseRunString(\"npx -y @echo/server\")\n * // => { command: \"npx\", args: [\"-y\", \"@echo/server\"] }\n */\nfunction parseRunString(runStr: string): ServerConfig {\n const parts = runStr.trim().split(/\\s+/);\n if (parts.length === 0 || !parts[0]) {\n throw new Error('Run string cannot be empty');\n }\n\n return {\n command: parts[0],\n args: parts.slice(1),\n };\n}\n\n/**\n * Parse and validate a full server config JSON string against the MCP schema.\n *\n * @example\n * parseServerConfigJson('{\"command\":\"npx\",\"args\":[\"-y\",\"@echo/server\"]}')\n * parseServerConfigJson('{\"url\":\"https://example.com/mcp\",\"type\":\"http\"}')\n */\nfunction parseServerConfigJson(jsonStr: string, serverName: string): ServerConfig {\n let parsed: unknown;\n try {\n parsed = JSON.parse(jsonStr);\n } catch (error) {\n throw new Error(`Failed to parse server config JSON: ${error instanceof Error ? error.message : String(error)}`);\n }\n\n if (typeof parsed !== 'object' || parsed === null) {\n throw new Error('Server config must be a JSON object');\n }\n\n const config = parsed as McpServerEntry;\n\n // Validate: must have either 'command' (stdio) or 'url' (http)\n if (!config.command && !config.url) {\n throw new Error('Server config must have either \"command\" (for stdio) or \"url\" (for http)');\n }\n\n // Normalize: if url is present without explicit type, set type to 'http'\n if (config.url && !config.type) {\n config.type = 'http';\n }\n\n // Validate against the MCP servers schema\n const serversMap = { [serverName]: config };\n const validation = validateServers(serversMap);\n if (!validation.valid) {\n const errorDetails = validation.errors?.join('\\n ') || 'Unknown validation error';\n throw new Error(`Invalid server config:\\n ${errorDetails}`);\n }\n\n // Return as ServerConfig (compatible with McpServerEntry)\n return config as ServerConfig;\n}\n"],"names":["validateServers","fs","path","findConfigPath","resolveServerConfig","opts","inlineOptions","run","url","serverConfig","filter","Boolean","length","Error","hasInlineConfig","config","resolveInlineConfig","resolveFileConfig","serverName","server","configDir","process","cwd","parseRunString","type","parseServerConfigJson","fullConfig","raw","cfgPath","JSON","parse","readFileSync","servers","mcpServers","serverNames","Object","keys","includes","join","dirname","runStr","parts","trim","split","command","args","slice","jsonStr","parsed","error","message","String","serversMap","validation","valid","errorDetails","errors"],"mappings":"AAAA;;;;;CAKC,GAGD,SAASA,eAAe,QAAQ,gBAAgB;AAChD,YAAYC,QAAQ,KAAK;AACzB,YAAYC,UAAU,OAAO;AAE7B,SAASC,cAAc,QAAQ,mBAAmB;AAgClD;;;;;;;;;;;;CAYC,GACD,OAAO,SAASC,oBAAoBC,IAAyB;IAC3D,gDAAgD;IAChD,MAAMC,gBAAgB;QAACD,KAAKE,GAAG;QAAEF,KAAKG,GAAG;QAAEH,KAAKI,YAAY;KAAC,CAACC,MAAM,CAACC;IACrE,IAAIL,cAAcM,MAAM,GAAG,GAAG;QAC5B,MAAM,IAAIC,MAAM;IAClB;IAEA,MAAMC,kBAAkBR,cAAcM,MAAM,GAAG;IAE/C,+CAA+C;IAC/C,IAAIE,mBAAmBT,KAAKU,MAAM,EAAE;QAClC,MAAM,IAAIF,MAAM;IAClB;IAEA,8BAA8B;IAC9B,IAAIC,iBAAiB;QACnB,OAAOE,oBAAoBX;IAC7B;IAEA,yC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AAE;YACAD;QAArB,MAAME,eAAeF,EAAAA,qBAAAA,WAAWG,MAAM,cAAjBH,yCAAAA,mBAAmBf,IAAI,CAAC,YAAW;QACxD,MAAM,IAAIzB,MAAM,CAAC,0BAA0B,EAAE0C,cAAc;IAC7D;IAEA,0DAA0D;IAC1D,OAAOxC;AACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "module" }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface MCPConfiguration {
|
|
2
|
+
mcpServers: Record<string, ServerConfig>;
|
|
3
|
+
}
|
|
4
|
+
export interface ServerConfigStdio {
|
|
5
|
+
type?: 'stdio';
|
|
6
|
+
command: string;
|
|
7
|
+
args?: string[];
|
|
8
|
+
env?: Record<string, string>;
|
|
9
|
+
}
|
|
10
|
+
export interface ServerConfigHttp {
|
|
11
|
+
type: 'http';
|
|
12
|
+
url: string;
|
|
13
|
+
headers?: Record<string, string>;
|
|
14
|
+
start?: ServerConfigStdio;
|
|
15
|
+
}
|
|
16
|
+
export type ServerConfig = ServerConfigStdio | ServerConfigHttp;
|
|
17
|
+
export declare function isHttpServer(config: ServerConfig): config is ServerConfigHttp;
|
|
18
|
+
export declare function isStdioServer(config: ServerConfig): config is ServerConfigStdio;
|
|
19
|
+
export declare function hasStartBlock(config: ServerConfig): config is ServerConfigHttp & {
|
|
20
|
+
start: ServerConfigStdio;
|
|
21
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Type definitions for MCP config files
|
|
2
|
+
// Type guards
|
|
3
|
+
export function isHttpServer(config) {
|
|
4
|
+
return config.type === 'http';
|
|
5
|
+
}
|
|
6
|
+
export function isStdioServer(config) {
|
|
7
|
+
return !isHttpServer(config);
|
|
8
|
+
}
|
|
9
|
+
export function hasStartBlock(config) {
|
|
10
|
+
return isHttpServer(config) && config.start !== undefined;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/cli/src/types.ts"],"sourcesContent":["// Type definitions for MCP config files\n\nexport interface MCPConfiguration {\n mcpServers: Record<string, ServerConfig>;\n}\n\n// Stdio server: spawns with stdio transport\nexport interface ServerConfigStdio {\n type?: 'stdio'; // Optional: absence means stdio\n command: string;\n args?: string[]; // OPTIONAL per .mcp.json standard\n env?: Record<string, string>;\n}\n\n// HTTP server: connects to URL, optionally spawns the server locally\nexport interface ServerConfigHttp {\n type: 'http';\n url: string;\n headers?: Record<string, string>;\n start?: ServerConfigStdio; // Extension: reuse stdio config for spawning HTTP servers\n}\n\nexport type ServerConfig = ServerConfigStdio | ServerConfigHttp;\n\n// Type guards\nexport function isHttpServer(config: ServerConfig): config is ServerConfigHttp {\n return config.type === 'http';\n}\n\nexport function isStdioServer(config: ServerConfig): config is ServerConfigStdio {\n return !isHttpServer(config);\n}\n\nexport function hasStartBlock(config: ServerConfig): config is ServerConfigHttp & { start: ServerConfigStdio } {\n return isHttpServer(config) && config.start !== undefined;\n}\n"],"names":["isHttpServer","config","type","isStdioServer","hasStartBlock","start","undefined"],"mappings":"AAAA,wCAAwC;AAwBxC,cAAc;AACd,OAAO,SAASA,aAAaC,MAAoB;IAC/C,OAAOA,OAAOC,IAAI,KAAK;AACzB;AAEA,OAAO,SAASC,cAAcF,MAAoB;IAChD,OAAO,CAACD,aAAaC;AACvB;AAEA,OAAO,SAASG,cAAcH,MAAoB;IAChD,OAAOD,aAAaC,WAAWA,OAAOI,KAAK,KAAKC;AAClD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mcp-z/cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "CLI tool for managing MCP server clusters and testing workflows.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"mcp",
|
|
7
|
+
"model-context-protocol",
|
|
8
|
+
"mcp-server",
|
|
9
|
+
"mcp-client",
|
|
10
|
+
"server",
|
|
11
|
+
"client",
|
|
12
|
+
"cli",
|
|
13
|
+
"lib",
|
|
14
|
+
"token-storage",
|
|
15
|
+
"testing",
|
|
16
|
+
"integration-testing",
|
|
17
|
+
"development-tools",
|
|
18
|
+
"server-management",
|
|
19
|
+
"lifecycle",
|
|
20
|
+
"graceful-shutdown",
|
|
21
|
+
"test-utilities",
|
|
22
|
+
"workflow",
|
|
23
|
+
"ai",
|
|
24
|
+
"claude"
|
|
25
|
+
],
|
|
26
|
+
"homepage": "https://github.com/mcp-z/cli#readme",
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/mcp-z/cli/issues"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/mcp-z/cli.git"
|
|
33
|
+
},
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"author": "Kevin Malakoff <kmalakoff.info@gmail.com>",
|
|
36
|
+
"type": "module",
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"types": "./dist/esm/index.d.ts",
|
|
40
|
+
"import": "./dist/esm/index.js",
|
|
41
|
+
"require": "./dist/cjs/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./package.json": "./package.json"
|
|
44
|
+
},
|
|
45
|
+
"main": "./dist/cjs/index.js",
|
|
46
|
+
"module": "./dist/esm/index.js",
|
|
47
|
+
"types": "./dist/esm/index.d.ts",
|
|
48
|
+
"bin": {
|
|
49
|
+
"mcp-z": "./bin/cli.js",
|
|
50
|
+
"z": "./bin/cli.js"
|
|
51
|
+
},
|
|
52
|
+
"files": [
|
|
53
|
+
"dist",
|
|
54
|
+
"bin",
|
|
55
|
+
"schemas"
|
|
56
|
+
],
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "tsc -p . --noEmit && tsds build",
|
|
59
|
+
"format": "tsds format",
|
|
60
|
+
"prepublish:check": "ncp",
|
|
61
|
+
"prepublishOnly": "tsds validate",
|
|
62
|
+
"test": "npm run test:unit && npm run test:integration",
|
|
63
|
+
"test:engines": "nvu engines tsds test:node --no-timeouts",
|
|
64
|
+
"test:integration": "tsds test:node --no-timeouts 'test/integration/**/*.test.ts'",
|
|
65
|
+
"test:unit": "tsds test:node --no-timeouts 'test/unit/**/*.test.ts'",
|
|
66
|
+
"validate:server-json": "node --input-type=module -e \"import { execSync } from 'child_process'; import fs from 'fs'; import path from 'path'; import { validateSchema } from './src/lib/json-schema.ts'; const root = path.resolve(process.cwd(), '..'); const files = execSync('rg --files -g \\\"server.json\\\"', { cwd: root, encoding: 'utf8' }).trim().split('\\\\n').filter(Boolean); if (files.length === 0) { console.log('No server.json files found'); process.exit(0); } for (const file of files) { const data = JSON.parse(fs.readFileSync(path.join(root, file), 'utf8')); await validateSchema(data, file); console.log('OK ' + file); }\"",
|
|
67
|
+
"version": "tsds version"
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"@inquirer/checkbox": "^5.0.3",
|
|
71
|
+
"@inquirer/confirm": "^6.0.3",
|
|
72
|
+
"@inquirer/input": "^5.0.3",
|
|
73
|
+
"@inquirer/password": "^5.0.3",
|
|
74
|
+
"@inquirer/select": "^5.0.3",
|
|
75
|
+
"@mcp-z/client": "^1.0.0",
|
|
76
|
+
"ajv": "^8.0.0",
|
|
77
|
+
"ajv-formats": "^3.0.0",
|
|
78
|
+
"commander": "^14.0.2",
|
|
79
|
+
"module-root-sync": "^2.0.0"
|
|
80
|
+
},
|
|
81
|
+
"devDependencies": {
|
|
82
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
83
|
+
"@types/mocha": "^10.0.10",
|
|
84
|
+
"@types/node": "^25.0.2",
|
|
85
|
+
"express": "^5.0.0",
|
|
86
|
+
"get-port": "^7.1.0",
|
|
87
|
+
"node-version-use": "^2.1.6",
|
|
88
|
+
"ts-dev-stack": "^1.21.3",
|
|
89
|
+
"tsds-config": "^1.0.0",
|
|
90
|
+
"typescript": "^5.9.3",
|
|
91
|
+
"zod": "^4.0.0"
|
|
92
|
+
},
|
|
93
|
+
"engines": {
|
|
94
|
+
"node": ">=22"
|
|
95
|
+
},
|
|
96
|
+
"tsds": {
|
|
97
|
+
"source": "src/index.ts"
|
|
98
|
+
}
|
|
99
|
+
}
|