---
description: 
globs: 
alwaysApply: true
---
# Zuora Code Generation Workspace Rule

## MCP-First, SDK-Compliant, and Traceable Code Generation

**IMPORTANT:** This rule applies ONLY to **code generation requests** (e.g., "generate Java code for...", "create a class that...", "write code to..."). 

For **operational requests** (e.g., "create a subscription", "query accounts", "create a product"), use the appropriate Zuora MCP tools directly:
- `mcp_zuora-mcp_create_subscription` for subscription operations
- `mcp_zuora-mcp_create_product` for product operations  
- `mcp_zuora-mcp_query_objects` for data queries
- `mcp_zuora-mcp_ask_zuora` for Zuora knowledge questions

### 1. MCP-First Model Discovery (Code Generation Only)
- Never generate code for any Zuora API, model, or enum without first querying the MCP for:
  - The API method signature and required/optional parameters.
  - All request/response model structures.
  - All enum values and their correct usage.
- If a model or enum is not found in the MCP, do not generate code for that part.
  - Instead, insert a clear TODO comment and stop code generation for that section.

### 2. Strict Type and Enum Usage
- Always use the SDK's enum types for fields that require enums (e.g., `RenewalSetting.WITH_SPECIFIC_TERM`, not `"RENEW_WITH_SPECIFIC_TERM"`).
- Never use string literals for enum fields unless the MCP explicitly states that only strings are accepted.
- Always use the correct model classes for nested objects (e.g., `InitialTerm`, `RenewalTerm`), as defined by the MCP.

### 3. No Guessing or Hallucination
- Never guess field names, types, or enum values.
- If a field or type is ambiguous, pause code generation and request clarification (from the user or via additional MCP queries).

### 4. Code Mapping and Traceability
- For every generated code block, be able to show (on request) the exact MCP model or enum output that justifies the code.
- If the user requests, provide a mapping of code lines to MCP model fields.

### 5. Error Handling and Placeholders
- If a required field or enum is missing from the MCP, insert a TODO comment and do not generate a placeholder or default value.
- If the SDK requires a field that is not documented in the MCP, pause and request clarification.

### 6. Language and SDK Conventions
- Always follow the language-specific SDK patterns as returned by the MCP's `code_rules` endpoint.
- Use fluent setters, correct package imports, and idiomatic error handling as per the SDK's conventions.

### 7. Validation Before Output
- Before presenting code, validate that:
  - All fields and enums are present in the MCP output.
  - The code matches the SDK's required structure and types.
  - There are no unresolved TODOs for required fields.

### 8. Transparency
- If the user requests, provide the raw MCP output for any model, enum, or API used in the code.

---

## Summary Table

| Request Type        | Tool to Use                                                                 |
|---------------------|-----------------------------------------------------------------------------|
| Code Generation     | `mcp_zuora-mcp_zuora_codegen` (follow all rules below)                     |
| Create Subscription | `mcp_zuora-mcp_create_subscription`                                        |
| Create Product      | `mcp_zuora-mcp_create_product`                                             |
| Query Objects       | `mcp_zuora-mcp_query_objects`                                              |
| Zuora Knowledge     | `mcp_zuora-mcp_ask_zuora`                                                  |

| Code Generation Step | Rule/Action                                                                 |
|---------------------|-----------------------------------------------------------------------------|
| Model Discovery     | MCP query for all models/enums before code generation                        |
| Enum Usage          | Always use SDK enums, never strings (unless MCP says otherwise)              |
| No Guessing         | Never guess types/fields; pause for clarification if needed                  |
| Mapping             | Be able to show MCP-to-code mapping on request                               |
| Placeholders        | Insert TODOs for missing fields/enums, never use defaults                    |
| SDK Conventions     | Follow language-specific code_rules from MCP                                 |
| Validation          | Check all code against MCP before output                                     |
| Transparency        | Provide MCP output on request                                                |

---

**This rule must be followed for all Zuora code generation in this workspace.** 