@bigbrain-work/mcp-connect 1.0.0 → 1.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 CHANGED
@@ -4,7 +4,13 @@
4
4
 
5
5
  ## 使用
6
6
 
7
- 先在石榴 AI 页面复制当前账户的 API Key,然后执行对应命令:
7
+ 先在石榴 AI 页面复制当前账户的 API Key。推荐直接运行智能一键配置,安装器会检测本机已有的 Codex、Claude Code 和 Cursor:
8
+
9
+ ```bash
10
+ npx -y @bigbrain-work/mcp-connect
11
+ ```
12
+
13
+ 也可以明确指定客户端:
8
14
 
9
15
  ```bash
10
16
  npx -y @bigbrain-work/mcp-connect --agent codex
@@ -12,6 +18,15 @@ npx -y @bigbrain-work/mcp-connect --agent claude
12
18
  npx -y @bigbrain-work/mcp-connect --agent cursor
13
19
  ```
14
20
 
21
+ 其他 Agent 也可以使用任意名称,例如:
22
+
23
+ ```bash
24
+ npx -y @bigbrain-work/mcp-connect --agent openclaw
25
+ npx -y @bigbrain-work/mcp-connect --agent workbuddy
26
+ ```
27
+
28
+ 对于尚未内置配置适配器的 Agent,安装器不会修改未知配置文件,而是输出石榴 AI 的通用 HTTP MCP 地址和认证方式。
29
+
15
30
  安装器会隐藏输入 API Key。配置完成后,重启对应客户端并检查连接:
16
31
 
17
32
  ```bash
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bigbrain-work/mcp-connect",
3
- "version": "1.0.0",
4
- "description": "石榴 AI MCP 一键配置工具,支持 Codex、Claude Code 和 Cursor。",
3
+ "version": "1.1.0",
4
+ "description": "石榴 AI MCP 智能配置工具,支持自动检测与通用 HTTP MCP 接入指引。",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "mcp-connect": "bin/mcp-connect.js"
package/src/arguments.js CHANGED
@@ -1,7 +1,5 @@
1
1
  import { parseArgs } from 'node:util'
2
2
 
3
- import { SUPPORTED_AGENTS } from './constants.js'
4
-
5
3
  export function parseCliArguments(args) {
6
4
  const parsed = parseArgs({
7
5
  args,
@@ -38,11 +36,8 @@ export function parseCliArguments(args) {
38
36
  }
39
37
 
40
38
  const agent = parsed.values.agent?.toLowerCase()
41
- if (agent && !SUPPORTED_AGENTS.includes(agent)) {
42
- throw new Error(`不支持的客户端:${agent}。可选值:${SUPPORTED_AGENTS.join('')}`)
43
- }
44
- if (command === 'install' && !agent && !parsed.values.help && !parsed.values.version) {
45
- throw new Error('请通过 --agent 指定客户端:codex、claude 或 cursor')
39
+ if (agent && !/^[a-z0-9][a-z0-9_-]{0,63}$/u.test(agent)) {
40
+ throw new Error('客户端名称只能包含小写字母、数字、下划线和连字符')
46
41
  }
47
42
 
48
43
  return {
package/src/cli.js CHANGED
@@ -3,11 +3,13 @@ import path from 'node:path'
3
3
 
4
4
  import { parseCliArguments } from './arguments.js'
5
5
  import { configureAgent } from './configurators.js'
6
+ import { detectInstalledAgents } from './detection.js'
6
7
  import {
7
8
  API_KEY_ENV,
8
9
  MCP_URL,
9
10
  PACKAGE_NAME,
10
11
  PACKAGE_VERSION,
12
+ SERVER_NAME,
11
13
  SUPPORTED_AGENTS,
12
14
  } from './constants.js'
13
15
  import { persistApiKey, resolveApiKey } from './credentials.js'
@@ -17,7 +19,8 @@ function printHelp() {
17
19
  console.log(`${PACKAGE_NAME} ${PACKAGE_VERSION}
18
20
 
19
21
  用法:
20
- mcp-connect --agent <${SUPPORTED_AGENTS.join('|')}>
22
+ mcp-connect
23
+ mcp-connect --agent <name>
21
24
  mcp-connect status
22
25
 
23
26
  选项:
@@ -29,7 +32,21 @@ function printHelp() {
29
32
 
30
33
  认证:
31
34
  安装器优先读取 ${API_KEY_ENV};未设置时会隐藏提示输入。
32
- 真实 API Key 不会写入生成的 MCP 配置。`)
35
+ 真实 API Key 不会写入生成的 MCP 配置。
36
+
37
+ 智能配置:
38
+ 不指定 --agent 时,自动检测并配置已安装的 ${SUPPORTED_AGENTS.join('、')}。
39
+ 其他 Agent 名称也可传入;未内置适配器时会输出通用 HTTP MCP 配置。`)
40
+ }
41
+
42
+ function printGenericInstructions(agent, { dryRun = false } = {}) {
43
+ console.log(`暂未内置 ${agent} 的自动配置适配器,请在该 Agent 中添加远程 HTTP MCP:
44
+
45
+ 名称:${SERVER_NAME}
46
+ 地址:${MCP_URL}
47
+ 认证头:Authorization: Bearer <你的石榴 AI API Key>
48
+
49
+ ${dryRun ? `演练模式未保存 API Key;正式运行时会安全保存到 ${API_KEY_ENV}。` : `API Key 已安全保存到 ${API_KEY_ENV}。`}请勿将真实 API Key 写入项目代码或提交到 Git。`)
33
50
  }
34
51
 
35
52
  export async function runCli(argv = process.argv.slice(2)) {
@@ -57,12 +74,28 @@ export async function runCli(argv = process.argv.slice(2)) {
57
74
  dryRun: options.dryRun,
58
75
  home,
59
76
  })
60
- await configureAgent(options.agent, {
61
- dryRun: options.dryRun,
62
- home,
63
- })
77
+ const requestedAgent = options.agent === 'auto' ? undefined : options.agent
78
+ if (requestedAgent && !SUPPORTED_AGENTS.includes(requestedAgent)) {
79
+ printGenericInstructions(requestedAgent, { dryRun: options.dryRun })
80
+ return
81
+ }
82
+
83
+ const agents = requestedAgent
84
+ ? [requestedAgent]
85
+ : await detectInstalledAgents({ home })
86
+ if (agents.length === 0) {
87
+ printGenericInstructions('当前客户端', { dryRun: options.dryRun })
88
+ return
89
+ }
90
+
91
+ for (const agent of agents) {
92
+ await configureAgent(agent, {
93
+ dryRun: options.dryRun,
94
+ home,
95
+ })
96
+ }
64
97
 
65
98
  console.log(options.dryRun
66
- ? `检查完成:将为 ${options.agent} 配置 ${MCP_URL},未写入任何文件。`
67
- : `配置完成:${options.agent} 已接入石榴 AI MCP。请重启客户端后运行 ${PACKAGE_NAME} status 检查连接。`)
99
+ ? `检查完成:将为 ${agents.join('、')} 配置 ${MCP_URL},未写入任何文件。`
100
+ : `配置完成:${agents.join('、')} 已接入石榴 AI MCP。请重启客户端后运行 ${PACKAGE_NAME} status 检查连接。`)
68
101
  }
package/src/constants.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export const PACKAGE_NAME = '@bigbrain-work/mcp-connect'
2
- export const PACKAGE_VERSION = '1.0.0'
2
+ export const PACKAGE_VERSION = '1.1.0'
3
3
  export const SERVER_NAME = 'shiliu_mcp'
4
4
  export const MCP_URL = 'https://api.bigbrain.work/shiliu/mcp'
5
5
  export const API_KEY_ENV = 'SHILIU_AI_API_KEY'
@@ -0,0 +1,41 @@
1
+ import { access } from 'node:fs/promises'
2
+ import path from 'node:path'
3
+ import { spawnSync } from 'node:child_process'
4
+
5
+
6
+ export function commandExists(command, spawn = spawnSync) {
7
+ const result = spawn(command, ['--version'], {
8
+ encoding: 'utf8',
9
+ windowsHide: true,
10
+ shell: false,
11
+ timeout: 5000,
12
+ })
13
+ return !result.error && result.status === 0
14
+ }
15
+
16
+ async function pathExists(targetPath) {
17
+ try {
18
+ await access(targetPath)
19
+ return true
20
+ } catch {
21
+ return false
22
+ }
23
+ }
24
+
25
+ export async function detectInstalledAgents({
26
+ home,
27
+ hasCommand = commandExists,
28
+ exists = pathExists,
29
+ } = {}) {
30
+ const agents = []
31
+ if (hasCommand('codex')) {
32
+ agents.push('codex')
33
+ }
34
+ if (hasCommand('claude')) {
35
+ agents.push('claude')
36
+ }
37
+ if (hasCommand('cursor') || await exists(path.join(home, '.cursor'))) {
38
+ agents.push('cursor')
39
+ }
40
+ return agents
41
+ }