
在Part 3里聊了可观测性,这篇说说自动化这座大山怎么爬。
Azure APIM MCP 现在还是预览版,这意味着什么?你的基础设施即代码(IaC)流水线直接抓瞎:
现实就是这么残酷:标准 IaC 工具一个都用不了。要么手动在 Azure Portal 里点点点,要么自己造轮子做自动化。
但在你冲动地去写 REST API 脚本之前,先聊聊为什么这个问题值得关注,以及它对你的架构意味着什么。
大多数 IaC 缺口都是小麻烦,写几行 REST API 调用,打包成脚本,丢到流水线里跑,齐活。
MCP 不一样,原因如下:
AI 智能体(Agent)会读取你的 API 描述。这些描述直接变成工具定义,决定了大语言模型什么时候、怎么调用你的接口。描述写得烂?智能体理解偏差。摘要误导?调用错接口。安全注意事项没写?数据直接泄漏。
这是个披着自动化外衣的治理问题。
没有proper的治理机制:
这不是 Terraform 部署虚拟机失败的问题。这是让 AI 智能体直接访问你的业务逻辑,却没有proper的监管。
在担心自动化工具之前,先把这些问题想清楚:
这是 GitOps 的地盘。不是因为 Kubernetes 或者 Helm Chart,而是因为我们需要:
核心思路:OpenAPI 规范就是你的配置文件。
paths: /users/{userId}/profile: get: operationId: getUserProfile summary: "Retrieve user profile information" description: "Get comprehensive profile data for the authenticated user including preferences, settings, and basic account information. This tool respects user privacy and only returns data the user has permission to access." x-mcp-enabled: true # 治理标记 parameters: - name: userId in: path required: true description: "User identifier - must match authenticated user" schema: type: string
那个 x-mcp-enabled: true 标记是治理元数据,不只是个技术开关。它说明:
没这个标记 = 不暴露给 MCP。就这么简单。
聊聊怎么填补 IaC 的空白,在 ASO 追上之前。
提前声明:这些是我们正在探索的方案,不是生产验证过的解决方案。都是基于几个月折腾 APIM MCP 的经验加上几年的 GitOps 积累,当作架构思路看就行。
思路:搞个独立仓库,轮询 APIM 实例,检测带 x-mcp-enabled 标记的 API,然后应用 MCP overlay。
特点:
x-mcp-enabled 的 API 才会被转换代价:
思路:用 ArgoCD PostSync 钩子,在 API 部署之后检测 MCP 启用的 API,然后做转换。
特点:
代价:
思路:Maven 插件或者构建工具生成两份输出:标准 API Spec + MCP Overlay 配置。
特点:
代价:
不管选哪个方案,核心原则都一样:
x-mcp-enabled 显式选择加入)选哪个?看你的组织情况:
拆解一下 MCP 暴露场景下治理到底意味着什么。
典型的审批链路:
Developer → OpenAPI with x-mcp-enabled → Pull Request → Domain Review → Security Review → Principal Architect → Merge → Automated Deployment → MCP Server Live
审查什么:
| 方面 | 审查重点 | 跳过风险 |
|---|---|---|
| 描述质量 | 对 AI 智能体来说清晰吗? | 意图被误解,调用错误 API |
| 安全模型 | 认证要求写清楚了吗? | 未授权访问、数据泄露 |
| 数据暴露 | 敏感数据标记了吗? | 隐私违规、合规漏洞 |
| 操作安全性 | 只读还是写操作? | 意外修改数据 |
| 限流 | 节流配置合理吗? | 资源耗尽、拒绝服务攻击 |
MCP 启用操作的最低要求:
# BAD:对 AI 智能体来说太模糊
get: summary: "Get user" x-mcp-enabled: true # GOOD:清晰、可操作、有约束
get: summary: "Retrieve user profile information" description: | Get comprehensive profile data for the authenticated user including preferences, settings, and basic account information. **Authentication required**: User can only access their own profile. **Data privacy**: Returns only non-sensitive user data. **Rate limit**: 100 requests per minute. x-mcp-enabled: true security: - BearerAuth: []
为什么重要:AI 智能体依赖描述来理解:
描述烂 = 智能体行为烂。
强制审查要求:
# 在 Git 仓库里
/apis/customer-management/ @customer-team @security-team
/apis/payment-processing/ @payment-team @compliance-team @security-team
/apis/public-data/ @platform-team # 任何带 x-mcp-enabled 的文件需要首席架构师审批
**/openapi*.yaml @principal-architect
这样强制:
Git 就是审计跟踪:
{ "commit": "abc123", "author": "developer@org.com", "timestamp": "2026-01-12T10:30:00Z", "changes": [ { "file": "apis/customer-management/openapi.yaml", "operation": "/users/{userId}/profile", "change": "Added x-mcp-enabled: true", "reviewers": ["security-team", "principal-architect"], "approved_at": "2026-01-12T11:00:00Z" } ]
}
每个 MCP 暴露变更都存在 Git 历史里。谁改的、什么时候改的、谁批的,一清二楚。
说个扎心的真相:在一个烂 API 集合上套 MCP,别指望有好结果。
不是所有 API 都应该变成 MCP 工具。考虑这些:
| 特征 | MCP 就绪 | 不适合 MCP |
|---|---|---|
| 文档 | 清晰、完整、对智能体友好 | 稀疏、过时、只给人看 |
| 稳定性 | 版本化管理、契约稳定 | 频繁破坏性变更 |
| 错误处理 | 结构化错误响应 | 通用 500,没有详情 |
| 安全模型 | 认证授权定义清晰 | 权限配置随意 |
| 性能 | 响应时间稳定可靠 | 时不时超时 |
| 幂等性 | 重试安全 | 重试有副作用 |
AI 智能体是不宽容的消费者。它们不会调试你的 API,不会提工单,只会挂得很难看。
我的立场:AI 智能体需要功能性 API,不是技术性 API。
技术性 API(大多数公司有的):
# CRUD 操作,以数据库为中心
POST /api/v1/customers
GET /api/v1/customers/{id}
PUT /api/v1/customers/{id}
DELETE /api/v1/customers/{id} POST /api/v1/accounts
GET /api/v1/accounts/{id}
PUT /api/v1/accounts/{id}
AI 智能体看到这个:"有创建、读取、更新、删除...但我到底为用户做什么?"
功能性 API(智能体需要的):
# 业务能力,以意图为导向
POST /customers/onboard - "Onboard a new customer with KYC verification" POST /customers/{id}/verify-identity - "Verify customer identity using government documents" POST /accounts/open - "Open a new bank account for verified customer" POST /payments/transfer - "Transfer money between accounts with fraud checks"
AI 智能体看到这个:"我能开户客户、验证身份、开账户、转账——我理解业务意图。"
用技术性 API:
用功能性 API:
三条路:
不要把 CRUD 端点暴露给 AI 智能体,然后指望它们编排业务逻辑。这是等着发生产故障。
烂 API(技术性,别 MCP 化这个):
/api/customers: post: summary: "Create customer" description: "Insert customer record into database" requestBody: content: application/json: schema: type: object properties: firstName: string lastName: string email: string # 还有50多个字段...
AI 智能体看到这个:"我能创建客户记录,但 KYC 呢?合规检查呢?账户设置呢?我是不是要调其他 API?调哪些?"
好 API(功能性,MCP 就绪):
/customers/onboard: post: summary: "Onboard new customer with full verification" description: | Complete customer onboarding process including: - Identity verification (government ID + liveness check) - KYC/AML compliance screening - Risk assessment - Welcome email and account activation **Business rules enforced:** - Customer must be 18+ years old - Must pass identity verification - Must clear compliance screening - Duplicate detection performed automatically **What happens on success:** - Customer record created with verified status - Welcome email sent - Customer can proceed to account opening **Authentication required:** Staff or authorized system only **Rate limit:** 10 requests per minute x-mcp-enabled: true requestBody: required: true content: application/json: schema: type: object required: [firstName, lastName, dateOfBirth, governmentId] properties: firstName: type: string description: "Customer's legal first name" lastName: type: string description: "Customer's legal last name" dateOfBirth: type: string format: date description: "Date of birth (must be 18+ years ago)" governmentId: type: object description: "Government-issued identification" required: [type, number, issuingCountry] properties: type: type: string enum: [passport, drivers_license, national_id] number: type: string issuingCountry: type: string responses: '201': description: "Customer onboarded successfully" content: application/json: schema: type: object properties: customerId: type: string description: "Unique customer identifier" verificationStatus: type: string enum: [verified, pending_review] nextSteps: type: array items: type: string example: ["Open savings account", "Apply for credit card"] '400': description: "Invalid input or failed verification" content: application/json: schema: type: object properties: error: type: string reason: type: string enum: [underage, failed_identity_check, failed_compliance, duplicate_customer]
AI 智能体看到这个:"非常清晰。开客户、验证身份、执行规则、告诉我下一步做什么。我知道什么时候用这个、需要什么数据。"
问题一:编排负担
技术方案(智能体要自己搞懂):
1. POST /customers (创建记录)
2. POST /kyc-checks (验证身份)
3. GET /kyc-checks/{id} (等待结果)
4. POST /compliance-screenings (AML 检查)
5. GET /compliance-screenings/{id} (等待结果)
6. PUT /customers/{id} (更新状态为已验证)
7. POST /emails (发送欢迎邮件) 如果第 4 步失败了怎么办?如果第 6 步失败但第 7 步成功了怎么办?
功能方案(一次调用):
POST /customers/onboard (原子性执行所有操作)
问题二:业务规则发现
技术性 API 说:"给你个数据库表,自己看着办"
功能性 API 说:"这是业务流程,规则我来管"
问题三:错误语义
技术性 API: 400 Bad Request (哪里出问题了?)
功能性 API: 400 Bad Request - reason: "failed_identity_check" (哦,身份验证失败了)
这不是 API 设计的洁癖。这是智能体能跑起来还是引发生产故障的区别。
聊聊"GitOps"在这个场景下到底意味着什么。
所有东西都在 Git 里:
x-mcp-enabled 标记的 OpenAPI 规范不在 Azure Portal 里改东西。不在 Git 里的东西就不存在。
我们想要的:
# 这个操作应该是 MCP 工具
x-mcp-enabled: true
不是:
# 命令式修改状态
az apim mcp create --name ...
桥接自动化读取声明式配置,然后同步 Azure 状态。
Feature Branch → Pull Request → Automated Validation → Human Review → Approval → Merge to Main → Automated Deployment
禁止野路子部署。每个变更都要走审查。
用 Git 标签做部署标记:
git tag deploy-20260112-103000
回滚 = 切回之前的标签:
git checkout deploy-20260112-100000
./deploy.sh # 重新应用之前的状态
跟踪自动化做了什么:
x-mcp-enabled?流水线日志就是你的审计跟踪。
坦诚交代:我们也在摸索阶段。说说 Grand Central 考虑什么方案。
Maven 插件扩展,在构建时生成 MCP overlay 配置。
为什么吸引我们:
工作原理: