Using the Sitecore MCP Server in CrewAI
In a previous post, we’ve seen how to build your own AI application using CrewAI. The Sitecore MCP Server is a Model Context Protocol (MCP) server implementation designed to integrate Sitecore content with AI agents like those in CrewAI. This guide walks you through setting up and using the MCP Server within a CrewAI environment to enable intelligent, context-aware interactions with Sitecore-managed content.
But before we start, a big shout out to Anton Tishchenko for driving the development of this MCP Server!
What is an MCP Server?
An MCP Server acts as a bridge between your AI agents and another platform by exposing a structured API that conforms to the Model Context Protocol. This allows agents to query, retrieve, and reason using tools of the integrated platform in a standardized way.
What you’ll need
Before you start, make sure you have:
-
A running Sitecore instance (XM Cloud or version 10+)
-
A CrewAI agent setup (see this article as an example)
- Including the
crewai-tools[mcp]
andmcp
python modules installed
- Including the
-
The necessary values as described in the MCP Server README, such as
- Sitecore CM domain
- Sitecore API key
- Item service username + password
- Sitecore PowerShell Extensions admin username + password
Setup your crew
Let’s create a new, Sitecore Content Management, crew in CrewAI. This is very similar to a regular crew setup, with some additions to add MCP servers to the context.
First we need to define the MCP server parameters. The Sitecore MCP Server runs through the Stdio transport mechanism, meaning it will run a command on the machine to start the MCP Server application. In the case of the Sitecore MCP Server, we want to run it straight from NPM using the npx
command.
Additionally, we need to specify all the environment variables according to the Sitecore instance you want to connect to.
server_params=StdioServerParameters(
command="npx",
args=["@antonytm/mcp-sitecore-server@latest"],
env={
"TRANSPORT": "stdio",
"GRAPHQL_ENDPOINT": "https://[your sitecore cm domain]/sitecore/api/graph/",
"GRAPHQL_SCHEMAS": "edge,master,core",
"GRAPHQL_API_KEY": "[your API key]",
"GRAPHQL_HEADERS": "",
"ITEM_SERVICE_DOMAIN": "sitecore",
"ITEM_SERVICE_USERNAME": "admin",
"ITEM_SERVICE_PASSWORD": "b",
"ITEM_SERVICE_SERVER_URL": "https://[your sitecore cm domain]/",
"POWERSHELL_DOMAIN": "sitecore",
"POWERSHELL_USERNAME": "admin",
"POWERSHELL_PASSWORD": "b",
"POWERSHELL_SERVER_URL": "https://[your sitecore cm domain]/",
}
)
Using these server parameters, we can now define the MCP Server Adapter context and start defining our Agents and Tasks. To create the context object, create a new MCPServerAdapter
with the server_params
as parameters as shown below.
with MCPServerAdapter(server_params) as mcp_tools:
Within the with
, you can then start creating your Crew.
A full Crew setup file would look something like this:
from crewai import Agent, Task, Crew, Process
from crewai_tools import MCPServerAdapter
from mcp import StdioServerParameters # For Stdio Server
class SitecoreCrew():
server_params=StdioServerParameters(
command="npx",
args=["@antonytm/mcp-sitecore-server@latest"],
env={
"TRANSPORT": "stdio",
"GRAPHQL_ENDPOINT": "https://[your sitecore cm domain]/sitecore/api/graph/",
"GRAPHQL_SCHEMAS": "edge,master,core",
"GRAPHQL_API_KEY": "[your API key]",
"GRAPHQL_HEADERS": "",
"ITEM_SERVICE_DOMAIN": "sitecore",
"ITEM_SERVICE_USERNAME": "admin",
"ITEM_SERVICE_PASSWORD": "b",
"ITEM_SERVICE_SERVER_URL": "https://[your sitecore cm domain]/",
"POWERSHELL_DOMAIN": "sitecore",
"POWERSHELL_USERNAME": "admin",
"POWERSHELL_PASSWORD": "b",
"POWERSHELL_SERVER_URL": "https://[your sitecore cm domain]/",
},
)
with MCPServerAdapter(server_params) as mcp_tools:
print(f"Available tools: {[tool.name for tool in mcp_tools]}")
content_manager_agent = Agent(
role="Content Manager",
goal="To create and manage content effectively within the Sitecore environment.",
backstory="You are a content management expert with a deep understanding of Sitecore's capabilities. You excel at creating, editing, and optimizing content to enhance user engagement.",
reasoning=True,
verbose=True,
max_iter=1,
tools=mcp_tools # Pass the loaded tools to your agent
)
read_content_task = Task(
description="Read content from the Sitecore environment based on the provided parameters.",
expected_output="The content retrieved from Sitecore.",
agent=content_manager_agent
)
def crew(self) -> Crew:
"""Creates the crew"""
return Crew(
agents=[self.content_manager_agent],
tasks=[self.read_content_task],
verbose=True,
process=Process.sequential
)
From here, you can use the SitecoreCrew().crew()
method in your application to trigger the agent to run.
Final thoughts
The Sitecore MCP Server is a great starting point for anyone looking to integrate AI capabilities into Sitecore. Whether you’re building a smart assistant, a content-aware chatbot, or a dynamic content delivery system, this integration is a solid foundation and I’m looking forward to seeing what the Sitecore community can come up with.
Ready to try it out? Head over to the GitHub repo and get started today.