DeepDiff MCP服务器
MCP(模型上下文协议)服务器 DeepDiff 图书馆。此服务器允许您通过模型上下文协议使用DeepDiff功能,从而允许从任何MCP客户端与DeepDiff进行交互。
安装
使用pip
pip install deepdiff-mcp使用紫外线(推荐)
uv pip install deepdiff-mcp用法
运行服务器
您可以通过多种方式运行DeepDiff MCP服务器:
作为命令行工具
# Using stdio transport (default)
deepdiff-mcp
# Using HTTP transport
deepdiff-mcp --transport http --host 127.0.0.1 --port 8000
# Using SSE transport
deepdiff-mcp --transport sse --host 127.0.0.1 --port 8000作为Python模块
from deepdiff_mcp import create_server
# Create a DeepDiff MCP server
server = create_server("My DeepDiff Server")
# Run the server with stdio transport (default)
server.run()
# Or with HTTP transport
server.run(transport="http", host="127.0.0.1", port=8000, path="/mcp")
# Or with SSE transport
server.run(transport="sse", host="127.0.0.1", port=8000)连接到服务器
您可以使用任何MCP客户端连接到服务器。以下是使用FastMCP的示例:
import asyncio
from fastmcp import Client
async def main():
# Connect to a DeepDiff MCP server running as a subprocess
async with Client("deepdiff-mcp") as client:
# List available tools
tools = await client.list_tools()
print(f"Available tools: {[tool.name for tool in tools]}")
# Compare two dictionaries
t1 = {"a": 1, "b": 2}
t2 = {"a": 1, "b": 3, "c": 4}
result = await client.call_tool("compare", {"t1": t1, "t2": t2})
print(f"Differences: {result.text}")
if __name__ == "__main__":
asyncio.run(main())可用工具
compare_files-直接比较两个CSV、Excel或JSON文件
DeepDiff MCP服务器提供以下工具:
compare-比较两个对象并返回它们的差异get_deep_distance-计算两个物体之间的深度距离search-在对象中搜索项目grep-使用类似grep的行为在对象中搜索项目hash_object-根据对象的内容对其进行哈希处理create_delta-创建一个可以将一个对象转换为另一个对象的增量apply_delta-应用增量来变换对象extract_path-使用路径从对象中提取值
文档
有关DeepDiff的更多信息,请参阅 DeepDiff文档.
有关MCP和FastMCP的更多信息,请参阅 模型上下文协议 和 FastMCP文档.
比较 CSV 和 Excel 文件
DeepDiff MCP 支持直接比较 CSV、Excel 和 JSON 文件:
import asyncio
from fastmcp import Client
async def main():
async with Client("deepdiff-mcp") as client:
# Compare dois arquivos CSV
result = await client.call_tool(
"compare_files",
{
"file1_path": "caminho/para/arquivo1.csv",
"file2_path": "caminho/para/arquivo2.csv",
"ignore_order": True # Ignorar a ordem das linhas
}
)
print(f"Diferenças: {result.text}")
# Compare arquivos Excel
excel_result = await client.call_tool(
"compare_files",
{
"file1_path": "caminho/para/arquivo1.xlsx",
"file2_path": "caminho/para/arquivo2.xlsx"
}
)
print(f"Diferenças: {excel_result.text}")
if __name__ == "__main__":
asyncio.run(main())此功能对于数据分析和管道数据完整性检查尤其有用。
