# @agent-infra/mcp-client 中文文档

规范地址：https://npmcn.com/package/%40agent-infra/mcp-client/

版本：1\.2\.29
npm 元数据更新时间：2026-05-14T05:36:15.194Z
中文译文更新时间：2026-11-06T01:00:40.522Z
软件包许可：未声明

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40agent-infra/mcp-client
原文对照：https://npmcn.com/package/%40agent-infra/mcp-client/?lang=original
项目主页：https://github.com/bytedance/UI-TARS-desktop
源码仓库：https://github.com/bytedance/UI-TARS-desktop

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：59.9 kB，6 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：6 个
- 首次发布：2025-04-01T02:32:17.659Z
- 最新版本发布：2025-12-15T06:31:48.258Z
- 近 30 天下载量：7543（2026-10-05 至 2026-11-03，npm 官方下载统计）
- 已发布版本数：74（近 12 个月 5 个）

## 中文简介

运行 Electron apps 服务器的 MCP 客户端, 支持同一进程接近

## 安装

```sh
npm install @agent-infra/mcp-client
```

也可以使用：`pnpm add @agent-infra/mcp-client`、`yarn add @agent-infra/mcp-client`、`bun add @agent-infra/mcp-client`

## README

## @ agent-infra/mcp-客户端

[![NPM Downloads](https://img.shields.io/npm/d18m/@agent-infra/mcp-client)](https://www.npmjs.com/package/@agent-infra/mcp-client)

QQ 在 TypeScript 中执行一个统一的 MCP 客户端, 支持四大运出框 : **记忆**Stdio,SSE(服务生事件),以及 **可流取的 HTTP**。 。 。 .

### \* 特性

-   🟦 **在类型脚本中写入**:类型安全,现代,并易于整合.
-   🔌 **多运输支助**: 外出支持四大运输:
    -   🧠 **记忆**:为快速,本地工具集成.
    -   🖥️ **斯特迪奥**:通过标准输入/输出与工具进行交流,适合基于进程的工具.
    -   🔄 **SSE( 仆人事件)**: 实时,事件驱动的通信超過HTTP.
    -   🌐 **可流取的 HTTP**:高效,以流为基础的HTTP通信,用于可伸缩远程工具.
-   🛠️ **统一 API**: 与所有运输机使用单一,一致的接口进行交互.
-   🧩 **范围很广**:根据需要方便地添加自定义运输或工具.
-   🔍 **过滤支持**: 使用带有允许/块列表的 glob 模式过滤工具和提示.

### QQ 快速启动

```ts
import { MCPClient } from '@agent-infra/mcp-client';

// type: module project usage
import { createServer as createFileSystemServer } from '@agent-infra/mcp-server-filesystem';
// commonjs project usage
// const { createServer as createFileSystemServer } = await import('@agent-infra/mcp-server-filesystem')

const mcpClient = new MCPClient([
  // In-memory
  {
    type: 'builtin',
    name: 'FileSystem',
    description: 'filesystem tool',
    mcpServer: createFileSystemServer({
      allowedDirectories: [omegaDir],
    }),
  },
  // stdio
  {
    type: 'stdio',
    name: 'FileSystem-Stdio',
    description: 'filesystem tool',
    command: 'npx',
    args: [
      '-y',
      '@agent-infra/mcp-server-filesystem'
    ]
  },
  // sse
  {
    type: 'sse',
    name: 'FileSystem-sse',
    description: 'filesystem tool',
    url: 'http://localhost:8889/sse'
  },
  // streamable-http
  {
    type: 'sse',
    name: 'FileSystem-http',
    description: 'filesystem tool',
    url: 'http://localhost:8889/mcp'
  }
]);


await mcpClient.listTools();
await mcpClient.listPrompts();
const result = await mcpClient.callTool({
  client: 'FileSystem-sse',
  name: 'list_directory',
  arguments: {
    path: '~/your_computer'
  },
});
```

### 过滤工具和提示

您可以使用 glob 模式过滤工具和提示, 包含允许和块列表 :

```ts
const mcpClient = new MCPClient([
  {
    type: 'builtin',
    name: 'FileSystem',
    description: 'filesystem tool',
    mcpServer: createFileSystemServer({
      allowedDirectories: [omegaDir],
    }),
    // Filter configuration
    filters: {
      tools: {
        allow: ['list_*', 'read_*'], // Only allow tools starting with 'list_' or 'read_'
        block: ['delete_*']          // Block any tools starting with 'delete_'
      },
      prompts: {
        allow: ['safe_*'],           // Only allow prompts starting with 'safe_'
        block: ['admin_*']           // Block prompts starting with 'admin_'
      }
    }
  }
]);

// List all tools (filtered)
const tools = await mcpClient.listTools();

// List all prompts (filtered)  
const prompts = await mcpClient.listPrompts();

// List tools from specific server
const serverTools = await mcpClient.listTools('FileSystem');
```

**过滤规则 :**

-   **允许模式**: 如果指定, 只包含符合这些模式的项目
-   **块图案**: 不包括符合这些模式的项目
-   **模式语法**: 用途 [小型匹配](https://github.com/isaacs/minimatch) 平面图案( u)`*`, (中文(简体) ), `**`, (中文(简体) ), `?`, (中文(简体) ), `[...]`页:1
-   **处理顺序**: 允许先应用过滤器, 然后用块过滤器

### • 信贷

感谢:

-   [康芬马奥](https://github.com/kangfenmao) 用于创建伟大的 AI 聊天器产品 [樱桃工作室](https://github.com/CherryHQ/cherry-studio) 我们从中汲取了很多浏览器检测功能的灵感.
-   这个 [@ modelcontextprotocol/ sdk (英语)](https://github.com/modelcontextprotocol/typescript-sdk) 帮助我们更好地开发和使用代理工具的项目.

## 常见问题

### @agent-infra/mcp-client 是什么？

运行 Electron apps 服务器的 MCP 客户端, 支持同一进程接近

### 如何安装 @agent-infra/mcp-client？

在项目目录运行 npm install @agent-infra/mcp-client，或使用 pnpm add / yarn add / bun add。

### @agent-infra/mcp-client 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @agent-infra/mcp-client 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @agent-infra/mcp-client 可以商用吗？

@agent-infra/mcp-client 使用 未声明 许可。package\.json 没有声明许可证。没有许可证的代码默认保留全部权利，商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括，不构成法律意见，请以许可原文为准。

### @agent-infra/mcp-client 的下载量有多少？

根据 npm 官方下载统计，@agent-infra/mcp-client 在 2026/10/05 – 2026/11/03 这 30 天内被下载 7,543 次，日均约 251 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @agent-infra/mcp-client 还在维护吗？

最新版本 1\.2\.29 发布于 2025/12/15（10 个月前）；至今共发布 74 个版本，其中过去 12 个月发布了 5 个；首次发布于 2025/04/01。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

