在几秒钟内将任何Python库或本地脚本转换为LLM工具。
allbemcp是一个高性能的网桥,可以立即将任何Python环境(无论是标准PyPI库还是您自己的自定义代码)作为模型上下文协议(MCP)服务器公开。它使大型语言模型(Claude、ChatGPT等)能够执行本地函数、操纵数据帧、管理有状态对象,并安全高效地与系统交互。
基于最新 FastMCP+流式HTTP 运行时,与Claude Desktop、LangChain和Cursor实现最大兼容性。
安装
pip install allbemcp使用场景
allbemcp支持两个主要用例:公开公共库和公开您自己的自定义业务逻辑。
1.公开公共图书馆
暴露 pandas, numpy,或使用单个命令将任何其他已安装的库添加到LLM中。allbemcp自动处理依赖项安装和API生成。
# Install, generate, and serve in one go
allbemcp start pandas
# Explicit transport selection
allbemcp start pandas --transport streamable-http
allbemcp start pandas --transport stdio2.暴露自定义代码
allbemcp将您的本地Python脚本视为一级公民。它解析类型提示、文档字符串和类结构,以生成高质量的工具定义。
步骤1:创建脚本(例如。, my_tools.py)
# my_tools.py
from typing import List
def calculate_bmi(weight_kg: float, height_m: float) -> float:
"""
Calculate Body Mass Index (BMI).
Args:
weight_kg: Weight in kilograms.
height_m: Height in meters.
"""
return round(weight_kg / (height_m ** 2), 2)
class BankAccount:
"""A stateful class example."""
def __init__(self, owner: str):
self.owner = owner
self.balance = 0
def deposit(self, amount: float) -> str:
self.balance += amount
return f"Deposited ${amount}. New balance: ${self.balance}"
# Factory function to create instances
def open_account(owner: str) -> BankAccount:
return BankAccount(owner)步骤2:启动服务器
# allbemcp detects the file in your current directory
allbemcp start my_tools
# FastMCP 3.x is enabled by default in generated requirements
allbemcp generate my_tools --use-fastmcpLLM现在可以调用 calculate_bmi 直接。此外,如果LLM调用 open_account,allbemcp自动管理返回的 BankAccount 实例,允许LLM对以下对象进行后续调用 deposit 关于那个特定的对象。
客户端配置
使用您的工具 克劳德桌面 或其他MCP客户端,将相应的配置添加到您的 claude_desktop_config.json.
对于图书馆(例如pandas):
{
"mcpServers": {
"pandas": {
"command": "uv",
"args": ["run", "allbemcp", "start", "pandas"]
}
}
}对于自定义代码(例如my_tools):
{
"mcpServers": {
"my_tools": {
"command": "uv",
"args": ["run", "allbemcp", "start", "my_tools"],
"cwd": "/absolute/path/to/your/script/directory"
}
}
}主要特点
零配置反思
自动检查Python包或本地模块,提取公共API,并生成完全兼容的MCP服务器。不需要手动模式定义(YAML/JSON)。
状态对象管理
与标准的无状态工具不同,allbemcp支持面向对象的工作流:
- 实例持久性:当函数返回一个类实例时,它会存储在内存中。
- 方法链:LLM可以通过生成的
object_id. - 非常适合:数据库连接、游戏状态、模拟环境和基于会话的工作流。
智能序列化引擎
LLM难以处理复杂的对象。allbemcp会自动处理它们:
- 数据框架:根据大小转换为markdown或JSON预览。
- 图像:使用资源链接自动编码或保存到临时存储。
- 遍历器:自动消耗和汇总。
本地和安全
完全在您的机器上运行。没有数据离开您的网络。您可以控制主机绑定(默认 127.0.0.1)以及执行环境。
高级用法
检查图书馆
在生成代码之前,检查哪些函数将被公开并查看其质量分数:
allbemcp inspect numpy仅生成
在不运行服务器代码的情况下生成服务器代码(对审计或自定义很有用):
allbemcp generate matplotlib --output-dir ./my-server许可证
该项目根据 AGPL v3许可证.
