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
26 changes: 26 additions & 0 deletions Core/Resgrid.Config/McpConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace Resgrid.Config
{
/// <summary>
/// Configuration settings for the Model Context Protocol (MCP) server
/// Note: MCP uses SystemBehaviorConfig.ResgridApiBaseUrl for the API base URL
/// </summary>
public static class McpConfig
{
/// <summary>
/// The name of the MCP server
/// </summary>
public static string ServerName = "Resgrid CAD System";

/// <summary>
/// The version of the MCP server
/// </summary>
public static string ServerVersion = "1.0.0";

/// <summary>
/// The transport mechanism for MCP (e.g., "stdio")
/// </summary>
public static string Transport = "stdio";
}
}


12 changes: 5 additions & 7 deletions Web/Resgrid.Web.Mcp/McpServerHost.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using ModelContextProtocol.Server;
using Resgrid.Config;

namespace Resgrid.Web.Mcp
{
Expand All @@ -14,7 +14,6 @@ namespace Resgrid.Web.Mcp
public sealed class McpServerHost : IHostedService, IDisposable
{
private readonly ILogger<McpServerHost> _logger;
private readonly IConfiguration _configuration;
private readonly McpToolRegistry _toolRegistry;
private readonly IHostApplicationLifetime _applicationLifetime;
private McpServer _mcpServer;
Expand All @@ -24,12 +23,10 @@ public sealed class McpServerHost : IHostedService, IDisposable

public McpServerHost(
ILogger<McpServerHost> logger,
IConfiguration configuration,
McpToolRegistry toolRegistry,
IHostApplicationLifetime applicationLifetime)
{
_logger = logger;
_configuration = configuration;
_toolRegistry = toolRegistry;
_applicationLifetime = applicationLifetime;
}
Expand All @@ -42,8 +39,9 @@ public Task StartAsync(CancellationToken cancellationToken)

try
{
var serverName = _configuration["McpServer:ServerName"] ?? "Resgrid CAD System";
var serverVersion = _configuration["McpServer:ServerVersion"] ?? "1.0.0";
// Use McpConfig for server configuration
var serverName = McpConfig.ServerName;
var serverVersion = McpConfig.ServerVersion;

// Create MCP server with server information
_mcpServer = new McpServer(serverName, serverVersion, _logger);
Expand Down
13 changes: 6 additions & 7 deletions Web/Resgrid.Web.Mcp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Threading.Tasks;
using Autofac.Extensions.DependencyInjection;
Expand Down Expand Up @@ -78,19 +78,18 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
services.AddSingleton<Infrastructure.ITokenRefreshService, Infrastructure.TokenRefreshService>();
services.AddSingleton<Infrastructure.IAuditLogger, Infrastructure.AuditLogger>();

// Validate required API configuration
var apiBaseUrl = configuration["McpServer:ApiBaseUrl"];
if (string.IsNullOrWhiteSpace(apiBaseUrl))
// Validate required API configuration from SystemBehaviorConfig
if (string.IsNullOrWhiteSpace(SystemBehaviorConfig.ResgridApiBaseUrl))
{
throw new InvalidOperationException(
"McpServer:ApiBaseUrl is required but not configured. " +
"Configure this setting in appsettings.json or via environment variables.");
"SystemBehaviorConfig.ResgridApiBaseUrl is required but not configured. " +
"Configure this setting via the Resgrid configuration file or environment variables (RESGRID:SystemBehaviorConfig:ResgridApiBaseUrl).");
}

// Register HTTP client for API calls with connection pooling
services.AddHttpClient("ResgridApi", client =>
{
client.BaseAddress = new Uri(apiBaseUrl);
client.BaseAddress = new Uri(SystemBehaviorConfig.ResgridApiBaseUrl);
client.DefaultRequestHeaders.Add("Accept", "application/json");
client.Timeout = TimeSpan.FromSeconds(30);
})
Expand Down
9 changes: 2 additions & 7 deletions Web/Resgrid.Web.Mcp/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"Logging": {
"LogLevel": {
"Default": "Information",
Expand All @@ -9,12 +9,7 @@
"AppOptions": {
"ConfigPath": ""
},
"McpServer": {
"ServerName": "Resgrid CAD System",
"ServerVersion": "1.0.0",
"ApiBaseUrl": "https://api.resgrid.com",
"Transport": "stdio"
},
"_Comment": "MCP Server configuration is now managed by Resgrid.Config classes. API Base URL uses SystemBehaviorConfig.ResgridApiBaseUrl. Configure via ResgridConfig.json or environment variables (RESGRID:SystemBehaviorConfig:ResgridApiBaseUrl, RESGRID:McpConfig:ServerName, RESGRID:McpConfig:ServerVersion, RESGRID:McpConfig:Transport)",
"ConnectionStrings": {
"ResgridContext": ""
}
Expand Down
Loading