Huggingface.js documentation
@huggingface/mcp-client
@huggingface/inference
使用 Inference ClientAPI 参考
类
HfInferenceInferenceClientInferenceClientEndpointInferenceClientErrorInferenceClientHubApiErrorInferenceClientInputErrorInferenceClientProviderApiErrorInferenceClientProviderOutputErrorInferenceClientRoutingError
接口
AudioToAudioOutputAudioToAudioOutputElemBaseArgsBodyParamsHeaderParamsInferenceProviderMappingEntryLogger选项TextGenerationInputTextGenerationOutputTextGenerationStreamBestOfSequenceTextGenerationStreamDetailsTextGenerationStreamOutputTextGenerationStreamPrefillTokenTextGenerationStreamTokenUrlParams
模块
@huggingface/hub
与 Hub 交互API 参考
类
接口
AuthInfoCachedFileInfoCachedRepoInfoCachedRevisionInfoCommitCopyFileCommitDataCommitDeletedEntryCommitEditFileCommitEditFileParamsCommitFileCommitInfoCommitOutputCopyDestinationCopyFilesEntryCopyProgressEventCopySource凭据DatasetEntryFileDownloadInfoOutputHFCacheInfoJobVolumeLfsPathInfoListFileEntryMlxQuantizationConfigModelConfigModelDerivedFieldsModelEntryOAuthResultParallelDownloadOptionsPathInfoQuantizationConfigRangeEditCacheEntryRepoIdSafetensorsIndexJsonSafetensorsShardFileInfoSecurityFileStatusSpaceEntrySpaceResourceConfigSpaceResourceRequirementSpaceRuntimeTensorInfoUserInfoWhoAmIAppWhoAmIOrgWhoAmIUserXetFileInfoXetReadToken
@huggingface/mcp-client
@huggingface/tiny-agents
@huggingface/space-header
@huggingface/gguf
@huggingface/lerobot
@huggingface/usd-web-viewer
@huggingface/mcp-client
模型上下文协议(MCP)的客户端。
此包提供了一个用于与 MCP 服务器交互的客户端实现,基于我们的 InferenceClient @huggingface/inference 构建。
它包含一个示例 CLI smol Agent,可以利用 MCP 工具。
安装
此包是 Hugging Face JS monorepo 的一部分。要安装所有包的依赖项,请在仓库根目录下运行:
pnpm install
用法(CLI Agent)
该包包含一个命令行界面(CLI)代理,用于演示如何使用 MCP 客户端。
先决条件
- Hugging Face API Token: 您需要一个具有相应权限的 Hugging Face API 令牌。请将其设置为环境变量:
export HF_TOKEN="hf_..."
运行 Agent
导航到包目录并运行代理脚本:
cd packages/mcp-client
pnpm agent或者,从 monorepo 的根目录运行:
pnpm --filter @huggingface/mcp-client agent
该智能体将加载可用的 MCP 工具(默认情况下,会连接到用于您桌面的文件系统服务器和一个 Playwright 服务器),并提示您输入(>)。
配置(环境变量)
HF_TOKEN(可选):您的 Hugging Face API 令牌。如果您在 HF 上使用 Inference Provider,则此项为必填。MODEL_ID(可选):用于智能体推理的模型 ID。默认为Qwen/Qwen2.5-72B-Instruct。PROVIDER(可选):推理提供商。默认为together。有关可用的提供商,请参阅@huggingface/inference。ENDPOINT_URL或BASE_URL(可选):要调用的自定义基础 URL(例如本地 URL)。
使用自定义模型的示例:
export HF_TOKEN="hf_..."
export MODEL_ID="Qwen/Qwen2.5-72B-Instruct"
pnpm agent开发
可以使用 pnpm 脚本运行常见的开发任务:
pnpm build:构建该包。pnpm lint:检查并修复代码风格。pnpm format:使用 Prettier 格式化代码。pnpm test:使用 Vitest 运行测试。pnpm check:使用 TypeScript 对代码进行类型检查。
许可证
MIT
Update on GitHub