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