using System.Threading; using xCommons.Providers; using Newtonsoft.Json.Linq; using xAiService.Interfaces; using System.Threading.Tasks; using xCommons.Configurations; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Http; using xIdentityService.Interfaces; using Microsoft.Extensions.Logging; using xIdentityService.Controllers; using Microsoft.AspNetCore.Authorization; namespace xAiService.Controllers { [Route("mcp")] [AllowAnonymous] public abstract class XAiMcpControllerBase : XBaseIdentityApiV1Controller { private readonly IXAiMcpHandler mcpHandler; protected XAiMcpControllerBase( IXAiMcpHandler mcpHandler, XAppConfiguration appConfiguration, IXIdentityProvider identityProvider, ILogger logger, XValidationProvider validationProvider ) : base(logger, appConfiguration, identityProvider, validationProvider) { this.mcpHandler = mcpHandler; } /// /// Handle MCP ... /// /// /// /// [HttpPost] public virtual async Task HandleMcp( [FromBody] JObject request, CancellationToken cancellationToken = default ) { // var userInfo = await GetUserInfo(); var connectionId = GetConnectionId(); // var response = await mcpHandler.ProcessAsync( request: request, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); // return Ok(response); } /// /// Handle SSE EndPoint ... /// /// /// [HttpGet("sse")] public virtual async Task SseEndpoint( CancellationToken cancellationToken = default ) { // Response.Headers.Add("Content-Type", "text/event-stream"); Response.Headers.Add("Cache-Control", "no-cache"); // await Response .WriteAsync( "event: endpoint\ndata: /mcp\n\n", cancellationToken ); // await Response.Body.FlushAsync(cancellationToken); // while (!cancellationToken.IsCancellationRequested) { await Task.Delay(1000, cancellationToken); } } } }