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.

🐛 fix: avoid undefined MCP preview capability counts (#21744)

Bryan6e39d1aa0a4c
diff --git a/apps/desktop/src/main/controllers/McpCtr.ts b/apps/desktop/src/main/controllers/McpCtr.ts
index 36d7a6fb3f5..40be74fa1f4 100644
--- a/apps/desktop/src/main/controllers/McpCtr.ts
+++ b/apps/desktop/src/main/controllers/McpCtr.ts
@@ -6,6 +6,7 @@ import {
type McpIpcPayload,
serializeMcpIpcPayload,
} from '@lobechat/utils/mcpIpcPayload';
+import { getMcpServerDescription } from '@lobechat/utils/mcpServerDescription';
import FileService from '@/services/fileSrv';
import { createLogger } from '@/utils/logger';
@@ -510,13 +511,7 @@ export default class McpCtr extends ControllerModule {
identifier,
meta: {
avatar: input.metadata?.avatar || 'MCP_AVATAR',
- description:
- input.metadata?.description ||
- `${identifier} MCP server has ` +
- Object.entries(manifest)
- .filter(([key]) => ['tools', 'prompts', 'resources'].includes(key))
- .map(([key, item]) => `${(item as Array<any>)?.length} ${key}`)
- .join(','),
+ description: input.metadata?.description || getMcpServerDescription(identifier, manifest),
title: input.metadata?.name || identifier,
},
...manifest,
@@ -579,7 +574,7 @@ export default class McpCtr extends ControllerModule {
avatar: input.metadata?.avatar || 'MCP_AVATAR',
description:
input.metadata?.description ||
- `${identifier} MCP server has ${tools.length} tools, like "${tools[0]?.name}"`,
+ getMcpServerDescription(identifier, { tools }, { includeToolExample: true }),
title: identifier,
},
type: 'mcp' as any,
diff --git a/apps/desktop/src/main/controllers/__tests__/McpCtr.session-reuse.test.ts b/apps/desktop/src/main/controllers/__tests__/McpCtr.session-reuse.test.ts
index 6e10a0abf29..ce2e414824c 100644
--- a/apps/desktop/src/main/controllers/__tests__/McpCtr.session-reuse.test.ts
+++ b/apps/desktop/src/main/controllers/__tests__/McpCtr.session-reuse.test.ts
@@ -1,3 +1,4 @@
+import { deserializeMcpIpcPayload, serializeMcpIpcPayload } from '@lobechat/utils/mcpIpcPayload';
import { SdkError, SdkErrorCode, SdkHttpError } from '@modelcontextprotocol/client';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
@@ -52,6 +53,105 @@ describe('McpCtr stdio session reuse (T-801 stateful MCP servers)', () => {
vi.restoreAllMocks();
});
+ it.each(['My server description'])(
+ 'keeps stdio descriptions as metadata (%s)',
+ async (description) => {
+ const instance = {
+ ...makeClientInstance('tools-only'),
+ listManifests: vi.fn().mockResolvedValue({
+ prompts: undefined,
+ resources: undefined,
+ tools: [{ inputSchema: { type: 'object' }, name: 'hello' }],
+ }),
+ };
+ mcpClientMocks.mockReturnValue(instance);
+
+ const result = await ctr.getStdioMcpServerManifest(
+ serializeMcpIpcPayload({
+ command: 'test-command',
+ metadata: { description },
+ name: 'tools-only',
+ }),
+ );
+ const manifest = deserializeMcpIpcPayload<{ api: unknown[]; meta: { description?: string } }>(
+ result,
+ );
+
+ expect(manifest.api).toHaveLength(1);
+ expect(manifest.meta.description).toBe(description);
+ },
+ );
+
+ it.each(['My server description'])(
+ 'keeps HTTP descriptions as metadata (%s)',
+ async (description) => {
+ const instance = { ...makeClientInstance('http'), listTools: vi.fn().mockResolvedValue([]) };
+ mcpClientMocks.mockReturnValue(instance);
+
+ const result = await ctr.getStreamableMcpServerManifest(
+ serializeMcpIpcPayload({
+ identifier: 'empty-server',
+ metadata: { description },
+ url: 'http://localhost/mcp',
+ }),
+ );
+ const manifest = deserializeMcpIpcPayload<{ api: unknown[]; meta: { description?: string } }>(
+ result,
+ );
+
+ expect(manifest.api).toEqual([]);
+ expect(manifest.meta.description).toBe(description);
+ },
+ );
+
+ it.each([
+ {
+ capabilities: { tools: [{ name: 'hello' }] },
+ summary: '1 tool',
+ },
+ {
+ capabilities: { prompts: [], resources: [], tools: [] },
+ summary: 'no tools, prompts, or resources',
+ },
+ {
+ capabilities: {
+ prompts: [{ name: 'greet' }],
+ resources: [{ name: 'readme' }],
+ tools: [{ name: 'hello' }],
+ },
+ summary: '1 prompt, 1 resource, 1 tool',
+ },
+ ])('persists the automatic stdio description: $summary', async ({ capabilities, summary }) => {
+ const instance = makeClientInstance('automatic');
+ instance.listManifests.mockResolvedValue(capabilities);
+ mcpClientMocks.mockReturnValue(instance);
+
+ const result = await ctr.getStdioMcpServerManifest(
+ serializeMcpIpcPayload({ command: 'test-command', name: 'automatic' }),
+ );
+ const manifest = deserializeMcpIpcPayload<{ meta: { description: string } }>(result);
+
+ expect(manifest.meta.description).toBe(`automatic MCP server has ${summary}`);
+ expect(manifest.meta.description).not.toContain('undefined');
+ });
+
+ it.each([
+ { tools: [], summary: 'no tools, prompts, or resources' },
+ { tools: [{ name: 'hello' }], summary: '1 tool, like "hello"' },
+ ])('persists the automatic HTTP description: $summary', async ({ tools, summary }) => {
+ mcpClientMocks.mockReturnValue({
+ ...makeClientInstance('automatic'),
+ listTools: vi.fn().mockResolvedValue(tools),
+ });
+ const result = await ctr.getStreamableMcpServerManifest(
+ serializeMcpIpcPayload({ identifier: 'automatic', url: 'http://localhost/mcp' }),
+ );
+ const manifest = deserializeMcpIpcPayload<{ meta: { description: string } }>(result);
+
+ expect(manifest.meta.description).toBe(`automatic MCP server has ${summary}`);
+ expect(manifest.meta.description).not.toContain('undefined');
+ });
+
it('reuses one stdio session across consecutive tool calls (state survives)', async () => {
const instance = makeClientInstance('first');
mcpClientMocks.mockReturnValue(instance);
diff --git a/apps/server/src/services/mcp/index.manifestDescriptions.test.ts b/apps/server/src/services/mcp/index.manifestDescriptions.test.ts
new file mode 100644
index 00000000000..4196c666992
--- /dev/null
+++ b/apps/server/src/services/mcp/index.manifestDescriptions.test.ts
@@ -0,0 +1,116 @@
+import type * as LobeConst from '@lobechat/const';
+import { pluginPrompts } from '@lobechat/prompts';
+import type { ToolManifest } from '@lobechat/types';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { MCPClient } from '@/libs/mcp';
+
+import { MCPService } from './index';
+
+vi.mock('@/libs/mcp');
+vi.mock('@lobechat/const', async (importOriginal) => ({
+ ...(await importOriginal<typeof LobeConst>()),
+ isDesktop: true,
+}));
+
+const tools = [{ inputSchema: { type: 'object' as const }, name: 'hello' }];
+const scenarios = [
+ {
+ expected: 'test-mcp MCP server has 1 tool',
+ manifest: { prompts: undefined, resources: undefined, tools },
+ name: 'tools only',
+ },
+ {
+ expected: 'test-mcp MCP server has no tools, prompts, or resources',
+ manifest: { prompts: [], resources: [], tools: [] },
+ name: 'empty capabilities',
+ },
+ {
+ expected: 'test-mcp MCP server has 1 prompt, 1 resource, 1 tool',
+ manifest: {
+ prompts: [{ name: 'greet' }],
+ resources: [{ name: 'readme', uri: 'file:///readme' }],
+ tools,
+ },
+ name: 'all capabilities',
+ },
+];
+
+describe('MCP automatic descriptions and installed tool prompts', () => {
+ let service: MCPService;
+
+ beforeEach(() => {
+ vi.clearAllMocks();
+ service = new MCPService();
+ vi.mocked(MCPClient.prototype.listTools).mockResolvedValue(tools);
+ vi.mocked(MCPClient.prototype.listManifests).mockResolvedValue({
+ prompts: undefined,
+ resources: undefined,
+ title: undefined,
+ tools,
+ version: undefined,
+ });
+ });
+
+ afterEach(() => vi.restoreAllMocks());
+
+ it.each(scenarios)(
+ 'generates a nonempty English description: $name',
+ async ({ manifest, expected }) => {
+ vi.mocked(MCPClient.prototype.listManifests).mockResolvedValue({
+ ...manifest,
+ title: undefined,
+ version: undefined,
+ });
+ const result = await service.getStdioMcpServerManifest({ command: 'mcp', name: 'test-mcp' });
+
+ expect(result.meta.description).toBe(expected);
+ expect(result.meta.description).not.toContain('undefined');
+ },
+ );
+
+ it.each([
+ { expected: 'test-mcp MCP server has no tools, prompts, or resources', tools: [] },
+ { expected: 'test-mcp MCP server has 1 tool, like "hello"', tools },
+ ])(
+ 'generates an HTTP description without an absent tool example: $expected',
+ async (scenario) => {
+ vi.mocked(MCPClient.prototype.listTools).mockResolvedValue(scenario.tools);
+ const result = await service.getStreamableMcpServerManifest(
+ 'test-mcp',
+ 'https://mcp.example.com',
+ );
+
+ expect(result.meta.description).toBe(scenario.expected);
+ expect(result.meta.description).not.toContain('undefined');
+ },
+ );
+
+ it.each(['stdio', 'http'] as const)(
+ 'keeps the installed %s manifest description in pluginPrompts',
+ async (transport) => {
+ const manifest =
+ transport === 'stdio'
+ ? await service.getStdioMcpServerManifest({ command: 'mcp', name: 'test-mcp' })
+ : await service.getStreamableMcpServerManifest('test-mcp', 'https://mcp.example.com');
+ // Installation persists this manifest as JSON. Exercise the read-back shape
+ // and the same description field consumed by ToolSystemRoleProvider.
+ // eslint-disable-next-line unicorn/prefer-structured-clone -- Exercise JSON persistence, not an in-memory clone.
+ const installed: ToolManifest = JSON.parse(JSON.stringify(manifest));
+ const prompt = pluginPrompts({
+ tools: [
+ {
+ apis: installed.api.map((api) => ({ desc: api.description, name: api.name })),
+ description: installed.meta.description,
+ identifier: installed.identifier,
+ name: installed.meta.title,
+ },
+ ],
+ });
+
+ expect(prompt).not.toContain('no description');
+ expect(prompt).toContain('<tool name="test-mcp">test-mcp MCP server has 1 tool');
+ expect(prompt).not.toContain('undefined');
+ },
+ );
+});
diff --git a/apps/server/src/services/mcp/index.test.ts b/apps/server/src/services/mcp/index.test.ts
index fe0dbb452b5..68def2cad73 100644
--- a/apps/server/src/services/mcp/index.test.ts
+++ b/apps/server/src/services/mcp/index.test.ts
@@ -260,6 +260,7 @@ describe('MCPService', () => {
// 创建 mock 客户端
mockClient = {
callTool: vi.fn(),
+ listManifests: vi.fn(),
listPrompts: vi.fn(),
listResources: vi.fn(),
listTools: vi.fn(),
@@ -269,6 +270,43 @@ describe('MCPService', () => {
getClientSpy = vi.spyOn(mcpService as any, 'getClient').mockResolvedValue(mockClient);
});
+ describe('manifest descriptions', () => {
+ it.each(['My server description'])(
+ 'keeps stdio descriptions as metadata (%s)',
+ async (description) => {
+ mockClient.listManifests.mockResolvedValue({
+ prompts: undefined,
+ resources: undefined,
+ tools: [{ inputSchema: { type: 'object' }, name: 'hello' }],
+ });
+
+ const manifest = await mcpService.getStdioMcpServerManifest(
+ { command: 'test-command', name: 'tools-only' },
+ { description },
+ );
+
+ expect(manifest.api).toHaveLength(1);
+ expect(manifest.meta.description).toBe(description);
+ },
+ );
+
+ it.each(['My server description'])(
+ 'keeps HTTP descriptions as metadata (%s)',
+ async (description) => {
+ mockClient.listTools.mockResolvedValue([]);
+
+ const manifest = await mcpService.getStreamableMcpServerManifest(
+ 'empty-server',
+ 'https://mcp.example.com',
+ { description },
+ );
+
+ expect(manifest.api).toEqual([]);
+ expect(manifest.meta.description).toBe(description);
+ },
+ );
+ });
+
describe('callTool', () => {
const mockParams = {
name: 'test-mcp',
diff --git a/apps/server/src/services/mcp/index.ts b/apps/server/src/services/mcp/index.ts
index bafe35e8f69..c883a73bfc0 100644
--- a/apps/server/src/services/mcp/index.ts
+++ b/apps/server/src/services/mcp/index.ts
@@ -7,6 +7,7 @@ import {
type ToolManifestSettings,
} from '@lobechat/types';
import { safeParseJSON } from '@lobechat/utils';
+import { getMcpServerDescription } from '@lobechat/utils/mcpServerDescription';
import { type DeploymentOption } from '@lobehub/market-sdk';
import { ProtocolError, SdkError, SdkErrorCode } from '@modelcontextprotocol/client';
import { TRPCError } from '@trpc/server';
@@ -376,7 +377,7 @@ export class MCPService {
avatar: metadata?.avatar || 'MCP_AVATAR',
description:
metadata?.description ||
- `${identifier} MCP server has ${tools.length} tools, like "${tools[0]?.name}"`,
+ getMcpServerDescription(identifier, { tools }, { includeToolExample: true }),
title: identifier,
},
// TODO: temporary
@@ -407,13 +408,7 @@ export class MCPService {
identifier,
meta: {
avatar: metadata?.avatar || 'MCP_AVATAR',
- description:
- metadata?.description ||
- `${identifier} MCP server has ` +
- Object.entries(manifest)
- .filter(([key]) => ['tools', 'prompts', 'resources'].includes(key))
- .map(([key, item]) => `${(item as Array<any>)?.length} ${key}`)
- .join(','),
+ description: metadata?.description || getMcpServerDescription(identifier, manifest),
title: metadata?.name || identifier,
},
...manifest,
diff --git a/locales/en-US/plugin.json b/locales/en-US/plugin.json
index 73495ab725e..9926489849b 100644
--- a/locales/en-US/plugin.json
+++ b/locales/en-US/plugin.json
@@ -828,6 +828,13 @@
"dev.preview.desc": "Preview description",
"dev.preview.empty.desc": "Complete configuration to preview Skill capabilities",
"dev.preview.empty.title": "Configure to preview",
+ "dev.preview.mcp.empty": "No tools, prompts, or resources",
+ "dev.preview.mcp.prompts_one": "{{count}} prompt",
+ "dev.preview.mcp.prompts_other": "{{count}} prompts",
+ "dev.preview.mcp.resources_one": "{{count}} resource",
+ "dev.preview.mcp.resources_other": "{{count}} resources",
+ "dev.preview.mcp.tools_one": "{{count}} tool",
+ "dev.preview.mcp.tools_other": "{{count}} tools",
"dev.preview.title": "Skill name preview",
"dev.save": "Install",
"dev.saveError": "Install failed, please try again",
diff --git a/locales/zh-CN/plugin.json b/locales/zh-CN/plugin.json
index 10ec861e979..70947641d49 100644
--- a/locales/zh-CN/plugin.json
+++ b/locales/zh-CN/plugin.json
@@ -828,6 +828,13 @@
"dev.preview.desc": "预览技能描述",
"dev.preview.empty.desc": "完成配置后,将能够在此处预览技能支持的能力",
"dev.preview.empty.title": "配置技能后开始预览",
+ "dev.preview.mcp.empty": "没有工具、提示词或资源",
+ "dev.preview.mcp.prompts_one": "{{count}} 个提示词",
+ "dev.preview.mcp.prompts_other": "{{count}} 个提示词",
+ "dev.preview.mcp.resources_one": "{{count}} 个资源",
+ "dev.preview.mcp.resources_other": "{{count}} 个资源",
+ "dev.preview.mcp.tools_one": "{{count}} 个工具",
+ "dev.preview.mcp.tools_other": "{{count}} 个工具",
"dev.preview.title": "技能名称预览",
"dev.save": "安装技能",
"dev.saveError": "安装失败,请重试",
diff --git a/packages/locales/src/default/plugin.ts b/packages/locales/src/default/plugin.ts
index cda20337008..246c47d567d 100644
--- a/packages/locales/src/default/plugin.ts
+++ b/packages/locales/src/default/plugin.ts
@@ -847,6 +847,13 @@ export default {
'dev.preview.desc': 'Preview description',
'dev.preview.empty.desc': 'Complete configuration to preview Skill capabilities',
'dev.preview.empty.title': 'Configure to preview',
+ 'dev.preview.mcp.empty': 'No tools, prompts, or resources',
+ 'dev.preview.mcp.prompts_one': '{{count}} prompt',
+ 'dev.preview.mcp.prompts_other': '{{count}} prompts',
+ 'dev.preview.mcp.resources_one': '{{count}} resource',
+ 'dev.preview.mcp.resources_other': '{{count}} resources',
+ 'dev.preview.mcp.tools_one': '{{count}} tool',
+ 'dev.preview.mcp.tools_other': '{{count}} tools',
'dev.preview.title': 'Skill name preview',
'dev.save': 'Install',
'dev.saveError': 'Install failed, please try again',
diff --git a/packages/utils/src/mcpServerDescription.test.ts b/packages/utils/src/mcpServerDescription.test.ts
new file mode 100644
index 00000000000..61deab4baa2
--- /dev/null
+++ b/packages/utils/src/mcpServerDescription.test.ts
@@ -0,0 +1,35 @@
+import { describe, expect, it } from 'vitest';
+
+import { getMcpServerDescription } from './mcpServerDescription';
+
+describe('getMcpServerDescription', () => {
+ it.each([
+ { capabilities: {}, summary: 'no tools, prompts, or resources' },
+ {
+ capabilities: { prompts: [], resources: [], tools: [] },
+ summary: 'no tools, prompts, or resources',
+ },
+ { capabilities: { tools: [{ name: 'hello' }] }, summary: '1 tool' },
+ {
+ capabilities: { prompts: [{}], resources: [{}, {}], tools: [{ name: 'a' }, { name: 'b' }] },
+ summary: '1 prompt, 2 resources, 2 tools',
+ },
+ ])('describes available capabilities: $summary', ({ capabilities, summary }) => {
+ const description = getMcpServerDescription('example', capabilities);
+ expect(description).toBe(`example MCP server has ${summary}`);
+ expect(description).not.toContain('undefined');
+ });
+
+ it('only adds a tool example when a tool exists', () => {
+ expect(getMcpServerDescription('example', { tools: [] }, { includeToolExample: true })).toBe(
+ 'example MCP server has no tools, prompts, or resources',
+ );
+ expect(
+ getMcpServerDescription(
+ 'example',
+ { tools: [{ name: 'hello' }] },
+ { includeToolExample: true },
+ ),
+ ).toBe('example MCP server has 1 tool, like "hello"');
+ });
+});
diff --git a/packages/utils/src/mcpServerDescription.ts b/packages/utils/src/mcpServerDescription.ts
new file mode 100644
index 00000000000..0accd4921c3
--- /dev/null
+++ b/packages/utils/src/mcpServerDescription.ts
@@ -0,0 +1,25 @@
+interface McpServerCapabilities {
+ prompts?: readonly unknown[];
+ resources?: readonly unknown[];
+ tools?: readonly { name: string }[];
+}
+
+/** Persisted MCP metadata, also consumed by model prompts. Keep this text in English. */
+export const getMcpServerDescription = (
+ identifier: string,
+ { prompts, resources, tools }: McpServerCapabilities,
+ { includeToolExample = false }: { includeToolExample?: boolean } = {},
+): string => {
+ const counts = [
+ { count: prompts?.length, name: 'prompt' },
+ { count: resources?.length, name: 'resource' },
+ { count: tools?.length, name: 'tool' },
+ ];
+ const summary = counts
+ .filter(({ count }) => count)
+ .map(({ count, name }) => `${count} ${name}${count === 1 ? '' : 's'}`)
+ .join(', ');
+ const example = includeToolExample && tools?.[0] ? `, like ${JSON.stringify(tools[0].name)}` : '';
+
+ return `${identifier} MCP server has ${summary || 'no tools, prompts, or resources'}${example}`;
+};
diff --git a/src/features/PluginDevModal/PluginPreview/index.tsx b/src/features/PluginDevModal/PluginPreview/index.tsx
index 4e4c110690d..c37579e73ea 100644
--- a/src/features/PluginDevModal/PluginPreview/index.tsx
+++ b/src/features/PluginDevModal/PluginPreview/index.tsx
@@ -12,9 +12,10 @@ import { pluginHelpers } from '@/store/tool';
import ApiVisualizer from './ApiVisualizer';
import PluginEmptyState from './EmptyState';
+import { getMcpManifestSummary } from './mcpManifestSummary';
const PluginPreview = memo<{ form: FormInstance<LobeToolCustomPlugin> }>(({ form }) => {
- const { t } = useTranslation('plugin');
+ const { t, i18n } = useTranslation('plugin');
const manifest = useWatch(form, 'manifest');
const meta = manifest?.meta;
@@ -48,7 +49,10 @@ const PluginPreview = memo<{ form: FormInstance<LobeToolCustomPlugin> }>(({ form
<PluginTag type={'customPlugin'} />
</Flexbox>
<Text style={{ fontSize: 12 }} type={'secondary'}>
- {pluginHelpers.getPluginDesc(meta) || 'Plugin Description'}
+ {pluginHelpers.getPluginDesc(meta) ||
+ (manifest.type === 'mcp'
+ ? getMcpManifestSummary(manifest, t, i18n.resolvedLanguage)
+ : 'Plugin Description')}
</Text>
</Flexbox>
</Flexbox>
diff --git a/src/features/PluginDevModal/PluginPreview/mcpManifestSummary.test.ts b/src/features/PluginDevModal/PluginPreview/mcpManifestSummary.test.ts
new file mode 100644
index 00000000000..c855f4c821e
--- /dev/null
+++ b/src/features/PluginDevModal/PluginPreview/mcpManifestSummary.test.ts
@@ -0,0 +1,49 @@
+import { createInstance } from 'i18next';
+import { describe, expect, it } from 'vitest';
+
+import enUS from '../../../../locales/en-US/plugin.json';
+import zhCN from '../../../../locales/zh-CN/plugin.json';
+import { getMcpManifestSummary } from './mcpManifestSummary';
+
+const i18n = createInstance();
+await i18n.init({
+ fallbackLng: 'en-US',
+ resources: { 'en-US': { plugin: enUS }, 'zh-CN': { plugin: zhCN } },
+});
+
+const summary = (manifest: Parameters<typeof getMcpManifestSummary>[0], locale = 'en-US') =>
+ getMcpManifestSummary(manifest, i18n.getFixedT(locale, 'plugin'), locale);
+
+describe('MCP preview capability summary', () => {
+ it.each([undefined, []])('omits missing or empty capabilities (%s)', (empty) => {
+ expect(summary({ api: [{}, {}, {}], prompts: empty, resources: empty })).toBe('3 tools');
+ });
+
+ it('uses singular counts and a localized list for mixed capabilities', () => {
+ expect(summary({ api: [{}], prompts: [{}], resources: [{}] })).toBe(
+ '1 prompt, 1 resource, and 1 tool',
+ );
+ expect(summary({ api: [{}, {}], prompts: [{}, {}], resources: [{}, {}] })).toBe(
+ '2 prompts, 2 resources, and 2 tools',
+ );
+ });
+
+ it('handles a successful connection with no capabilities', () => {
+ expect(summary({ api: [], prompts: [], resources: [] })).toBe(
+ 'No tools, prompts, or resources',
+ );
+ });
+
+ it('does not require tools when the server only provides prompts or resources', () => {
+ expect(summary({ api: [], prompts: [{}] })).toBe('1 prompt');
+ expect(summary({ api: [], resources: [{}] })).toBe('1 resource');
+ });
+
+ it('translates counts and the empty state into Chinese', () => {
+ expect(summary({ api: [{}, {}, {}] }, 'zh-CN')).toBe('3 个工具');
+ expect(summary({ api: [{}], prompts: [{}], resources: [{}] }, 'zh-CN')).toBe(
+ '1 个提示词、1 个资源和1 个工具',
+ );
+ expect(summary({ api: [] }, 'zh-CN')).toBe('没有工具、提示词或资源');
+ });
+});
diff --git a/src/features/PluginDevModal/PluginPreview/mcpManifestSummary.ts b/src/features/PluginDevModal/PluginPreview/mcpManifestSummary.ts
new file mode 100644
index 00000000000..7519bc9b882
--- /dev/null
+++ b/src/features/PluginDevModal/PluginPreview/mcpManifestSummary.ts
@@ -0,0 +1,27 @@
+import type { TFunction } from 'i18next';
+
+interface MCPPreviewManifest {
+ api: readonly unknown[];
+ prompts?: readonly unknown[];
+ resources?: readonly unknown[];
+}
+
+/** Capability summaries are presentation, not persisted server descriptions. */
+export const getMcpManifestSummary = (
+ manifest: MCPPreviewManifest,
+ t: TFunction<'plugin'>,
+ locale?: string,
+): string => {
+ const capabilities: string[] = [];
+
+ if (manifest.prompts?.length)
+ capabilities.push(t('dev.preview.mcp.prompts', { count: manifest.prompts.length }));
+ if (manifest.resources?.length)
+ capabilities.push(t('dev.preview.mcp.resources', { count: manifest.resources.length }));
+ if (manifest.api.length)
+ capabilities.push(t('dev.preview.mcp.tools', { count: manifest.api.length }));
+
+ return capabilities.length
+ ? new Intl.ListFormat(locale).format(capabilities)
+ : t('dev.preview.mcp.empty');
+};