Oracle APEX应用自然语言构建服务

通过自然语言指令构建、检查和修改Oracle APEX 24.2应用程序的MCP服务器,支持Claude/GPT/Gemini等AI客户端。

  • by TechFernandesLTDA
  • Python
  • 本地部署
  • 15 星标
  • 更新于
在 GitHub 查看 TechFernandesLTDA/apex-mcp

使用说明

apex-mcp——Oracle apex mcp服务器

构建、检查和修改 Oracle APEX 24.2 通过自然语言的应用程序。 使用 Claude、GPT、Gemini、游标、VS代码,以及任何兼容MCP的AI客户端。


概述

顶点mcp 是一个 模型上下文协议(MCP) 服务器 这暴露了 86工具 用于通过AI助手构建Oracle APEX 24.2应用程序。 它基于FastMCP 3.x和Python 3.11+构建,通过 oracledb 瘦驱动程序(mTLS钱包——不需要Oracle即时客户端)。

您无需在APEX App Builder UI中导航,只需描述您想要什么,AI就会做什么 工作:创建应用程序、生成CRUD页面、添加JET图表、配置身份验证方案、导出 页面、生成REST端点等。

┌─────────────────────────────────────────────────────────────────┐
│  AI Client (Claude / GPT / Gemini / Cursor / VS Code)           │
│                                                                  │
│  "Create a full HR app from the EMPLOYEES table"                 │
└────────────────────────────┬────────────────────────────────────┘
                             │ MCP (stdio or HTTP)
                             ▼
┌─────────────────────────────────────────────────────────────────┐
│  apex-mcp server (FastMCP 3.x, Python 3.11+)                    │
│  86 tools across 15 categories                                   │
└────────────────────────────┬────────────────────────────────────┘
                             │ oracledb (mTLS)
                             ▼
┌─────────────────────────────────────────────────────────────────┐
│  Oracle Autonomous Database 23ai                                 │
│  wwv_flow_imp_page → APEX 24.2 App Builder                      │
└─────────────────────────────────────────────────────────────────┘

支持的AI客户端

客户端 传输 配置文件 安装指南
克劳德代码 站立 .mcp.json docs/setup-claude.md
克劳德桌面版 站立 claude_desktop_config.json docs/setup-claude.md
GPT/OpenAI代理SDK 可流式传输的http Python代码 docs/setup-gpt.md
谷歌Gemini CLI 站立 .gemini/settings.json docs/setup-gemini.md
光标IDE 站立 .cursor/mcp.json docs/setup-cursor.md
VS代码/GitHub副本 stdio或http .vscode/mcp.json docs/setup-vscode.md
ZAI(视觉伴侣) n/a 并排 docs/setup-zai.md

快速开始

1.安装

git clone https://github.com/your-org/apex-mcp
cd apex-mcp
pip install -e .

2.配置

复制并编辑AI客户端的配置文件:

克劳德代码 --创建 .mcp.json 在项目根目录中:

{
  "mcpServers": {
    "apex-mcp": {
      "command": "python",
      "args": ["-m", "apex_mcp"],
      "cwd": "/path/to/apex-mcp",
      "env": {
        "ORACLE_DB_USER": "YOUR_SCHEMA",
        "ORACLE_DB_PASS": "YOUR_PASSWORD",
        "ORACLE_DSN": "YOUR_DSN",
        "ORACLE_WALLET_DIR": "/path/to/wallet",
        "ORACLE_WALLET_PASSWORD": "YOUR_WALLET_PW",
        "APEX_WORKSPACE_ID": "YOUR_WORKSPACE_ID",
        "APEX_SCHEMA": "YOUR_SCHEMA",
        "APEX_WORKSPACE_NAME": "YOUR_WORKSPACE"
      }
    }
  }
}

其他客户请参见 支持的AI客户端 上面。

3.验证

在克劳德代码中:

/mcp

你应该看看 apex-mcp 与86个工具相连。

然后:

Connect to Oracle and list all APEX applications in the workspace.

运输方式

apex mcp支持三种传输模式,通过以下方式控制 --transport 标志或环境变量。

stdio(默认--本地客户端)

python -m apex_mcp                        # default
python -m apex_mcp --transport stdio      # explicit
apex-mcp                                  # if installed via pip

最适合:克劳德代码、克劳德桌面、光标、VS代码、Gemini CLI。

流式HTTP(远程/多客户端)

apex-mcp --transport streamable-http --port 8000
# Server available at: http://127.0.0.1:8000/mcp

最适合:OpenAI代理SDK、代码空间、远程设置、多个客户端。

SSE(服务器发送事件)

apex-mcp --transport sse --port 9000
# Server available at: http://127.0.0.1:9000/sse

最适合:特别需要SSE运输的客户。

环境变量

所有CLI标志都有等效的环境变量(优先级低于CLI参数):

变量 CLI标志 默认值
MCP_TRANSPORT --transport stdio
MCP_HOST --host 127.0.0.1
MCP_PORT --port 8000
MCP_PATH --path /mcp (http)或 /sse

Oracle连接变量

变量 描述
ORACLE_DB_USER Oracle架构名称
ORACLE_DB_PASS Oracle架构密码
ORACLE_DSN TNS别名或连接字符串
ORACLE_WALLET_DIR 包含钱包文件的目录(cwallet.sso等等)
ORACLE_WALLET_PASSWORD 钱包加密密码
APEX_WORKSPACE_ID 数字APEX工作区ID
APEX_SCHEMA 拥有APEX对象的架构
APEX_WORKSPACE_NAME APEX工作区名称

工具参考

15个类别的86个工具。

连接和SQL

工具 说明
apex_connect 连接到Oracle ADB(mTLS钱包)
apex_run_sql 执行任何SELECT/DML/DDL语句
apex_status 显示连接状态和会话信息

应用程序

工具 说明
apex_create_app 创建新的APEX应用程序(开始导入会话)
apex_finalize_app 完成并提交应用程序
apex_list_apps 列出工作区中的所有应用程序
apex_delete_app 删除应用程序
apex_get_app_details 获取完整的应用程序配置
apex_validate_app 验证应用程序结构(主页、孤立项目等)
apex_dry_run_preview 切换模拟运行模式(记录SQL而不执行)
apex_describe_page 以人类可读的形式描述页面的组件

页面

工具 说明
apex_add_page 向应用程序添加新页面
apex_list_pages 列出所有页面
apex_get_page_details 获取完整页面详细信息
apex_update_page 更新页面属性
apex_delete_page 删除页面
apex_copy_page 将页面复制到新ID
apex_diff_app 比较更改前后的应用程序结构

区域和组件

工具 说明
apex_add_region 添加区域(HTML、IR、报告等)
apex_list_regions 列出页面上的区域
apex_update_region 更新区域属性
apex_delete_region 删除区域
apex_add_interactive_grid 添加交互式网格区域
apex_add_master_detail 添加主细节区域对
apex_add_notification_region 添加通知/警报区域
apex_add_timeline 添加时间线区域
apex_add_breadcrumb 添加面包屑导航区域
apex_add_faceted_search 添加分面搜索区域
apex_add_file_upload 添加文件上传组件
apex_add_search_bar 添加搜索栏组件

项目(表单字段)

工具 说明
apex_add_item 添加表单项(文本、选择、日期等)
apex_list_items 在页面上列出项目
apex_update_item 更新项目属性
apex_delete_item 删除项目
apex_bulk_add_items 在一次通话中添加多个项目
apex_add_item_validation 向项目添加服务器端验证
apex_add_item_computation 添加计算以设置项目值

按钮和流程

工具 说明
apex_add_button 向页面/区域添加按钮
apex_delete_button 删除按钮
apex_add_process 添加页面进程(PL/SQL、DML、分支)
apex_list_processes 列表页面进程

动态操作

工具 说明
apex_add_dynamic_action 添加动态操作(客户端事件处理程序)
apex_list_dynamic_actions 列出页面上的动态操作

图表和可视化

工具 说明
apex_add_jet_chart 添加Oracle JET图表(条形图、折线图、饼图等)
apex_add_gauge 添加仪表/刻度盘
apex_add_funnel 添加漏斗图
apex_add_sparkline 添加火花线图
apex_add_metric_cards 添加具有渐变样式的度量/KPI卡
apex_add_calendar 添加日历区域
apex_add_chart_drilldown 将深入行为添加到图表中

共享组件

工具 说明
apex_add_lov 添加值列表(静态或动态)
apex_list_lovs 列出应用程序中的所有LOV
apex_add_auth_scheme 添加授权方案
apex_list_auth_schemes 列出授权方案
apex_add_nav_item 添加导航菜单项
apex_add_app_item 添加应用程序级项(全局变量)
apex_add_app_process 添加应用程序级流程

架构检查

工具 说明
apex_list_tables 列出架构中的Oracle表/视图
apex_describe_table 描述列、类型、PK、FK(带缓存)
apex_detect_relationships 自动检测表之间的FK关系

发电机(高级)

工具 说明
apex_generate_crud 为表生成完整的CRUD(列表+表单页面)
apex_generate_dashboard 生成带有图表的仪表板
apex_generate_login 生成登录页面
apex_generate_report_page 生成格式化的报告页面
apex_generate_wizard 生成一个多步骤向导
apex_generate_analytics_page 生成一个包含多个图表的分析页面
apex_generate_from_schema 从多个表生成完整的应用程序
apex_generate_modal_form 生成模态表单对话框
apex_generate_rest_endpoints 为表生成ORDS REST端点

JavaScript

工具 说明
apex_add_page_js 添加页面级JavaScript
apex_add_global_js 添加应用级全局JavaScript
apex_add_global_css 添加应用级CSS
apex_add_page_css 添加页面级CSS
apex_generate_ajax_handler 生成AJAX回调过程

DevOps和批处理

工具 说明
apex_export_page 将页面导出为SQL(用于版本控制)
apex_generate_docs 为应用程序生成Markdown文档
apex_begin_batch 开始批处理操作(将多个SQL语句排队)
apex_commit_batch 在一次往返中执行批处理队列
apex_preview_page 预览页面结构(不打开浏览器)

设置和验证

工具 说明
apex_setup_guide 获取此工作区的设置说明
apex_check_requirements 验证是否满足所有要求
apex_check_permissions 验证Oracle授权和APEX访问权限
apex_fix_permissions 自动修复常见权限问题

用户

工具 说明
apex_create_user 创建APEX工作区用户
apex_list_users 列出工作区用户

代码示例

示例1:模式中的完整应用程序(单个命令)

# Uses apex_generate_from_schema internally
# Prompt: "Generate a full app from tables EMPLOYEES, DEPARTMENTS, JOBS"
# Result: App with CRUD pages, dashboard, navigation — in ~10 seconds

示例2:增量构建

1. apex_connect()
2. apex_create_app(app_id=200, app_name="Inventory", home_page=1)
3. apex_add_page(page_id=1, page_name="Dashboard", page_mode="Normal")
4. apex_add_region(page_id=1, region_name="KPIs", region_type="STATIC")
5. apex_add_metric_cards(page_id=1, region_id=..., metrics=[...])
6. apex_generate_crud(table_name="PRODUCTS", start_page_id=10)
7. apex_add_nav_item("Dashboard", app_id=200, page_id=1, icon="fa-home")
8. apex_add_nav_item("Products", app_id=200, page_id=10, icon="fa-box")
9. apex_finalize_app()

示例3:OpenAI代理SDK

import asyncio
from agents import Agent, Runner
from agents.mcp import MCPServerStreamableHttp

async def main():
    # apex-mcp must be running: apex-mcp --transport streamable-http
    async with MCPServerStreamableHttp(url="http://127.0.0.1:8000/mcp") as apex:
        agent = Agent(
            name="APEX Developer",
            instructions="Build Oracle APEX apps using apex-mcp tools.",
            mcp_servers=[apex],
        )
        result = await Runner.run(
            agent,
            "Connect to Oracle and generate a CRUD app for the ORDERS table."
        )
        print(result.final_output)

asyncio.run(main())

示例4:批处理操作

apex_begin_batch()
# ... add many regions, items, processes ...
apex_commit_batch(rollback_on_error=True)
# All statements execute in one round-trip; rolls back on any error

示例5:干运行模式

apex_dry_run_preview(enabled=True)
apex_generate_crud(table_name="EMPLOYEES")
# Logs all SQL without executing — useful for review before committing
apex_dry_run_preview(enabled=False)

建筑

apex_mcp/
├── server.py          Entry point — FastMCP 3.x, argparse (stdio/http/sse)
├── __main__.py        Enables `python -m apex_mcp`
├── __init__.py        Version: 0.2.0
├── config.py          Constants (APEX version, workspace ID, date format)
├── db.py              ConnectionManager singleton — mTLS, retry, batch, dry-run
├── ids.py             Sequential ID generator (base 8_900_000_000_000_000)
├── session.py         ImportSession — tracks pages, regions, items, buttons
├── templates.py       Hardcoded Universal Theme 42 template IDs
├── validators.py      Input validation (page IDs, SQL, chart types, table names)
├── utils.py           Shared helpers (_esc, _blk, _sql_to_varchar2)
└── tools/
    ├── sql_tools.py       apex_connect, apex_run_sql, apex_status
    ├── app_tools.py       apex_create_app, apex_finalize_app, ...
    ├── page_tools.py      apex_add_page, apex_list_pages
    ├── component_tools.py apex_add_region, apex_add_item, apex_add_button, ...
    ├── shared_tools.py    apex_add_lov, apex_add_auth_scheme, ...
    ├── schema_tools.py    apex_list_tables, apex_describe_table, ...
    ├── generator_tools.py apex_generate_crud, apex_generate_dashboard, ...
    ├── js_tools.py        apex_add_page_js, apex_add_global_js, ...
    ├── inspect_tools.py   apex_get_app_details, apex_update_*, apex_delete_*, ...
    ├── user_tools.py      apex_create_user, apex_list_users
    ├── setup_tools.py     apex_setup_guide, apex_check_requirements, ...
    ├── validation_tools.py apex_add_item_validation, apex_add_item_computation
    ├── visual_tools.py    apex_add_jet_chart, apex_add_gauge, ...
    ├── advanced_tools.py  apex_generate_report_page, apex_generate_wizard, ...
    └── devops_tools.py    apex_generate_rest_endpoints, apex_export_page, ...

APEX创建是如何工作的

apex-mcp通过生成和执行来创建apex应用程序 wwv_flow_imp_page.* PL/SQL直接调用Oracle数据库——与APEX使用的机制相同 自己的进出口系统。这完全绕过了App Builder UI,完全 与APEX 24.2.13/环球主题42兼容。

HTTP传输说明

使用时 --transport streamable-http 或 --transport sse,apex mcp是一个 单用户服务器: ImportSession singleton意味着只有一个活动导入 会话一次存在。对于多用户场景,运行单独的服务器实例 在不同的港口。


已知限制

限制 详细信息
单个导入会话 只有一个 apex_create_app → apex_finalize_app 一次序列
无HTTP身份验证 将HTTP传输绑定到 127.0.0.1 (默认);添加远程访问的反向代理
仅限APEX 24.2 wwv_flow_imp_page API是特定于版本的;未在APEX 23.x或25.x上测试
需要Oracle mTLS 不支持TLS直接连接(需要钱包)
许可仪器内容 TEA_QUESTOES / TEA_OPCOES_RESPOSTA 表为空(内容已获得许可)

需求

组件 版本
Python 3.11+
FastMCP 3.0.0+
oracledb 2.0.0+
Oracle APEX 24.2(通用主题42)
Oracle数据库 19c+(在ADB 23ai上测试)
Oracle钱包 mTLS连接需要

无需Oracle即时客户端 oracledb 瘦驱动程序本机处理mTLS。


故障排除

连接问题

错误 原因 解决方案
ORA-12541: no listener 错误的DSN 检查 ORACLE_DSN 与中的TNS别名匹配 tnsnames.ora
ORA-28759: failure to open file 钱包路径错误 ORACLE_WALLET_DIR 必须包含 cwallet.sso
DPY-6005: cannot connect to database 钱包密码错误 检查 ORACLE_WALLET_PASSWORD
ModuleNotFoundError: apex_mcp 未安装 运行 pip install -e . 来自apex mcp目录

APEX问题

错误 原因 解决方案
ORA-20987: APEX - Application not found app_id或工作区错误 检查 APEX_WORKSPACE_ID 并运行 apex_list_apps
ORA-01403: no data found 在项目创建过程中 缺失 p_attributes 在DatePicker上 在v0.2.0中已修复--更新到最新版本
PLS-00306: wrong number of arguments 过程参数名称错误 使用 p_process_success_message 不 p_success_message
标准页面上未显示按钮 区域位置错误 使用内容区域位置(CLOSE/CREATE),而不是对话框页脚

HTTP传输问题

问题 解决方案
ConnectionRefusedError 使用启动服务器 apex-mcp --transport streamable-http 首先
404 Not Found 在 / 默认路径为 /mcp;使用 curl http://127.0.0.1:8000/mcp
OpenAI SDK无法连接 确保 MCPServerStreamableHttp URL匹配 --path 设置

运行测试

cd apex-mcp
pip install -e ".[dev]"

# Unit tests (no database required)
pytest tests/ -v -m "not integration"

# All tests including integration (requires live Oracle connection)
pytest tests/ -v

该测试套件包含51个单元测试,涵盖工具、验证器和生成器。


演示脚本

脚本 描述
demos/build_app100.py TEA临床评估应用程序(15页,46项)
demos/build_app203.py 带有JET图表和度量卡的分析仪表板
demos/build_app204.py 架构后台(8个表,17页,得分100/100)
demos/build_app205.py 评估向导(4步向导、CRUD、仪表板、9s构建)
demos/demo_rest_endpoints.py 5张桌子→ 25 ORDS端点在1秒内
demos/demo_generate_docs.py 自动为应用程序生成Markdown文档

运行任何演示(需要实时Oracle连接):

python demos/build_app205.py

贡献

  1. 分叉存储库
  2. 创建要素分支
  3. 在中添加新工具的测试 tests/
  4. 确保 pytest tests/ -m "not integration" 通过
  5. 提交拉取请求

添加新工具

  1. 将该功能添加到相应的 tools/*.py 模块
  2. 在中注册 server.py 随着 mcp.tool()(function_name)
  3. 在中添加单元测试 tests/
  4. 更新此README中的工具参考部分

许可证

麻省理工学院——见 许可证 了解详情。


pt-BR: 这个MCP服务器是为TEA(国家Unimed)破坏平台项目构建的, 使用 Oracle APEX 24.2 + Oracle ADB 23ai。对于生产环境的详细配置, 查看或 CLAUDE.md 项目的根源。