Sitecore docs AI and MCP

Did you know Sitecore Docs has a new AI feature that you can talk with a LLM chat that has been trained on the Sitecore documentation?

Just go to https://doc.sitecore.com/ and press the Icon in the header, marked in the picture, and you can start asking it questions.

Sitecores documentation has greatly improved the last years, not only in quality, but also in quantity. Sometimes it can be hard to find the right place to look at. And with this AI chat tool you can find answers fast!

There is also an MCP server you can connect to.
To add the MCP to your VS Code you can do following, or Cursor etc:

You can now also use the MCP in context with your code repository to get even more context for your question.

A short post but it gives huge impact, and fast!

NOTE from Sitecore:
“This assistant has access to all Sitecore documentation. We are currently testing this, therefore the answers provided should not be considered official advice or support.”

SitecoreAI – AI Translation

Translate a page or even translate an entire site from one language to another is a powerful yet simple to use tool in SitecoreAI.

Lets break it down.

First lets talk about Brand Kits

Brand Kits allow marketing or communication teams to configure how AI should generate content within Sitecore.

brand kits in sitecoreAI

By creating Brand Kits, organizations can define instructions and brand guidelines that AI features in SitecoreAI will follow. When editors then use AI functionality they can select a Brand Kit. Brand kits provide:

  • A centralized location for brand instructions
  • Reusable configuration
  • Consistent tone and messaging in your content

By default, administrators can see all brand kits, but they have the power to grant users access as needed to specific brand kits. This is very important and good feature!

Knowledge

Within a Brand Kit, the Knowledge tab allows you to upload documents that help build your brand knowledge base. Basically if you upload documents here SitecoreAI will populate the otherwise empty sections on the Brand Kit based on those documents.

Examples of supported documents:

  • Brand books
  • Visual guidelines
  • Style guides
  • Graphic manuals

Sections

In the tab Sections, you can setup the configuration of the kit.

Sections can be populated using the uploaded Knowledge documents (via the button in the top-right corner). However, you might want to look over and edit these if needed. It provides a strong starting point, but manual refinement is typically required.

Examples of sections include:

  • Brand Context – Describes your brand’s purpose and positioning
  • Do’s and Don’ts – Guidelines ensuring AI-generated content aligns with tone and values (e.g., formal, academic, relaxed)
  • Tone of Voice – Attributes such as friendliness or confidence that define brand personality

You can setup multiple Brand Kits and use them for different goals, like campaigns, audience etc.

Brand Kits are not required to use translation features, but they can significantly improve consistency and quality.

Inside Page Builder, several built-in AI tools support Brand Kits. Like this image below, you can select a field you want to edit, click the “Optimize with AI”-button in red. Here you can use the prompt, translate, or adhere to a brand kit.


Agentic Studio – Translation assistant

The Agentic Studio is a centralized place for AI agents, which helps to automize work for you. There’s a ton of out-of-the-box agents from Sitecore, and one of them is the Translator, which allows you to translate content to multiple languages at the same time while keeping the Brand context.

This is the first interface of the Translation Assistant. You have your input, then you can add context; in this case, I’ve added my Brand Kit as context to get the tone of voice, etc., that I’m interested in. You could also add more context to the translation if you wish.

Then we get this window. Here we can set the desired parameters for this translation job. Like selecting which languages, persona, tone etc. Then the artifacts are created for each translation for you to use.


Page translation

This is maybe the highlight of this blogpost. This functionality does not require Brand Kits.

For example, you can navigate to a page that has been created and setup content in English. In the language dropdown at the top of Page Builder, select Translate.

A dialog will appear allowing you to choose one of the available site languages. The system will then traverse all references and related items in Sitecore for that page and generate, for example, a Swedish version. All text content will be translated, display names on items will receive a Swedish version, and image alt texts will also be translated if an alt text exists.

The following field types are translated:

  • Single-line text
  • Multi-line text
  • Rich text
  • General Link (link title, link text)
  • General Link with Search (link title, link text)
  • Image (alt text)

Shared fields are skipped. These are template fields marked as SHARED, since they are identical across all language versions.

Choose source language and then click Translate on the desired language. Note that your language only pops up here if it’s configurated for the site.

Site translation

If you instead go to manage languages from page builder you will get to this language page, here you have the button “Translate with AI” which does the same as the page translation but for the entire site. Very powerfull stuff!

The full site translation functionality is available for admins or Sitecore Client Site Managing roles.


That’s what I wanted to go over with Sitecore AI translation and some info on the Brand kits also if you’re interested in that.
Hope this helps!

Generate images in Sitecore with OpenAI’s DALL·E API

OpenAI’s DALL·E API allows us to generate AI images based on a textual descripton. In this post I’ll show how we can use the API to create an image and store it in Sitecore.

To use the API you must sign up for an API key on openai.com.
Copy that API key and use it in your code. Then we can make a request to the API with a description of the image you want to generate.

With the Free trial usage you get $18 worth of credits to use the API. Generating one image is only a few cents. So it should be enough for a POC or just testing it out.

Using the HttpClient, we’ll send a POST request to the API endpoint with a JSON payload containing the description. Parse the JSON response to get the URL of the generated image, then use memorystream to save it in the media library.

Here’s an example how we can use it:

Custom dialog

I followed this great guide to setup a custom popup dialog
https://sbhatiablogs.wordpress.com/2019/07/07/custom-sitecore-menu-button-with-custom-popup-dialog/

With my own modifications it looks like this:

First the command that I’ve created in Sitecore. Follow steps in above guide for creating the Command and Sitecore Ribbon Button.

<configuration>
  <sitecore>
      <commands>
          <command name="item:generateimage" type="MyProject.Tasks.GenerateImageCommand, MyProject"/>
      </commands>
  </sitecore>
</configuration>
public class GenerateImageCommand : Sitecore.Shell.Framework.Commands.Command
  {
    public override void Execute(CommandContext context)
    {
      Sitecore.Context.ClientPage.Start(this, "Run", context.Parameters);
    }

    protected static void Run(ClientPipelineArgs args)
    {
      if (!args.IsPostBack)
      {
        UrlString urlString = new UrlString(UIUtil.GetUri("control:GenerateAiImage"));
        SheerResponse.ShowModalDialog(urlString.ToString(), "500", "300", "", true);
        args.WaitForPostBack();
      }
      else
      {
        if (args.HasResult)
        {
          if (Sitecore.Context.Item.Name == "Content Editor")
          {
           Sitecore.Context.ClientPage.ClientResponse.SetLocation(Sitecore.Links.LinkManager.GetItemUrl(Sitecore.Context.Item));
          }
        }
      }
    }
  }

Then the dialog that looks like this

The xml created under <webroot>/sitecore/shell/Application/Content Manager/Dialogs to make the dialog appearance.

<?xml version="1.0" encoding="utf-8" ?>
<control xmlns="http://schemas.sitecore.net/Visual-Studio-Intellisense" xmlns:def="Definition">
  <GenerateAiImage>
    <FormDialog Icon="Network/32x32/link.png" Style="height: 200%" Header="Generate AI image" Text="Enter filename and description" OKButton="Insert">
      <CodeBeside Type="MyProject.Tasks.GenerateImage, MyProject"/>
      <div class="scStretch" >
        <div class="col2">
          <Border Background="transparent" Border="none" GridPanel.VAlign="top" Padding="4px 0px 0px 0px">
            <GridPanel Class="scFormTable" CellPadding="2" Columns="2" Width="100%" GridPanel.Height="100%">
              <Label For="Filename" GridPanel.NoWrap="true">
                <Literal Text="Filename:" />
              </Label>
              <Edit ID="Filename" Width="100%"/>
              <Label for="Description" GridPanel.NoWrap="true">
                <Literal Text="Description:" />
              </Label>
              <Edit ID="Description" Width="100%"/>
            </GridPanel>
          </Border>
        </div>
      </div>
    </FormDialog>
  </GenerateAiImage>
</control>


With the CodeBeside in above XML I can catch the OnOk event which will generate the image from the API. From there I can grab the input texts from my dialog window. That code looks like this:

public class GenerateImage : Sitecore.Web.UI.Pages.DialogForm
  {
    protected override void OnOK(object sender, EventArgs e)
    {
      Sitecore.Web.UI.HtmlControls.Button senderB = sender as Sitecore.Web.UI.HtmlControls.Button;
      string apiKey = "<Your_API_key>";
      string apiEndpoint = "https://api.openai.com/v1/images/generations";

      var filename = senderB.Page.Request.Form.Get("Filename");
      var description = senderB.Page.Request.Form.Get("Description");

      HttpClient client = new HttpClient();
      client.DefaultRequestHeaders.Authorization = 
        new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", apiKey);

      string jsonPayload = JsonConvert.SerializeObject(new
      {
        prompt = description,
        n = 1, //how many images to generate
        size = "512x512"
      });

      StringContent content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
      HttpResponseMessage response = client.PostAsync(apiEndpoint, content).Result;

      if (response.IsSuccessStatusCode)
      {
        string jsonResponse = response.Content.ReadAsStringAsync().Result;
        dynamic result = JsonConvert.DeserializeObject(jsonResponse);

        // Get the generated image URL
        string imageUrl = result.data[0].url;

        // Download the image
        using (var imageResponse = new HttpClient().GetAsync(imageUrl).Result)
        {
          if (imageResponse.IsSuccessStatusCode)
          {
            using (var stream = new MemoryStream())
            {
              imageResponse.Content.CopyToAsync(stream).Wait();
              stream.Seek(0, SeekOrigin.Begin);

              var mediaCreator = new MediaCreator();
              var options = new MediaCreatorOptions
              {
                Versioned = false,
                IncludeExtensionInItemName = false,
                Database = Factory.GetDatabase("master"),
                Destination = "/sitecore/media library/AI-generated-images/"
              };

              using (new SecurityDisabler())
                mediaCreator.CreateFromStream(stream, $"{filename}.png", options);
            }
          }
        }
      }
    }
  }

Sources:
https://sbhatiablogs.wordpress.com/2019/07/07/custom-sitecore-menu-button-with-custom-popup-dialog/