Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ At least _one_ authentication provider must be configured, executed in order:
| Sitecore:CliUserFileAuthentication:EndpointName | `xmCloud` | The endpoint name to use |
| Sitecore:CloudAuthentication:ClientId | | Id with access to authoring endpoint |
| Sitecore:CloudAuthentication:ClientSecret | | Secret with access to authoring endpoint |
| Sitecore:ReadonlyMode | `false` | Disables all tools that mutates data |
2 changes: 1 addition & 1 deletion src/SitecoreBasicMcp/AssemblyMarker.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace SitecoreBasicMcp;

public class AssemblyMarker
internal class AssemblyMarker
{
}
2 changes: 2 additions & 0 deletions src/SitecoreBasicMcp/SitecoreSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ public class CloudAuthenticationSettings
public string? ClientId { get; set; }
public string? ClientSecret { get; set; }
}

public bool ReadonlyMode { get; set; }
}
19 changes: 16 additions & 3 deletions src/SitecoreBasicMcp/StartupExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@
using Microsoft.Extensions.Hosting;
using ModelContextProtocol.Protocol;
using SitecoreBasicMcp.Authentication;
using SitecoreBasicMcp.Tools;

namespace SitecoreBasicMcp;

public static class StartupExtensions
{
public static IMcpServerBuilder AddSitecoreMcpServer(this IHostApplicationBuilder builder)
{
builder.Services.Configure<SitecoreSettings>(builder.Configuration.GetSection(SitecoreSettings.Key));
var sitecoreSection = builder.Configuration.GetSection(SitecoreSettings.Key);
var sitecoreSettings = sitecoreSection.Get<SitecoreSettings>();

ArgumentNullException.ThrowIfNull(sitecoreSettings, nameof(sitecoreSettings));

builder.Services.Configure<SitecoreSettings>(sitecoreSection);
builder.Services.AddSingleton<IAuthenticationProvider, SitecoreCliUserFileAuthenticationProvider>();
builder.Services.AddSingleton<IAuthenticationProvider, SitecoreCloudAuthenticationProvider>();
builder.Services.AddSingleton<SitecoreAuthenticationService>();

var serverBuilder = builder.Services
.AddHttpClient()
.AddMcpServer()
.WithToolsFromAssembly(typeof(AssemblyMarker).Assembly)
.WithPromptsFromAssembly(typeof(AssemblyMarker).Assembly)
.AddCallToolFilter(next => async (context, cancellationToken) =>
{
try
Expand All @@ -36,6 +40,15 @@ public static IMcpServerBuilder AddSitecoreMcpServer(this IHostApplicationBuilde
}
});

if (sitecoreSettings.ReadonlyMode)
{
serverBuilder.WithTools<GetItemTool>();
}
else
{
serverBuilder.WithToolsFromAssembly(typeof(AssemblyMarker).Assembly);
}

return serverBuilder;
}
}