-
-
Notifications
You must be signed in to change notification settings - Fork 75
RE1-T102 Fixing MCP server issue. #280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| using System; | ||
| using Microsoft.AspNetCore.Builder; | ||
| using Microsoft.AspNetCore.Hosting; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Resgrid.Config; | ||
| using Resgrid.Web.Mcp.Infrastructure; | ||
| using Resgrid.Web.Mcp.Tools; | ||
|
|
||
| namespace Resgrid.Web.Mcp | ||
| { | ||
| public class Startup | ||
| { | ||
| public IConfiguration Configuration { get; } | ||
|
|
||
| public Startup(IConfiguration configuration) | ||
| { | ||
| Configuration = configuration; | ||
| } | ||
|
|
||
| public void ConfigureServices(IServiceCollection services) | ||
| { | ||
| // Initialize Resgrid logging framework with Sentry if available | ||
| if (!string.IsNullOrWhiteSpace(ExternalErrorConfig.ExternalErrorServiceUrlForMcp)) | ||
| { | ||
| Framework.Logging.Initialize(ExternalErrorConfig.ExternalErrorServiceUrlForMcp); | ||
| } | ||
|
|
||
| // Register MCP server | ||
| services.AddHostedService<McpServerHost>(); | ||
|
|
||
| // Add MVC controllers for health check endpoint | ||
| services.AddControllers() | ||
| .AddNewtonsoftJson(); | ||
|
|
||
| // Register infrastructure services | ||
| services.AddMemoryCache(); | ||
| services.AddSingleton<IResponseCache, ResponseCache>(); | ||
| services.AddSingleton<IRateLimiter, RateLimiter>(); | ||
| services.AddSingleton<ITokenRefreshService, TokenRefreshService>(); | ||
| services.AddSingleton<IAuditLogger, AuditLogger>(); | ||
|
Comment on lines
+36
to
+41
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: find . -type f -name "*.cs" | xargs rg -l 'class ResponseCache|class RateLimiter|class TokenRefreshService|class AuditLogger' | head -20Repository: Resgrid/Core Length of output: 273 🏁 Script executed: # Find and examine these implementations
rg -B 2 -A 20 'class ResponseCache\s*[:\(]' --type csRepository: Resgrid/Core Length of output: 1912 🏁 Script executed: rg -B 2 -A 20 'class RateLimiter\s*[:\(]' --type csRepository: Resgrid/Core Length of output: 1998 🏁 Script executed: rg -B 2 -A 20 'class TokenRefreshService\s*[:\(]' --type csRepository: Resgrid/Core Length of output: 2199 🏁 Script executed: rg -B 2 -A 20 'class AuditLogger\s*[:\(]' --type csRepository: Resgrid/Core Length of output: 1756 🏁 Script executed: cat -n Web/Resgrid.Web.Mcp/Infrastructure/RateLimiter.csRepository: Resgrid/Core Length of output: 5735 🏁 Script executed: cat -n Web/Resgrid.Web.Mcp/Infrastructure/ResponseCache.csRepository: Resgrid/Core Length of output: 2181 🏁 Script executed: cat -n Web/Resgrid.Web.Mcp/Infrastructure/TokenRefreshService.csRepository: Resgrid/Core Length of output: 5217 🏁 Script executed: cat -n Web/Resgrid.Web.Mcp/Infrastructure/AuditLogger.csRepository: Resgrid/Core Length of output: 6643 RateLimiter and ResponseCache are already properly thread-safe, but TokenRefreshService has a race condition. RateLimiter uses 🤖 Prompt for AI Agents |
||
|
|
||
| // Validate required API configuration from SystemBehaviorConfig | ||
| if (string.IsNullOrWhiteSpace(SystemBehaviorConfig.ResgridApiBaseUrl)) | ||
| { | ||
| throw new InvalidOperationException( | ||
| "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(SystemBehaviorConfig.ResgridApiBaseUrl); | ||
| client.DefaultRequestHeaders.Add("Accept", "application/json"); | ||
| client.Timeout = TimeSpan.FromSeconds(30); | ||
| }) | ||
| .ConfigurePrimaryHttpMessageHandler(() => new System.Net.Http.SocketsHttpHandler | ||
| { | ||
| PooledConnectionLifetime = TimeSpan.FromMinutes(5), | ||
| PooledConnectionIdleTimeout = TimeSpan.FromMinutes(2), | ||
| MaxConnectionsPerServer = 10 | ||
| }); | ||
|
|
||
| // Register API client | ||
| services.AddSingleton<IApiClient, ApiClient>(); | ||
|
|
||
| // Register tool providers | ||
| services.AddSingleton<AuthenticationToolProvider>(); | ||
| services.AddSingleton<CallsToolProvider>(); | ||
| services.AddSingleton<DispatchToolProvider>(); | ||
| services.AddSingleton<PersonnelToolProvider>(); | ||
| services.AddSingleton<UnitsToolProvider>(); | ||
| services.AddSingleton<MessagesToolProvider>(); | ||
| services.AddSingleton<CalendarToolProvider>(); | ||
| services.AddSingleton<ShiftsToolProvider>(); | ||
| services.AddSingleton<InventoryToolProvider>(); | ||
| services.AddSingleton<ReportsToolProvider>(); | ||
| services.AddSingleton<McpToolRegistry>(); | ||
| } | ||
|
|
||
| public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | ||
| { | ||
| app.UseRouting(); | ||
|
|
||
| app.UseEndpoints(endpoints => | ||
| { | ||
| endpoints.MapControllers(); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: Resgrid/Core
Length of output: 3757
🏁 Script executed:
Repository: Resgrid/Core
Length of output: 89
Good defensive null-safety improvement, but multiple other locations need the same fix.
Using null-conditional operators on
GetEntryAssembly()andVersionprevents potentialNullReferenceExceptionin hosted environments whereGetEntryAssembly()can returnnull. The change in Program.cs follows C# best practices.However, the codebase has multiple other unsafe usages of this same pattern:
Web/Resgrid.Web/Program.csline 59Web/Resgrid.Web.Services/Program.csline 58Web/Resgrid.Web.Eventing/Program.csline 57Workers/Resgrid.Workers.Console/Program.csline 103Web/Resgrid.Web/Controllers/HealthController.csline 35Web/Resgrid.Web.Services/Controllers/v4/HealthController.csline 42Web/Resgrid.Web.Eventing/Controllers/HealthController.csline 37Core/Resgrid.Framework/Logging.csline 40Apply the same null-conditional operator pattern to all these locations for consistency and safety.
🤖 Prompt for AI Agents