shizai-agent-mcp 0.1.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 ADDED
@@ -0,0 +1,34 @@
1
+ # shizai-agent-mcp
2
+
3
+ 实在 Agent 本地 MCP 的 npm/npx 安装器。npm 包只负责下载 GitHub Release 中的编译版 MCP,不包含项目源码。
4
+
5
+ ## 使用
6
+
7
+ ```powershell
8
+ npx -y shizai-agent-mcp install
9
+ npx -y shizai-agent-mcp register codex
10
+ ```
11
+
12
+ 也可以注册 Cursor 或 Claude Desktop:
13
+
14
+ ```powershell
15
+ npx -y shizai-agent-mcp register cursor
16
+ npx -y shizai-agent-mcp register claude
17
+ ```
18
+
19
+ 常用命令:
20
+
21
+ ```powershell
22
+ npx -y shizai-agent-mcp status
23
+ npx -y shizai-agent-mcp path
24
+ npx -y shizai-agent-mcp uninstall
25
+ ```
26
+
27
+ 默认下载 `v0.5.0` 的 Windows x64 资产:
28
+ `shizai-agent-v0.5.0-windows-x64.zip`。
29
+
30
+ 发布 Release 时需要同时上传同名 `.sha256` 文件。测试企业内网镜像时,可设置
31
+ `SHIZAI_AGENT_RELEASE_BASE_URL`;测试其他版本可设置 `SHIZAI_AGENT_VERSION`。
32
+
33
+ 本地设计器需要正在运行且已登录。MCP 是本地 stdio 服务,Codex 显示 `Auth: Unsupported`
34
+ 属于正常状态,实在 Agent 的登录会话由桌面设计器提供。
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env node
2
+
3
+ /* Lightweight distribution layer. The MCP binary remains in GitHub Releases. */
4
+ const fs = require('node:fs');
5
+ const path = require('node:path');
6
+ const os = require('node:os');
7
+ const crypto = require('node:crypto');
8
+ const { execFileSync, spawn } = require('node:child_process');
9
+
10
+ const SERVER = 'shizai-agent';
11
+ const REPO = process.env.SHIZAI_AGENT_REPO || 'yimoxzy/shizai-agent';
12
+ const DEFAULT_VERSION = process.env.SHIZAI_AGENT_VERSION || '0.5.0';
13
+ const installRoot = process.env.SHIZAI_AGENT_HOME || path.join(
14
+ process.env.LOCALAPPDATA || path.join(os.homedir(), '.local'), 'Programs', 'ShizaiAgent'
15
+ );
16
+
17
+ function fail(message) { console.error(`shizai-agent-mcp: ${message}`); process.exitCode = 1; }
18
+ function json(value) { console.log(JSON.stringify(value, null, 2)); }
19
+ function help() {
20
+ console.log(`Shizai Agent MCP installer\n\nUsage:\n shizai-agent-mcp install [--version VERSION]\n shizai-agent-mcp register <codex|cursor|claude>\n shizai-agent-mcp status\n shizai-agent-mcp path\n shizai-agent-mcp uninstall\n\nEnvironment:\n SHIZAI_AGENT_VERSION Release version (default: ${DEFAULT_VERSION})\n SHIZAI_AGENT_HOME Installation directory\n SHIZAI_AGENT_REPO GitHub repository owner/name\n SHIZAI_AGENT_RELEASE_BASE_URL Override release asset base URL\n`);
21
+ }
22
+ function binaryPath() { return path.join(installRoot, 'shizai-agent-mcp.exe'); }
23
+ function psQuote(value) { return `'${String(value).replaceAll("'", "''")}'`; }
24
+ function runPowerShell(script, args = []) {
25
+ return execFileSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-Command', script, ...args], { encoding: 'utf8' });
26
+ }
27
+ function assetName(version) {
28
+ if (process.platform !== 'win32' || process.arch !== 'x64') {
29
+ throw new Error(`当前 npm 安装器暂时只提供 Windows x64,检测到 ${process.platform}/${process.arch}`);
30
+ }
31
+ return process.env.SHIZAI_AGENT_ASSET_NAME || `shizai-agent-v${version}-windows-x64.zip`;
32
+ }
33
+ function releaseUrl(version, asset) {
34
+ const base = process.env.SHIZAI_AGENT_RELEASE_BASE_URL || `https://github.com/${REPO}/releases/download/v${version}`;
35
+ return `${base.replace(/\/$/, '')}/${asset}`;
36
+ }
37
+ function verifySha256(file, expected) {
38
+ const actual = crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex').toLowerCase();
39
+ if (actual !== expected.toLowerCase()) throw new Error(`SHA256 校验失败:期望 ${expected},实际 ${actual}`);
40
+ }
41
+ function download(url, destination) {
42
+ const script = `Invoke-WebRequest -UseBasicParsing -Uri ${psQuote(url)} -OutFile ${psQuote(destination)}`;
43
+ runPowerShell(script);
44
+ }
45
+ function install(version) {
46
+ const asset = assetName(version);
47
+ const url = releaseUrl(version, asset);
48
+ const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'shizai-agent-'));
49
+ const archive = path.join(temp, asset);
50
+ const checksum = path.join(temp, `${asset}.sha256`);
51
+ try {
52
+ console.log(`下载 ${url}`);
53
+ download(url, archive);
54
+ try {
55
+ download(`${url}.sha256`, checksum);
56
+ const text = fs.readFileSync(checksum, 'utf8');
57
+ const expected = (text.match(/[a-f0-9]{64}/i) || [])[0];
58
+ if (expected) verifySha256(archive, expected);
59
+ } catch (error) {
60
+ if (process.env.SHIZAI_AGENT_REQUIRE_CHECKSUM === '1') throw error;
61
+ console.warn('未找到校验文件,继续解压;发布正式版本时建议上传 .sha256。');
62
+ }
63
+ fs.mkdirSync(installRoot, { recursive: true });
64
+ runPowerShell(`if (Test-Path -LiteralPath ${psQuote(installRoot)}) { Remove-Item -LiteralPath ${psQuote(installRoot)} -Recurse -Force }; New-Item -ItemType Directory -Force -Path ${psQuote(installRoot)} | Out-Null; Expand-Archive -LiteralPath ${psQuote(archive)} -DestinationPath ${psQuote(installRoot)} -Force; $nested = Get-ChildItem -LiteralPath ${psQuote(installRoot)} -Directory | Where-Object { Test-Path -LiteralPath (Join-Path $_.FullName 'shizai-agent-mcp.exe') } | Select-Object -First 1; if ($nested) { Get-ChildItem -LiteralPath $nested.FullName -Force | Move-Item -Destination ${psQuote(installRoot)} -Force }`);
65
+ if (!fs.existsSync(binaryPath())) throw new Error(`安装包中未找到 ${binaryPath()}`);
66
+ fs.writeFileSync(path.join(installRoot, 'version.json'), JSON.stringify({ version, asset, installedAt: new Date().toISOString() }, null, 2));
67
+ json({ installed: true, version, directory: installRoot, command: binaryPath() });
68
+ } finally {
69
+ fs.rmSync(temp, { recursive: true, force: true });
70
+ }
71
+ }
72
+ function replaceTomlSection(content, section, replacement) {
73
+ const escaped = section.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
74
+ const pattern = new RegExp(`(?ms)^\\[${escaped}\\]\\r?\\n.*?(?=^\\[|$)`);
75
+ const next = content.replace(pattern, '').trimEnd();
76
+ return `${next}${next ? '\\r\\n\\r\\n' : ''}${replacement.trim()}\\r\\n`;
77
+ }
78
+ function registerCodex() {
79
+ const config = process.env.SHIZAI_CODEX_CONFIG || path.join(os.homedir(), '.codex', 'config.toml');
80
+ fs.mkdirSync(path.dirname(config), { recursive: true });
81
+ const old = fs.existsSync(config) ? fs.readFileSync(config, 'utf8') : '';
82
+ if (old) fs.copyFileSync(config, `${config}.shizai-agent.bak`);
83
+ const section = `[mcp_servers.${SERVER}]\ncommand = ${psQuote(binaryPath())}\nargs = []\nstartup_timeout_sec = 30\ntool_timeout_sec = 120`;
84
+ fs.writeFileSync(config, replaceTomlSection(old, `mcp_servers.${SERVER}`, section), 'utf8');
85
+ json({ registered: true, client: 'codex', config, command: binaryPath() });
86
+ }
87
+ function registerJsonClient(client) {
88
+ const locations = {
89
+ cursor: process.env.SHIZAI_CURSOR_CONFIG || path.join(process.env.APPDATA || path.join(os.homedir(), 'AppData', 'Roaming'), 'Cursor', 'User', 'globalStorage', 'mcp.json'),
90
+ claude: process.env.SHIZAI_CLAUDE_CONFIG || path.join(process.env.APPDATA || path.join(os.homedir(), 'AppData', 'Roaming'), 'Claude', 'claude_desktop_config.json')
91
+ };
92
+ const file = locations[client];
93
+ if (!file) throw new Error(`未知客户端:${client}`);
94
+ fs.mkdirSync(path.dirname(file), { recursive: true });
95
+ const data = fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, 'utf8')) : {};
96
+ data.mcpServers = data.mcpServers || {};
97
+ data.mcpServers[SERVER] = { command: binaryPath(), args: [] };
98
+ fs.writeFileSync(file, `${JSON.stringify(data, null, 2)}\n`, 'utf8');
99
+ json({ registered: true, client, config: file, command: binaryPath() });
100
+ }
101
+ function launch() {
102
+ if (!fs.existsSync(binaryPath())) install(DEFAULT_VERSION);
103
+ const child = spawn(binaryPath(), process.argv.slice(2), { stdio: 'inherit', windowsHide: true });
104
+ child.on('exit', code => { process.exitCode = code ?? 0; });
105
+ }
106
+ function main() {
107
+ const [command, target, ...rest] = process.argv.slice(2);
108
+ if (!command) return launch();
109
+ if (command === '--help' || command === '-h') return help();
110
+ if (command === 'install') {
111
+ const index = rest.indexOf('--version');
112
+ return install(index >= 0 ? rest[index + 1] : (target && !target.startsWith('-') ? target : DEFAULT_VERSION));
113
+ }
114
+ if (command === 'register') {
115
+ if (!fs.existsSync(binaryPath())) throw new Error('尚未安装,请先运行 install');
116
+ if (target === 'codex') return registerCodex();
117
+ if (target === 'cursor' || target === 'claude') return registerJsonClient(target);
118
+ throw new Error('请指定 codex、cursor 或 claude');
119
+ }
120
+ if (command === 'status') return json({ installed: fs.existsSync(binaryPath()), directory: installRoot, command: binaryPath(), versionFile: path.join(installRoot, 'version.json') });
121
+ if (command === 'path') return console.log(binaryPath());
122
+ if (command === 'uninstall') { if (fs.existsSync(installRoot)) fs.rmSync(installRoot, { recursive: true, force: true }); return json({ uninstalled: true, directory: installRoot }); }
123
+ throw new Error(`未知命令:${command}`);
124
+ }
125
+ try { main(); } catch (error) { fail(error.message); }
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "shizai-agent-mcp",
3
+ "version": "0.1.0",
4
+ "description": "Installer and launcher for the Shizai Agent local MCP server",
5
+ "bin": {
6
+ "shizai-agent-mcp": "bin/shizai-agent-mcp.js"
7
+ },
8
+ "engines": {
9
+ "node": ">=18"
10
+ },
11
+ "files": [
12
+ "bin",
13
+ "README.md"
14
+ ],
15
+ "keywords": ["mcp", "shizai-agent", "codex", "cursor", "claude"],
16
+ "license": "MIT"
17
+ }