This repository demonstrates how to integrate with Sitecore's Model Context Protocol (MCP) server using OAuth 2.1 authentication with PKCE, showcasing both Python and .NET implementations.
These examples show how to build AI agents that can interact with Sitecore content management through MCP tools, using the Microsoft Agent Framework with Azure OpenAI.
SCMP_AI_Foundry_App/
βββ python_example/ # Python implementation (fully automated)
β βββ agent_with_mcp.py # Main chat app with MCP tools
β βββ mcp_compliant_auth.py # OAuth 2.1 + PKCE authentication
β βββ instructions.md # Agent behavior configuration
β βββ mcp.json # MCP server configuration
β βββ README.md # Python-specific documentation
β
βββ dotnet_example/ # .NET implementation (using MCP SDK)
β βββ SitecoreMcpChat/
β βββ Program.cs # Main chat application
β βββ McpOAuthClient.cs # OAuth 2.1 + PKCE
β βββ instructions.md # Agent behavior configuration
β βββ mcp.json # MCP server configuration
β βββ README.md # .NET-specific documentation
β
βββ README.md # This file
cd python_example
pip install -r requirements.txt
cp .env.example .env # Configure Azure OpenAI credentials
python agent_with_mcp.pyFeatures:
- β Streaming responses (word-by-word output)
- β Automatic MCP tool integration
- β 39+ Sitecore tools automatically available
- β Tool call indicators (π§ emoji)
- β OAuth 2.1 with PKCE and token caching
cd dotnet_example/SitecoreMcpChat
cp appsettings.example.json appsettings.json # Configure Azure OpenAI
dotnet runFeatures:
- β Official ModelContextProtocol C# SDK (v0.4.0-preview.3)
- β
HttpClientTransportfor HTTP/SSE connections - β OAuth 2.1 with PKCE and token caching
- β MCP tool discovery via SDK (39+ tools)
- β Native MCP tool integration via Agent Framework
- β Automatic function calling - agent calls tools as needed
- β Tool call visibility - shows which tools are being called
β οΈ No streaming (preview limitation)
Both implementations use OAuth 2.1 with PKCE for secure authentication:
- Metadata Discovery: Reads OAuth endpoints from
.well-known/oauth-authorization-server - Dynamic Client Registration: Registers OAuth client with the MCP server
- PKCE Flow: Uses code challenge/verifier for enhanced security
- Browser Authentication: Opens browser for user login
- Local Callback: Runs HTTP server on
localhost:3000to receive auth code - Token Exchange: Exchanges authorization code for access token
- Token Caching: Caches tokens for 24 hours (development only)
Current Implementation (Development Only):
- Tokens cached in
.mcp_token_cache.json - 24-hour expiry with 5-minute safety buffer
- Plain text storage
- NO encryption
- NO audit logging
Production Requirements:
- β Use Azure Key Vault or similar secure credential storage
- β Implement managed identities where possible
- β Enable token rotation and refresh mechanisms
- β Set shorter token lifetimes (1 hour maximum)
- β Enable comprehensive audit logging
- β Use encrypted storage for cached credentials
- β NEVER commit token cache files to source control
- β NEVER use plain text file storage in production
Both implementations provide access to 39+ Sitecore MCP tools:
- List sites, get site information, manage site configuration
- Create/update/delete pages and content items
- Search content, get page details, manage page templates
- List components, add/remove components from pages
- Manage component datasources, set personalization
- Get available languages, add language versions to pages
- Search assets, upload files, update asset metadata
- Create personalization versions, manage targeting rules
Both implementations use external instructions.md files for agent behavior:
Python: python_example/instructions.md
- Simple guidelines for when to use MCP tools
- Python Agent Framework handles tool integration automatically
dotnet: dotnet_example/SitecoreMcpChat/instructions.md
- Simple guidelines for when to use MCP tools
- .NET Agent Framework handles tool integration automatically
- Same automatic approach as Python
Both use mcp.json for MCP server settings:
{
"mcpServers": {
"marketer": {
"url": "https://edge-platform.sitecorecloud.io/mcp/marketer-mcp-prod",
"auth": {
"type": "external"
}
}
}
}Python: .env file
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com
AZURE_OPENAI_DEPLOYMENT=gpt-5.1-chat
AZURE_OPENAI_API_KEY=your-api-key
AZURE_OPENAI_API_VERSION=2025-01-01-preview.NET: appsettings.json file
{
"AZURE_OPENAI_ENDPOINT": "https://your-resource.openai.azure.com",
"AZURE_OPENAI_DEPLOYMENT": "gpt-5.1-chat",
"AZURE_OPENAI_API_KEY": "your-api-key"
}| Feature | Python | .NET |
|---|---|---|
| OAuth 2.1 + PKCE | β | β |
| Token Caching | β (24 hours) | β (24 hours) |
| MCP SDK Usage | β (MCPStreamableHTTPTool) | β (HttpClientTransport) |
| Tool Discovery | β (automatic) | β (automatic via SDK) |
| Tool Execution | β (automatic) | β (automatic via framework) |
| Tool Orchestration | β (automatic) | β (automatic) |
| Streaming Responses | β (word-level) | β (preview limitation) |
| Tool Call Visibility | β | β |
| Conversation History | β | β |
| Instructions File | β
(instructions.md) |
β
(instructions.md) |
Both implementations use native MCP integration:
- Python: Uses
MCPStreamableHTTPToolfor automatic tool orchestration - .NET: Passes tools to agent via
tools: [.. mcpTools.Cast<AITool>()]for automatic orchestration - Both follow official Microsoft Agent Framework documentation patterns
- Both are production-ready with automatic function calling
Choose based on your stack: Both implementations provide the same automatic tool calling capabilities.
- Content Management: Create, update, and manage Sitecore content items
- Site Administration: Manage sites, pages, and templates
- Marketing Operations: Set up personalization and targeting
- Asset Management: Upload and organize media files
- Multi-language Support: Manage content across multiple languages
- Component Management: Configure page layouts and components
- Python Example: See python_example/README.md
- dotnet Example: See dotnet_example/README.md
- Microsoft Agent Framework: https://learn.microsoft.com/agent-framework/
- Model Context Protocol: https://modelcontextprotocol.io/
- Sitecore MCP Documentation: https://doc.sitecore.com/mp/en/developers/sdk/0/sitecore-marketplace-sdk/developer-guides.html
- Python 3.13+
- Azure OpenAI resource
- Sitecore MCP server access
- .NET 9.0 SDK+
- Azure OpenAI resource
- Sitecore MCP server access
This is example code for learning purposes. Feel free to adapt and extend for your own use cases.
- Token Caching: Current implementation is for DEVELOPMENT ONLY. Use secure credential storage for production.
- Error Handling: Examples include basic error handling. Production code should be more robust.
- Agent Framework Versions: Python uses
agent-frameworkpackage, .NET uses Microsoft.Agents.AI preview packages. - MCP SDK Integration:
- Python: Native integration via
MCPStreamableHTTPTool- fully automatic orchestration - .NET: Native integration via Agent Framework - passes tools directly to agent for automatic orchestration
- Both use official SDKs with automatic function calling
- Python: Native integration via
- Production Use: Both Python and .NET are production-ready with automatic tool calling. Choose based on your preferred tech stack.
This is example code for educational purposes.