ODPS MCP 服务配置
环境变量
在运行前需要设置以下环境变量:
# 阿里云 Access Key
export ALIYUN_ACCESS_KEY_ID="your_access_key_id"
export ALIYUN_ACCESS_KEY_SECRET="your_access_key_secret"
# ODPS 端点和项目
export ALIYUN_ODPS_ENDPOINT="http://service.cn-beijing.maxcompute.aliyun.com/api"
export ALIYUN_ODPS_PROJECT="your_project_name"安装依赖
pip install pyodps使用方式
1. 直接测试
python odps_mcp_server.py --test2. 通过 MCP 客户端运行
在 MCP 客户端的配置文件(如 mcp-servers.json)中添加:
{
"odps": {
"command": "python",
"args": ["/odps_mcp_server.py"],
"env": {
"ALIYUN_ACCESS_KEY_ID": "your_key",
"ALIYUN_ACCESS_KEY_SECRET": "your_secret",
"ALIYUN_ODPS_PROJECT": "your_project",
"ALIYUN_ODPS_ENDPOINT": "your_endpoint"
}
}
}将 ` 替换为 odps_mcp_server.py` 的实际绝对路径。3. 直接 Python 使用
from odps_mcp_server import ODPSClient
client = ODPSClient()
# 查询
result = client.execute_sql("SELECT * FROM table_name LIMIT 10")
print(result)
# 列出表
tables = client.list_tables()
print(tables)
# 表结构
schema = client.get_table_schema("table_name")
print(schema)可用工具
odps_execute_sql- 执行 SQL 查询odps_list_tables- 列出所有表odps_table_schema- 获取表结构
