You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
4.4 KiB
83 lines
4.4 KiB
'use strict'; |
|
// Реестр MCP-приложений ArtCraft: discovery бинарников и сборка спецификаций. |
|
const fs = require('fs'); |
|
const path = require('path'); |
|
|
|
// Явный список: имя инструмента -> папка, бинарь, аргументы. |
|
// Имя обязано быть [a-z]+ — на него завязан regex в tools.js (^[a-z]+_mcp_(tools|call)$). |
|
const DEFAULT_APPS = { |
|
vectorcraft: { dir: 'VectorCraft', bin: 'vectorcraft-cli.exe', args: ['mcp'] }, |
|
photocraft: { dir: 'PhotoCraft', bin: 'photocraft-cli.exe', args: ['mcp'] }, |
|
figcraft: { dir: 'FigCraft', bin: 'figcraft-cli.exe', args: ['mcp'] }, |
|
designcraft: { dir: 'DesignCraft', bin: 'designcraft-cli.exe', args: ['mcp'] }, |
|
deckcraft: { dir: 'DeckCraft', bin: 'deckcraft-cli.exe', args: ['mcp'] }, |
|
cadcraft: { dir: 'CADCraft', bin: 'cadcraft-cli.exe', args: ['mcp'] }, |
|
craftanything: { dir: 'Craft Anything', bin: 'craft-anything-cli.exe', args: ['mcp'] }, |
|
effectcraft: { dir: 'EffectCraft', bin: 'effectcraft-cli.exe', args: ['mcp'] }, |
|
filmcraft: { dir: 'FilmCraft', bin: 'filmcraft-cli.exe', args: ['mcp'] }, |
|
gridcraft: { dir: 'GridCraft', bin: 'gridcraft-cli.exe', args: ['mcp'] }, |
|
lightcraft: { dir: 'LightCraft', bin: 'lightcraft-cli.exe', args: ['mcp'] }, |
|
materialcraft: { dir: 'MaterialCraft', bin: 'materialcraft-cli.exe', args: ['mcp'] }, |
|
pdfcraft: { dir: 'PdfCraft', bin: 'pdfcraft-cli.exe', args: ['mcp'] }, |
|
solidcraft: { dir: 'SolidCraft', bin: 'solidcraft-cli.exe', args: ['mcp'] }, |
|
soundcraft: { dir: 'SoundCraft', bin: 'soundcraft-cli.exe', args: ['mcp'] }, |
|
texturecraft: { dir: 'TextureCraft', bin: 'texturecraft-cli.exe', args: ['mcp'] }, |
|
wordcraft: { dir: 'WordCraft', bin: 'wordcraft-cli.exe', args: ['mcp'] }, |
|
}; |
|
|
|
function resolveRoot(config) { |
|
const c = config && config.mcpServers && config.mcpServers.artcraft; |
|
return (c && c.root) || process.env.ARTCRAFT_ROOT || 'V:\\artcraft'; |
|
} |
|
|
|
function resolveDisabled(config) { |
|
const c = config && config.mcpServers && config.mcpServers.artcraft; |
|
const list = (c && c.disabled) || []; |
|
return Array.isArray(list) ? list.map(String) : []; |
|
} |
|
|
|
function discover(root, spec) { |
|
const full = path.join(root, spec.dir, spec.bin); |
|
try { return fs.existsSync(full) ? full : null; } catch { return null; } |
|
} |
|
|
|
function toolNameFromDir(dirName) { |
|
return String(dirName).toLowerCase().replace(/[^a-z]/g, ''); |
|
} |
|
|
|
// Автообнаружение: любая папка в root с единственным *-cli.exe, которой нет в списке. |
|
// Нужно, чтобы новая установка ArtCraft подхватывалась без правки кода. |
|
function autodiscover(root, known) { |
|
const found = {}; |
|
let entries = []; |
|
try { entries = fs.readdirSync(root, { withFileTypes: true }); } catch { return found; } |
|
for (const it of entries) { |
|
if (!it.isDirectory()) continue; |
|
const dir = path.join(root, it.name); |
|
let exes = []; |
|
try { exes = fs.readdirSync(dir).filter(n => /-cli\.exe$/i.test(n)); } catch { continue; } |
|
if (exes.length !== 1) continue; |
|
const bin = path.join(dir, exes[0]); |
|
if (Object.values(known).some(s => path.join(root, s.dir, s.bin).toLowerCase() === bin.toLowerCase())) continue; |
|
const name = toolNameFromDir(it.name); |
|
if (!name || known[name] || found[name]) continue; |
|
found[name] = { dir: it.name, bin: exes[0], args: ['mcp'], auto: true }; |
|
} |
|
return found; |
|
} |
|
|
|
function buildSpecs(config) { |
|
const root = resolveRoot(config); |
|
const disabled = resolveDisabled(config); |
|
const known = { ...DEFAULT_APPS, ...autodiscover(root, DEFAULT_APPS) }; |
|
const out = {}; |
|
for (const [name, spec] of Object.entries(known)) { |
|
if (disabled.includes(name)) { out[name] = { name, enabled: false, reason: 'disabled in config' }; continue; } |
|
const bin = discover(root, spec); |
|
if (!bin) { out[name] = { name, enabled: false, reason: 'binary not found: ' + path.join(root, spec.dir, spec.bin) }; continue; } |
|
out[name] = { name, enabled: true, bin, args: spec.args, cwd: path.dirname(bin), auto: !!spec.auto }; |
|
} |
|
return { root, apps: out }; |
|
} |
|
|
|
module.exports = { DEFAULT_APPS, resolveRoot, resolveDisabled, buildSpecs, toolNameFromDir };
|
|
|