Skip to content

๐Ÿคฏ LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

โœจ feat(cli): add `lh mcp` alias and document connectors in the platform skill (#22626)

Lobehub Coder24e00d8cd80d
diff --git a/apps/cli/src/commands/connector.test.ts b/apps/cli/src/commands/connector.test.ts
index b7c81af71b4..1fd82d9900b 100644
--- a/apps/cli/src/commands/connector.test.ts
+++ b/apps/cli/src/commands/connector.test.ts
@@ -325,6 +325,25 @@ describe('connector command', () => {
});
});
+ describe('mcp alias', () => {
+ it('routes `mcp` to the connector command', async () => {
+ const program = createProgram();
+ const connector = program.commands.find((c) => c.name() === 'connector');
+
+ expect(connector?.aliases()).toContain('mcp');
+
+ mockTrpcClient.connector.list.query.mockResolvedValue([
+ { id: ID, identifier: 'deepwiki', tools: [{}] },
+ ]);
+ await program.parseAsync(['node', 'test', 'mcp', 'list', '--json', 'identifier,toolCount']);
+
+ expect(mockTrpcClient.connector.list.query).toHaveBeenCalledTimes(1);
+ expect(consoleSpy).toHaveBeenCalledWith(
+ JSON.stringify([{ identifier: 'deepwiki', toolCount: 1 }], null, 2),
+ );
+ });
+ });
+
describe('add', () => {
beforeEach(() => {
mockTrpcClient.connector.list.query.mockResolvedValue([]);
@@ -545,6 +564,12 @@ describe('connector command', () => {
expect(mockTrpcClient.connector.startOAuth.mutate).toHaveBeenCalledWith({ id: ID });
expect(mockTrpcClient.connector.syncTools.mutate).not.toHaveBeenCalled();
expect(consoleSpy).toHaveBeenCalledWith('https://auth.example.com/authorize?state=s');
+ // The OAuth callback syncs tools itself; refresh is only the fallback.
+ const output = consoleSpy.mock.calls.map((c: unknown[]) => String(c[0])).join('\n');
+ expect(output).toContain(
+ 'Tools sync automatically after authorization. Then check lh connector list',
+ );
+ expect(output).not.toContain('After authorizing, run');
});
it('refuses to overwrite an existing identifier without --force', async () => {
diff --git a/apps/cli/src/commands/connector.ts b/apps/cli/src/commands/connector.ts
index 3f4572c414b..edcb0c2f581 100644
--- a/apps/cli/src/commands/connector.ts
+++ b/apps/cli/src/commands/connector.ts
@@ -119,7 +119,9 @@ export function buildCreateInput(options: ConnectorAddOptions): {
throw new Error('--token is only valid with --auth bearer.');
}
if (options.stdioCmd && authType !== 'none') {
- throw new Error('stdio connectors do not support --auth; pass secrets via the command.');
+ throw new Error(
+ 'stdio connectors do not support --auth. Their command, args and env are stored in plain text, so do not put secrets in them.',
+ );
}
if (options.stdioCmd && options.header?.length) {
throw new Error('--header is only valid for HTTP connectors (--url).');
@@ -353,6 +355,7 @@ function fail(error: unknown, note?: string): never {
export function registerConnectorCommand(program: Command) {
const connector = program
.command('connector')
+ .alias('mcp')
.description('Manage MCP connectors (user connectors and their synced tools)');
// โ”€โ”€ list โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
@@ -467,7 +470,7 @@ export function registerConnectorCommand(program: Command) {
console.log(authorizationUrl);
console.log(
pc.dim(
- `After authorizing, run: lh connector refresh ${input.identifier} to fetch tools.`,
+ `Tools sync automatically after authorization. Then check lh connector list: if ${input.identifier} is not connected or has 0 tools, run: lh connector refresh ${input.identifier}`,
),
);
return;
diff --git a/packages/builtin-skills/src/lobehub/content.ts b/packages/builtin-skills/src/lobehub/content.ts
index c5c1253fd3e..aa0f027bef0 100644
--- a/packages/builtin-skills/src/lobehub/content.ts
+++ b/packages/builtin-skills/src/lobehub/content.ts
@@ -64,6 +64,7 @@ run commands.
| \`lh skill\` | Skill management (install, create, manage) | \`references/skill\` |
| \`lh model\` | AI model management | \`references/model\` |
| \`lh provider\` | AI provider management | \`references/provider\` |
+| \`lh connector\` / \`lh mcp\` | MCP connectors: add an MCP server (URL or stdio), sync its tools, refresh, remove | \`references/connector\` |
| \`lh legacy-plugin\` | Legacy 1.0 plugin management | \`references/plugin\` |
| \`lh bot\` | Bot integration management (Discord, Slack, Telegram, etc.) | \`references/bot\` |
| \`lh widget\` / \`lh dashboard\` | Monitoring widgets (sandboxed scripts) and the dashboards they sit on | \`references/dashboard\` |
diff --git a/packages/builtin-skills/src/lobehub/index.test.ts b/packages/builtin-skills/src/lobehub/index.test.ts
index 98eb24ea0ff..0623b28824b 100644
--- a/packages/builtin-skills/src/lobehub/index.test.ts
+++ b/packages/builtin-skills/src/lobehub/index.test.ts
@@ -18,6 +18,11 @@ describe('LobeHubSkill', () => {
}
});
+ it('activates for MCP connector requests and documents them', () => {
+ expect(LobeHubSkill.description).toContain('MCP servers / connectors');
+ expect(LobeHubSkill.content).toContain('references/connector');
+ });
+
it('documents workspace scope in the guide', () => {
expect(LobeHubSkill.content).toContain('`lh workspace`');
expect(LobeHubSkill.content).toContain('references/workspace');
diff --git a/packages/builtin-skills/src/lobehub/index.ts b/packages/builtin-skills/src/lobehub/index.ts
index a77e1f0090f..52e4a6e6989 100644
--- a/packages/builtin-skills/src/lobehub/index.ts
+++ b/packages/builtin-skills/src/lobehub/index.ts
@@ -15,6 +15,7 @@ import botSlack from './references/bot-slack';
import botTelegram from './references/bot-telegram';
import botWechat from './references/bot-wechat';
import config from './references/config';
+import connector from './references/connector';
import dashboard from './references/dashboard';
import doc from './references/doc';
import eval_ from './references/eval';
@@ -52,6 +53,7 @@ export const LobeHubSkill: BuiltinSkill = {
'references/bot/telegram': botTelegram,
'references/bot/wechat': botWechat,
'references/config': config,
+ 'references/connector': connector,
'references/dashboard': dashboard,
'references/doc': doc,
'references/eval': eval_,
diff --git a/packages/builtin-skills/src/lobehub/manifest.ts b/packages/builtin-skills/src/lobehub/manifest.ts
index f6840bb932b..dcc22c42e6d 100644
--- a/packages/builtin-skills/src/lobehub/manifest.ts
+++ b/packages/builtin-skills/src/lobehub/manifest.ts
@@ -9,7 +9,7 @@ const LOBEHUB_AVATAR =
export const LobeHubManifest: BuiltinSkillManifest = {
avatar: LOBEHUB_AVATAR,
description:
- "Read and change LobeHub platform data through the `lh` CLI, including this agent's own configuration. ACTIVATE when the user wants to: (1) change this agent โ€” system prompt / persona, tools / plugins / skills, model or provider, knowledge bases or files, opening message, or topic title; (2) work with any platform resource โ€” agents, topics, messages, memory, documents, knowledge bases, files, search, content generation, models / providers / plugins, evals, usage stats; (3) connect a chat-platform bot โ€” Discord, Telegram, Slack, Feishu (้ฃžไนฆ), Lark, QQ, WeChat (ๅพฎไฟก), e.g. 'ๆŽฅๅ…ฅ้ฃžไนฆ', 'connect my Slack'; (4) read another conversation โ€” the message contains a topic id (`tpc_โ€ฆ`) or a `<refer_topic>` tag. Without activation you cannot read or change platform data; you can only describe what you would do.",
+ "Read and change LobeHub platform data through the `lh` CLI, including this agent's own configuration. ACTIVATE when the user wants to: (1) change this agent โ€” system prompt / persona, tools / plugins / skills, model or provider, knowledge bases or files, opening message, or topic title; (2) work with any platform resource โ€” agents, topics, messages, memory, documents, knowledge bases, files, search, content generation, models / providers / plugins, MCP servers / connectors (add, list, refresh or remove an MCP server, `lh mcp`), evals, usage stats; (3) connect a chat-platform bot โ€” Discord, Telegram, Slack, Feishu (้ฃžไนฆ), Lark, QQ, WeChat (ๅพฎไฟก), e.g. 'ๆŽฅๅ…ฅ้ฃžไนฆ', 'connect my Slack'; (4) read another conversation โ€” the message contains a topic id (`tpc_โ€ฆ`) or a `<refer_topic>` tag. Without activation you cannot read or change platform data; you can only describe what you would do.",
identifier: LobeHubIdentifier,
name: 'lobehub',
source: 'builtin',
diff --git a/packages/builtin-skills/src/lobehub/references/connector.ts b/packages/builtin-skills/src/lobehub/references/connector.ts
new file mode 100644
index 00000000000..defe6d176f8
--- /dev/null
+++ b/packages/builtin-skills/src/lobehub/references/connector.ts
@@ -0,0 +1,48 @@
+const content = `# lh connector (alias: lh mcp) - MCP Connector Management
+
+Add and manage MCP servers as connectors. Each connector stores its server endpoint and credentials, and its tool list is synced so agents can call those tools. \`lh mcp\` is an alias: \`lh mcp list\` and \`lh connector list\` run the same command.
+
+## Subcommands
+
+- \`lh connector list [--json [fields]]\` - List connectors with id, identifier, source, status and tool count
+- \`lh connector add --url <url> [options]\` - Add a remote (streamable HTTP / SSE) MCP server and sync its tools
+- \`lh connector add --stdio-cmd <command> [--stdio-arg <arg>]...\` - Add a stdio MCP server launched on this machine
+- \`lh connector refresh <idOrIdentifier>\` (alias \`sync\`) - Refresh OAuth tokens and re-fetch the tool list
+- \`lh connector remove <idOrIdentifier> [--yes]\` - Remove a connector
+
+\`<idOrIdentifier>\` accepts the connector uuid or its identifier; when several connectors share an identifier, pass the uuid.
+
+## add options
+
+- \`--url <url>\` or \`--stdio-cmd <command>\` - Transport; pass exactly one
+- \`--stdio-arg <arg>\` - stdio argument, repeatable and kept in order; write an argument that starts with \`-\` as \`--stdio-arg=-y\`
+- \`--name <name>\` - Display name (defaults to the identifier)
+- \`--identifier <id>\` - Letters, digits, \`_\` and \`-\`; derived from \`--name\`, then the URL host (minus \`www.\` / \`mcp.\`), then the command name
+- \`--auth <none|bearer|oauth2>\` - Auth type; defaults to \`bearer\` when \`--token\` is given, otherwise \`none\`
+- \`--token <token>\` - Bearer token, only with \`--auth bearer\`
+- \`--header <key:value>\` - Custom request header for HTTP connectors, repeatable. Header values are stored as connector metadata and returned by \`list\`, so put a secret in \`--token\`, not in a header
+- \`--force\` - Overwrite an existing connector with the same identifier (otherwise \`add\` refuses the duplicate)
+- \`--json [fields]\` - Machine-readable result
+
+stdio connectors accept no \`--auth\` or \`--header\`. Their command and arguments are stored in plain text, returned by \`list\` to anyone who can see the connector, and visible in the local process list, so never put a token or key in \`--stdio-cmd\` or \`--stdio-arg\`. A stdio server that needs a secret cannot currently be configured securely with this command; prefer the server's HTTP endpoint with \`--token\` (bearer tokens are stored as credentials and never returned by \`list\`).
+
+## Tool sync after add
+
+- \`none\` / \`bearer\`: \`add\` creates the connector, then syncs its tools immediately and prints the tool count. If the sync fails, a newly created connector is rolled back, so fix the URL or credentials and run \`add\` again. A connector overwritten with \`--force\` is kept with the new settings, not restored; fix it and rerun \`add\` with \`--force\`.
+- \`oauth2\`: \`add\` creates the connector and prints an authorization URL (\`status: pending_oauth\` in \`--json\`). The user opens it in a browser; on success the authorization callback syncs the tools itself. The page says \`Authorization complete\` even when that sync fails, so after the user authorizes, check \`lh connector list\`: \`connected\` with a non-zero tool count means the connector is ready; \`error\` or 0 tools means the sync failed, so run \`lh connector refresh <identifier>\`.
+- Remote URLs reachable from the server are synced by the server. stdio commands and local URLs are listed from this machine and the result is uploaded; the output marks this as \`synced from this machine\` (\`local: true\` in \`--json\`). Local means \`localhost\`, loopback, \`0.0.0.0\` and private IPv4 addresses (10.x, 172.16-31.x, 192.168.x). LAN hostnames such as \`*.local\` are synced by the server, so use the IP address instead.
+- Run \`refresh\` when the MCP server's tools change. It is a maintenance operation: in a workspace it may require permission to manage that connector. Refreshing a stdio connector runs its stored command locally; a command not yet approved on this machine requires an interactive confirmation, so \`refresh\` fails in a non-interactive shell until a person approves it.
+
+## Examples
+
+\`\`\`bash
+lh mcp add --url https://mcp.example.com/mcp --name Example --token "$EXAMPLE_TOKEN"
+lh mcp add --url https://mcp.example.com/oauth/mcp --identifier example-oauth --auth oauth2
+lh mcp add --stdio-cmd uvx --stdio-arg mcp-server-fetch --name Fetch
+lh mcp list --json id,identifier,status,toolCount
+lh mcp refresh example
+lh mcp remove example --yes
+\`\`\`
+`;
+
+export default content;