Skip to main content
Glama
rafteles2016

MCP Dynamics CRM Server

by rafteles2016

dynamics_generate_fetchxml

Generate FetchXML queries for Dynamics CRM by specifying entities, columns, filters, and joins to retrieve structured data efficiently.

Instructions

Gera FetchXML com base em parâmetros estruturados

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
entityLogicalNameYesEntidade principal
columnsYesColunas a retornar
filtersNoFiltros
ordersNo
linkedEntitiesNo
topNo

Implementation Reference

  • The handler implementation for the `dynamics_generate_fetchxml` tool, which constructs a FetchXML string based on the provided schema parameters.
    server.tool(
      "dynamics_generate_fetchxml",
      "Gera FetchXML com base em parâmetros estruturados",
      GenerateFetchXmlSchema.shape,
      async (params: z.infer<typeof GenerateFetchXmlSchema>) => {
        let fetchXml = `<fetch version="1.0" output-format="xml-platform" mapping="logical"`;
        if (params.top) fetchXml += ` top="${params.top}"`;
        fetchXml += `>\n  <entity name="${params.entityLogicalName}">\n`;
    
        for (const col of params.columns) {
          fetchXml += `    <attribute name="${col}" />\n`;
        }
    
        if (params.orders) {
          for (const order of params.orders) {
            fetchXml += `    <order attribute="${order.attribute}" descending="${order.descending}" />\n`;
          }
        }
    
        if (params.filters && params.filters.length > 0) {
          fetchXml += `    <filter type="and">\n`;
          for (const f of params.filters) {
            if (f.value) {
              fetchXml += `      <condition attribute="${f.attribute}" operator="${f.operator}" value="${f.value}" />\n`;
            } else {
              fetchXml += `      <condition attribute="${f.attribute}" operator="${f.operator}" />\n`;
            }
          }
          fetchXml += `    </filter>\n`;
        }
    
        if (params.linkedEntities) {
          for (const le of params.linkedEntities) {
            fetchXml += `    <link-entity name="${le.name}" from="${le.from}" to="${le.to}" alias="${le.alias}" link-type="${le.linkType}">\n`;
            for (const col of le.columns) {
              fetchXml += `      <attribute name="${col}" />\n`;
            }
            fetchXml += `    </link-entity>\n`;
          }
        }
    
        fetchXml += `  </entity>\n</fetch>`;
    
        return {
          content: [
            {
              type: "text" as const,
              text: `FetchXML gerado:\n\n\`\`\`xml\n${fetchXml}\n\`\`\``,
            },
          ],
        };
      }
    );
  • The input validation schema (`GenerateFetchXmlSchema`) for the `dynamics_generate_fetchxml` tool.
    export const GenerateFetchXmlSchema = z.object({
      entityLogicalName: z.string().describe("Entidade principal"),
      columns: z.array(z.string()).describe("Colunas a retornar"),
      filters: z.array(z.object({
        attribute: z.string(),
        operator: z.string(),
        value: z.string().optional(),
      })).optional().describe("Filtros"),
      orders: z.array(z.object({
        attribute: z.string(),
        descending: z.boolean().default(false),
      })).optional(),
      linkedEntities: z.array(z.object({
        name: z.string(),
        from: z.string(),
        to: z.string(),
        alias: z.string(),
        columns: z.array(z.string()),
        linkType: z.enum(["inner", "outer"]).default("outer"),
      })).optional(),
      top: z.number().optional(),
    });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rafteles2016/mcpDynamics'

If you have feedback or need assistance with the MCP directory API, please join our Discord server