Refactor MCP Server and Complete it ...
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
using xCommons.Providers;
|
||||
using xCommons.Extensions;
|
||||
using xCommons.Controllers;
|
||||
using xExceptions.Constants;
|
||||
using xCommons.Configurations;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
@@ -44,20 +41,5 @@ namespace xAiApi.Controllers
|
||||
//
|
||||
return Ok(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Global Exception Handler Endpoint (Production) ...
|
||||
/// Returns a Generic Error without Leaking Exception Details ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[Route("error")]
|
||||
[ApiExplorerSettings(IgnoreApi = true)]
|
||||
public virtual ActionResult Error()
|
||||
{
|
||||
//
|
||||
var error = XException.ActionFailed.ToXError();
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
-12
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Grapevine;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace xAiMcpServer
|
||||
{
|
||||
@@ -8,19 +9,23 @@ namespace xAiMcpServer
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
//
|
||||
var server = RestServerBuilder
|
||||
.From<Startup>()
|
||||
.Build();
|
||||
|
||||
//
|
||||
server.Start();
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
|
||||
//
|
||||
Console.WriteLine("MCP Server running on https://localhost:7001/mcp");
|
||||
Console.ReadLine();
|
||||
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args)
|
||||
{
|
||||
//
|
||||
var result = Host.CreateDefaultBuilder(args)
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<Startup>();
|
||||
});
|
||||
|
||||
//
|
||||
server.Stop();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-15
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Grapevine;
|
||||
using System.Net.Http;
|
||||
using xAiMcpServer.DI;
|
||||
using Newtonsoft.Json;
|
||||
@@ -9,7 +8,6 @@ using xIdentityService.DI;
|
||||
using xCommons.Extensions;
|
||||
using xAiService.Extensions;
|
||||
using xCommons.Configurations;
|
||||
using Grapevine.Extensions.Mcp;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
@@ -91,21 +89,12 @@ namespace xAiMcpServer
|
||||
lifeTime: lifeTime,
|
||||
configuration: Configuration
|
||||
);
|
||||
|
||||
//
|
||||
// Register MCP Server ...
|
||||
services
|
||||
.AddMcpServer()
|
||||
.WithHttpTransport()
|
||||
.WithToolsFromAssembly();
|
||||
}
|
||||
|
||||
public void ConfigureServer(IRestServer server)
|
||||
{
|
||||
server.Prefixes.Add("https://localhost:7001/");
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
public void Configure(
|
||||
IApplicationBuilder app,
|
||||
IWebHostEnvironment env
|
||||
)
|
||||
{
|
||||
//
|
||||
// Configure the HTTP request pipeline ...
|
||||
|
||||
+8
-6
@@ -1,14 +1,16 @@
|
||||
using System.ComponentModel;
|
||||
using ModelContextProtocol.Server;
|
||||
|
||||
using xAiModels.Attributes;
|
||||
|
||||
namespace xAiMcpServer.Tools
|
||||
{
|
||||
[McpServerToolType]
|
||||
[XAiMcpToolType]
|
||||
public static class XEchoTools
|
||||
{
|
||||
[McpServerTool,
|
||||
Description("Echoes the message back to the client.")]
|
||||
public static string Echo(string message)
|
||||
[XAiMcpTool(Description = "Echoes the string back to the client give message in string")]
|
||||
public static string Echo(
|
||||
[XAiMcpToolParam(Description = "string value which specified message")]
|
||||
string message
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = $"hello {message}";
|
||||
|
||||
+3
-2
@@ -34,9 +34,10 @@
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user