dynamics_generate_plugin_code
Generate C# code for Dynamics CRM plugins by specifying entity, message, stage, and business logic to automate custom workflow extensions.
Instructions
Gera código C# para um plugin do Dynamics CRM com base nos parâmetros fornecidos
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Nome da classe do plugin (ex: AccountPreCreate) | |
| entityLogicalName | Yes | Nome lógico da entidade (ex: account) | |
| message | Yes | Mensagem/evento do plugin | |
| stage | Yes | Estágio de execução | |
| executionMode | No | Modo de execução | Synchronous |
| filteringAttributes | No | Atributos de filtragem separados por vírgula | |
| description | No | Descrição do plugin | |
| businessLogic | No | Lógica de negócio a ser implementada no plugin |
Implementation Reference
- src/tools/plugins/index.ts:75-102 (handler)The handler implementation for dynamics_generate_plugin_code, which generates C# code based on provided plugin configuration parameters.
server.tool( "dynamics_generate_plugin_code", "Gera código C# para um plugin do Dynamics CRM com base nos parâmetros fornecidos", CreatePluginSchema.shape, async (params: z.infer<typeof CreatePluginSchema>) => { const stageValue = STAGE_MAP[params.stage] || 40; const template = PLUGIN_TEMPLATES.standard; const code = template .replace(/{{CLASS_NAME}}/g, params.name) .replace(/{{ENTITY_LOGICAL_NAME}}/g, params.entityLogicalName) .replace(/{{MESSAGE}}/g, params.message) .replace(/{{STAGE}}/g, String(stageValue)) .replace(/{{EXECUTION_MODE}}/g, params.executionMode === "Synchronous" ? "0" : "1") .replace(/{{FILTERING_ATTRIBUTES}}/g, params.filteringAttributes || "") .replace(/{{DESCRIPTION}}/g, params.description || `Plugin ${params.name} for ${params.message} on ${params.entityLogicalName}`) .replace(/{{BUSINESS_LOGIC}}/g, params.businessLogic || "// TODO: Implement business logic here"); return { content: [ { type: "text" as const, text: `Plugin C# gerado com sucesso:\n\n\`\`\`csharp\n${code}\n\`\`\`\n\n**Configuração:**\n- Entidade: ${params.entityLogicalName}\n- Mensagem: ${params.message}\n- Estágio: ${params.stage} (${stageValue})\n- Modo: ${params.executionMode}\n${params.filteringAttributes ? `- Filtro: ${params.filteringAttributes}` : ""}`, }, ], }; } ); - src/tools/plugins/index.ts:7-22 (schema)The schema defining the expected input parameters for the dynamics_generate_plugin_code tool.
export const CreatePluginSchema = z.object({ name: z.string().describe("Nome da classe do plugin (ex: AccountPreCreate)"), entityLogicalName: z.string().describe("Nome lógico da entidade (ex: account)"), message: z.enum(["Create", "Update", "Delete", "Retrieve", "RetrieveMultiple", "Associate", "Disassociate", "SetState", "SetStateDynamicEntity"]) .describe("Mensagem/evento do plugin"), stage: z.enum(["PreValidation", "PreOperation", "PostOperation"]) .describe("Estágio de execução"), executionMode: z.enum(["Synchronous", "Asynchronous"]).default("Synchronous") .describe("Modo de execução"), filteringAttributes: z.string().optional() .describe("Atributos de filtragem separados por vírgula"), description: z.string().optional() .describe("Descrição do plugin"), businessLogic: z.string().optional() .describe("Lógica de negócio a ser implementada no plugin"), }); - src/tools/plugins/index.ts:70-73 (registration)The registration entry point for plugin-related tools, including dynamics_generate_plugin_code.
export function registerPluginTools( server: { tool: Function }, client: DataverseClient ) {