Skip to main content

MaxCompute (ODPS) MCP Server for getting table information and DDL

Project description

MCP for ODPS

MaxCompute (ODPS) API工具,用于获取表的详细信息,包括表名、字段信息、分区信息和DDL。

环境变量配置

在使用本工具之前,请配置以下环境变量:

必需的环境变量

  • MAXCOMPUTE_PROJECT_NAME: MaxCompute项目名称

可选的环境变量

  • MAXCOMPUTE_SCHEMA_NAME: Schema名称(默认值:default
  • MAXCOMPUTE_BASE_URL: MaxCompute API基础URL(默认值:https://maxcompute.cn-hangzhou.aliyuncs.com

OAuth认证环境变量(如果需要OAuth认证)

  • OAUTH_CLIENT_ID: OAuth客户端ID
  • OAUTH_CLIENT_SECRET: OAuth客户端密钥
  • OAUTH_REDIRECT_URI: OAuth重定向URI
  • OAUTH_SCOPE: OAuth授权范围(默认值:odps.readonly

配置示例

# 在 .env 文件中配置
MAXCOMPUTE_PROJECT_NAME=your_project_name
MAXCOMPUTE_SCHEMA_NAME=default
MAXCOMPUTE_BASE_URL=https://maxcompute.cn-hangzhou.aliyuncs.com

# OAuth认证配置(可选)
OAUTH_CLIENT_ID=your_oauth_client_id
OAUTH_CLIENT_SECRET=your_oauth_client_secret
OAUTH_REDIRECT_URI=your_redirect_uri
OAUTH_SCOPE=odps.readonly

或者在命令行中设置:

export MAXCOMPUTE_PROJECT_NAME=your_project_name
export MAXCOMPUTE_SCHEMA_NAME=default
export MAXCOMPUTE_BASE_URL=https://maxcompute.cn-hangzhou.aliyuncs.com

# OAuth认证配置(可选)
export OAUTH_CLIENT_ID=your_oauth_client_id
export OAUTH_CLIENT_SECRET=your_oauth_client_secret
export OAUTH_REDIRECT_URI=your_redirect_uri
export OAUTH_SCOPE=odps.readonly

使用方法

获取表信息

# 使用全局配置获取表信息
result = await get_table_info(['table1', 'table2'])

API功能

  • 并发请求: 支持同时获取多个表的信息,提高查询效率
  • 完整信息: 返回表的完整信息,包括字段、分区、DDL等
  • 错误处理: 详细的错误信息和日志记录
  • JSON格式: 返回结构化的JSON数据

返回数据格式

{
  "success": [
    {
      "tableName": "表名",
      "projectName": "项目名",
      "schema": "schema名",
      "owner": "所有者",
      "type": "表类型",
      "creationTime": "创建时间",
      "lastModifiedTime": "最后修改时间",
      "lifecycle": "生命周期",
      "comment": "表注释",
      "createTableDDL": "建表DDL",
      "columns": [
        {
          "name": "字段名",
          "type": "字段类型",
          "comment": "字段注释",
          "isNullable": true
        }
      ],
      "partitionColumns": [
        {
          "name": "分区字段名",
          "type": "分区字段类型",
          "comment": "分区字段注释",
          "isNullable": false
        }
      ]
    }
  ],
  "failed": [
    {
      "tableName": "失败的表名",
      "error": "错误信息"
    }
  ]
}

🧪 测试

项目包含完整的集成测试客户端,用于验证所有功能:

运行测试

# 进入测试客户端目录
cd client

# 运行所有测试
python run_test.py

测试内容

  • get_table_info 工具功能测试
  • execute_sql 工具功能测试(开发中)
  • OAuth环境变量 配置测试
  • MCP连接 和通信测试

测试客户端使用Mock数据,无需真实的MaxCompute环境即可完成功能验证。详细说明请参考 client/README.md

开发

项目结构

mcp_for_odps/
├── application.py          # MCP工具主文件
├── component/
│   ├── __init__.py        # 组件导出
│   ├── token_manager.py   # OAuth认证管理
│   └── get_table_info.py  # 表信息获取API
├── client/                 # 测试客户端
│   ├── mcp_client.py      # 主测试客户端
│   ├── run_test.py        # 测试运行脚本
│   ├── config.json        # Mock数据配置
│   ├── test_config.env    # 测试环境变量
│   └── README.md          # 测试说明文档
├── main.py
├── pyproject.toml
└── README.md

依赖

  • httpx: HTTP客户端
  • mcp[cli]: MCP框架
  • openai: OpenAI客户端

注意事项

  1. 确保设置了正确的环境变量
  2. MaxCompute项目需要有相应的访问权限
  3. 网络环境需要能够访问MaxCompute API
  4. 建议在生产环境中使用适当的日志级别

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_for_odps-0.1.3.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_for_odps-0.1.3-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file mcp_for_odps-0.1.3.tar.gz.

File metadata

  • Download URL: mcp_for_odps-0.1.3.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for mcp_for_odps-0.1.3.tar.gz
Algorithm Hash digest
SHA256 80ad3dac13262725d2969a06f09671a4f288bcbc056287ec811ca76462660def
MD5 eebdb5747d5652c983c38d0c27da033a
BLAKE2b-256 1fcb81bc463967b2b771837fda67a63e9c8ce6fc817ddb18558b5adb83791222

See more details on using hashes here.

File details

Details for the file mcp_for_odps-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: mcp_for_odps-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for mcp_for_odps-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9652f6b7e620a1f267e36dc150e596cca2a0ff0cb0e29ff05a32b172d824839f
MD5 c614e94910f98e29b9e7e17bc5e514ed
BLAKE2b-256 1317b8fdfef177d0e6de398bcf2f90712412d051c29952bf7deab4f459ff6652

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page