mhlabs mcp工具
mcp名称:io.github。音乐学院侯赛因实验室/mhlabs_mcp_tools
🧠 mhlabs mcp工具
mhlabs-mcp-tools 是一个 模块化MCP工具服务器 使用 FastMCP.\ 它提供了一个 可扩展的人工智能工具生态系统 组织成功能类别(文本预处理、NLP组件、文档分析等),可以通过以下方式动态加载和提供服务 MCP(模型上下文协议) 通过 STDIO传输.
该项目是 MHLabs人工智能代理生态系统,旨在与 mhlabs-mcp-server, mhlabs-mcp-agents以及下游A2A代理框架。
______________________________________________________________________
特性
- FastMCP服务器:支持多种传输协议的纯FastMCP实现
- 工厂模式:可重复使用的MCP工具工厂,便于服务管理
- 基于域的组织:按业务领域组织的服务(人力资源、技术支持等)
- 认证:可选的Azure AD身份验证支持
- 多个传输:STDIO、HTTP(流式传输)和SSE传输支持
- VS代码集成:调试配置和开发设置
- 综合测试:使用pytest进行单元测试
- 灵活的配置:基于环境的配置管理
建筑
mhlabs_mcp_tools/
├── .gitignore
├── .vscode/
│ └── settings.json
├── CHANGELOG.md
├── LICENSE
├── README.md
├── docs/
│ └── index.md
├── examples/
│ ├── example_client.py
│ └── example_client_http.py
├── mkdocs.yml
├── pyproject.toml
├── requirements.txt
├── server.json
└── src/
├── __init__.py
├── main.py
└── mhlabs_mcp_tools/
├── __init__.py
├── core/
│ ├── __init__.py
│ ├── config.py
│ ├── constants.py
│ ├── factory.py
│ └── prompts.py
├── data/
│ ├── __init__.py
│ ├── external/
│ │ └── __init__.py
│ ├── interim/
│ │ └── __init__.py
│ ├── processed/
│ │ └── __init__.py
│ └── raw/
│ ├── __init__.py
│ ├── contractions_dict.json
│ ├── custom_substitutions.csv
│ ├── leftovers_dict.json
│ └── slang_dict.json
├── handlers/
│ ├── __init__.py
│ ├── custom_exceptions.py
│ └── output_generator.py
├── mcp_server.py
├── models/
│ └── __init__.py
├── nlp_components/
│ ├── __init__.py
│ └── nlp_model.py
├── services/
│ ├── __init__.py
│ ├── langchain_framework.py
│ └── spacy_extractor.py
└── text_preprocessing/
├── __init__.py
├── contractions.py
├── emo_unicode.py
├── slang_text.py
└── text_preprocessing.py可用服务
目前,该软件包分为三个主要模块:
NLP组件
| 组件类型 | 描述 |
|---|---|
| 标记化 | 文本标记化 |
| 词性标注 | |
| 词词形化 | |
| 词法 | 词形研究 |
| dep | 依赖关系解析 |
| ner | 命名实体识别 |
| norm | 文本规范化 |
2.文本预处理
该模块为用户提供了一套广泛的文本预处理工具:
| 功能 | 说明 |
|---|---|
| to_lower | 将文本转换为小写 |
| to_upper | 将文本转换为大写 |
| remove_number | 删除数字字符 |
| remove_itemized_bullet_and_numbering | 取消逐项/要点编号 |
| remove_url | 从文本中删除url |
| remove_punctuation | 删除标点符号 |
| remove_special_character | 删除特殊字符 |
| keep_alpha_numeric | 仅保留字母数字字符 |
| remove_whitespace | 删除多余的空格 |
| normalize_unicode | 规范unicode字符 |
| remove_stopword | 消除常见的停用词 |
| remove_freqwords | 删除频繁出现的单词 |
| remove_rarewords | 删除罕见词 |
| remove_email | 删除电子邮件地址 |
| remove_phone_number | 删除电话号码 |
| remove_ssn | 删除社会安全号码(ssn) |
| remove_credit_card_number | 删除信用卡号 |
| remove_emoji | 删除表情符号 |
| remove_emotcons | 删除表情符号 |
| convert_emoticons_to_words | 将表情符号转换为单词 |
| convert_emojis_to_words | 将表情符号转换为单词 |
| remove_html | 删除html标签 |
| chat_words_conversion | 将聊天语言转换为标准英语 |
| expand_contraction | 扩大收缩(例如,“不能”到“不能”) |
| tokenize_word | 标记单词 |
| tokenize_sentence | 将句子标记化 |
| stem_word | 词干 |
| 词形词 | 对单词进行lemmatize |
| preprocess_text | 将多个预处理步骤合并到一个函数中 |
快速开始
开发设置
- 克隆和导航:
cd src/mhlabs_mcp_tools- 再进行:
pip install -r requirements.txt- 配置环境:
cp .env.example .env
# Edit .env with your configuration- 启动服务器:
# Default STDIO transport (for local MCP clients)
python mcp_server.py
# HTTP transport (for web-based clients)
python mcp_server.py --transport http --port 9000
or
after installed mhlabs-mcp-tools
python -m mhlabs_mcp_tools.mcp_server --transport http --port 9000
# Using FastMCP CLI (recommended)
fastmcp run mcp_server.py -t streamable-http --port 9000 -l DEBUG
# Debug mode with authentication disabled
python mcp_server.py --transport http --debug --no-auth运输选项
1.STDIO传输(默认)
- 🔧 非常适合:本地工具、命令行集成、Claude Desktop
- 🚀 用途:
python mcp_server.py或python mcp_server.py --transport stdio
2.HTTP(流式)传输
- 🌐 非常适合:基于Web的部署、微服务、远程访问
- 🚀 用途:
python mcp_server.py --transport http --port 9000 - 🌐 网址:
http://127.0.0.1:9000/mcp/
3.苏格兰和南方能源公司运输部(已弃用)
- ⚠️ 仅支持旧版本-对新项目使用HTTP传输
- 🚀 用途:
python mcp_server.py --transport sse --port 9000
FastMCP CLI使用情况
# Standard HTTP server
fastmcp run mcp_server.py -t streamable-http --port 9000 -l DEBUG
# With custom host
fastmcp run mcp_server.py -t streamable-http --host 0.0.0.0 --port 9000 -l DEBUG
# STDIO transport (for local clients)
fastmcp run mcp_server.py -t stdio
# Development mode with MCP Inspector
fastmcp dev mcp_server.py -t streamable-http --port 9000VS代码开发
- 在VS代码中打开:
code .- 使用调试配置:
- Debug MCP Server (STDIO):使用STDIO传输运行 - Debug MCP Server (HTTP):使用HTTP传输运行 - Debug Tests:运行测试套件
配置
环境变量
创建一个 .env 文件基于 .env.example:
# Server Settings
MCP_HOST=0.0.0.0
MCP_PORT=9000
MCP_DEBUG=false
MCP_SERVER_NAME=MHLABS MCP Server
# Authentication Settings
MCP_ENABLE_AUTH=true
AZURE_TENANT_ID=your-tenant-id-here
AZURE_CLIENT_ID=your-client-id-here
AZURE_JWKS_URI=https://login.microsoftonline.com/your-tenant-id/discovery/v2.0/keys
AZURE_ISSUER=https://sts.windows.net/your-tenant-id/
AZURE_AUDIENCE=api://your-client-id认证
当 MCP_ENABLE_AUTH=true,服务器需要Azure AD承载令牌。使用适当的设置配置您的Azure应用程序注册。
对于开发,set MCP_ENABLE_AUTH=false 禁用身份验证。
添加新服务
- 创建服务类:
from core.factory import MCPToolBase, Domain
class MyService(MCPToolBase):
def __init__(self):
super().__init__(Domain.MY_DOMAIN)
def register_tools(self, mcp):
@mcp.tool(tags={self.domain.value})
async def my_tool(param: str) -> str:
# Tool implementation
pass
@property
def tool_count(self) -> int:
return 1 # Number of tools- 在服务器中注册:
# In mcp_server.py (gets registered automatically from services/ directory)
factory.register_service(MyService())- 添加域 (如果是新的):
# In core/factory.py
class Domain(Enum):
# ... existing domains
MY_DOMAIN = "my_domain"MCP客户端使用情况
Python客户端
import asyncio
from fastmcp import Client
client = Client("http://localhost:9000/mcp")
async def main():
async with client:
tools = await client.list_tools()
# tools -> list[mcp.types.Tool]
# print(tools)
for tool in tools:
print(f"Tool: {tool.name}")
result = await client.call_tool("textprep.expand_contraction", {"input_text": "The must've SSN is 859-98-0987. The employee's phone number is 555-555-5555."})
print("Result:", result)
asyncio.run(main())命令行测试
# Test the server is running
curl http://localhost:9000/mcp/
# With FastMCP CLI for testing
fastmcp dev mcp_server.py -t streamable-http --port 9000快速测试
测试STDIO传输:
# Start server in STDIO mode
python mcp_server.py --debug --no-auth
# Test with client_example.py
python client_example.py测试HTTP传输:
# Start HTTP server
python mcp_server.py --transport http --port 9000 --debug --no-auth
# Test with FastMCP client
python -c "
from fastmcp import Client
import asyncio
async def test():
async with Client('http://localhost:9000/mcp') as client:
result = await client.call_tool("textprep.expand_contraction", {"input_text": "The must've SSN is 859-98-0987. The employee's phone number is 555-555-5555."})
print(result)
asyncio.run(test())
"使用FastMCP CLI进行测试:
# Start with FastMCP CLI
fastmcp run mcp_server.py -t streamable-http --port 9000 -l DEBUG
# Server will be available at: http://127.0.0.1:9000/mcp/故障排除
常见问题
- 导入错误:确保您位于正确的目录中,并且安装了依赖项
- 身份验证错误:检查您的Azure AD配置和令牌
- 端口冲突:如果9000已在使用中,请更改配置中的端口
- 缺少fastmcp:安装
pip install fastmcp
调试模式
启用调试模式以进行详细日志记录:
python mcp_server.py --debug --no-auth或设置在环境中:
MCP_DEBUG=true服务器参数
usage: mcp_server.py [-h] [--transport {stdio,http,streamable-http,sse}]
[--host HOST] [--port PORT] [--debug] [--no-auth]
MHLABS MCP Server
options:
-h, --help show this help message and exit
--transport, -t Transport protocol (default: stdio)
--host HOST Host to bind to for HTTP transport (default: 127.0.0.1)
--port, -p PORT Port to bind to for HTTP transport (default: 9000)
--debug Enable debug mode
--no-auth Disable authentication______________________________________________________________________
📄 许可证
麻省理工学院许可证©2025 侯赛因博物馆实验室
______________________________________________________________________
🤝 贡献
- 遵循现有的代码结构和模式
- 添加新功能的测试
- 更新新功能的文档
- 使用提供的VS代码配置进行开发
______________________________________________________________________
🧠 了解更多
- MCP协议: https://modelcontextprotocol.io
- FastMCP GitHub:
- LangGraph集成指南 (即将推出)
______________________________________________________________________
💡 小贴士
如果你想嵌入 mhlabs-mcp-tools 变成一个更大的基于MCP的编排器:
from fastmcp import StdioServerParameters
server_params = StdioServerParameters(
command="python",
args=["-m", "mhlabs_mcp_tools.server"],
//env={"MHLABS_MCP_CATEGORY": "textprep,nlp"}
)______________________________________________________________________
与开发❤️ 通过 侯赛因博物馆实验室
