About MCP 服务工具
MCP 服务工具 is a collection of MCP servers for calling Hugging Face and Dify APIs. It covers NLP, computer vision, and speech tasks as well as Dify app conversations, text generation, and conversation management.
Key features
- 01Hugging Face text and NLP tasks
- 02Image classification, segmentation, and captioning
- 03Speech recognition and zero-shot classification
- 04Dify chat and text generation
- 05Dify conversation history and listing
- 06Rename Dify conversations
Use cases
- 01Calling Hugging Face models for text or image tasks
- 02Transcribing audio with speech recognition
- 03Sending chat requests to Dify apps
- 04Reviewing or renaming Dify conversations
MCP support
The collection includes Hugging Face and Dify MCP servers that expose API operations as tools. Dify tools support chat, text generation, and conversation management; Hugging Face tools cover NLP, vision, and speech tasks.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEMCP 服务工具
这是一个 MCP(Model Context Protocol)服务工具集合,用于调用各种 AI 服务 API。
功能特点
Hugging Face MCP 服务
- 支持文本生成、分类、问答、摘要等 NLP 任务
- 支持图像分类、分割、图像到文本等 CV 任务
- 支持语音识别等语音处理任务
- 支持零样本学习分类任务
Dify MCP 服务 (新增)
- 支持对话型应用 API 调用
- 支持文本生成型应用 API 调用
- 支持对话历史管理
- 支持对话列表查询和管理
安装
首先,安装必要的依赖:
npm install
配置
在项目根目录创建 .env 文件,并添加以下配置:
# Hugging Face API 密钥(如果使用 Hugging Face 服务)
HUGGINGFACE_API_KEY=your_huggingface_api_key
# Dify API 配置(如果使用 Dify 服务)
DIFY_API_KEY=your_dify_api_key
DIFY_BASE_URL=your_dify_base_url
使用方法
启动 Dify MCP 服务
npm run start:dify
Hugging Face MCP 服务
import { createHuggingFaceMcpTool } from './src/hf_mcp';
// 创建工具实例
const hfTool = createHuggingFaceMcpTool('your_huggingface_api_key');
// 使用工具调用模型
async function example() {
const result = await hfTool.textGeneration(
'gpt2',
'人工智能正在改变世界,',
{ max_new_tokens: 50 }
);
console.log(result);
}
example();
Dify MCP 服务功能
Dify MCP 服务提供以下工具:
-
chat_with_dify:向 Dify 发送聊天消息并获取回复
- 参数:
base_url:Dify API 基础 URLapi_key:Dify API 密钥query:用户查询内容inputs:输入参数(可选)conversation_id:对话 ID(可选,用于继续对话)user:用户标识(可选)
- 参数:
-
generate_with_dify:使用 Dify 生成文本内容
- 参数:
base_url:Dify API 基础 URLapi_key:Dify API 密钥inputs:输入参数user:用户标识(可选)
- 参数:
-
get_conversation_history:获取 Dify 对话历史记录
- 参数:
base_url:Dify API 基础 URLapi_key:Dify API 密钥conversation_id:对话 IDuser:用户标识(可选)
- 参数:
-
list_conversations:获取 Dify 对话列表
- 参数:
base_url:Dify API 基础 URLapi_key:Dify API 密钥user:用户标识(可选)first:返回结果数量(可选,默认 20)
- 参数:
-
rename_conversation:重命名 Dify 对话
- 参数:
base_url:Dify API 基础 URLapi_key:Dify API 密钥conversation_id:对话 IDname:新对话名称user:用户标识(可选)
- 参数:
Dify API 使用示例
使用 Dify 聊天功能
// 向 Dify 发送聊天消息
const response = await difyClient.chatMessage(
"你好,请介绍一下自己", // 查询内容
{}, // 输入参数
"conversation_id_123", // 对话 ID(可选)
"user_123" // 用户标识(可选)
);
console.log(response.answer); // 输出 Dify 的回复
使用 Dify 文本生成功能
// 使用 Dify 生成文本
const response = await difyClient.completionMessage(
{ prompt: "写一篇关于人工智能的短文" }, // 输入参数
"user_123" // 用户标识(可选)
);
console.log(response.answer); // 输出生成的文本
Hugging Face 支持的功能
-
文本生成
await hfTool.textGeneration('gpt2', '输入文本', { max_new_tokens: 50 }); -
文本分类
await hfTool.textClassification('distilbert-base-uncased-finetuned-sst-2-english', '这是一段文本'); -
问答
await hfTool.questionAnswering('deepset/roberta-base-squad2', { question: '问题?', context: '包含答案的上下文' }); -
填充遮罩
await hfTool.fillMask('bert-base-uncased', 'Paris is the [MASK] of France.'); -
摘要生成
await hfTool.summarization('facebook/bart-large-cnn', '长文本内容'); -
文本翻译
await hfTool.translation('t5-base', '要翻译的文本'); -
图像分类
await hfTool.imageClassification('google/vit-base-patch16-224', imageBlob); -
图像分割
await hfTool.imageSegmentation('facebook/detr-resnet-50-panoptic', imageBlob); -
图像到文本
await hfTool.imageToText('nlpconnect/vit-gpt2-image-captioning', imageBlob); -
零样本图像分类
await hfTool.zeroShotImageClassification( 'openai/clip-vit-base-patch32', imageBlob, ['猫', '狗', '鸟'] ); -
零样本文本分类
await hfTool.zeroShotClassification( 'facebook/bart-large-mnli', '这是一段文本', ['类别1', '类别2', '类别3'], false ); -
语音识别
await hfTool.automaticSpeechRecognition('facebook/wav2vec2-base-960h', audioBlob);
注意事项
- 使用前需要先获取相应的 API 密钥
- 请注意 API 调用限制和费用
- Dify API 的具体参数和返回值可能因应用配置不同而有所差异
许可证
MIT
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.