adding Simple Web Search Tool, Untested ...
This commit is contained in:
+92
-3
@@ -2,12 +2,18 @@ using System.Linq;
|
||||
using xIdentityHelper;
|
||||
using xAiMcpServer.Tools;
|
||||
using xCommons.Extensions;
|
||||
using xExceptions.Constants;
|
||||
using xCommons.Authorization;
|
||||
using xAiMcpServer.Constants;
|
||||
using xAiMcpServer.Providers;
|
||||
using xAiMcpServer.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
using xIdentityService.Interfaces;
|
||||
using xAiMcpServer.Configurations;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace xAiMcpServer.DI
|
||||
@@ -44,7 +50,7 @@ namespace xAiMcpServer.DI
|
||||
var roleRequirements = policyDescriptor.Value.Requirements
|
||||
.OfType<RequiredRolesRequirement>()
|
||||
.FirstOrDefault();
|
||||
if (!roleRequirements.IsNull() &&
|
||||
if (!roleRequirements.IsNull() &&
|
||||
roleRequirements.Roles.HasChild())
|
||||
{
|
||||
//
|
||||
@@ -84,7 +90,7 @@ namespace xAiMcpServer.DI
|
||||
var roleRequirements = policyDescriptor.Value.Requirements
|
||||
.OfType<RequiredRolesRequirement>()
|
||||
.FirstOrDefault();
|
||||
if (!roleRequirements.IsNull() &&
|
||||
if (!roleRequirements.IsNull() &&
|
||||
roleRequirements.Roles.HasChild())
|
||||
{
|
||||
//
|
||||
@@ -126,14 +132,97 @@ namespace xAiMcpServer.DI
|
||||
source.UseForwardedHeaders(forwardOptions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extract Web Search Tool Configuration ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static XAiMcpWebSearchToolConfiguration GetXAiMcpWebSearchToolConfiguration(
|
||||
this IConfiguration source
|
||||
)
|
||||
{
|
||||
//
|
||||
XAiMcpWebSearchToolConfiguration result = null;
|
||||
|
||||
//
|
||||
var section = source.GetSection(ConfigurationNodeNames.WEB_SEARCH_TOOL_NODE);
|
||||
if (!section.IsNull())
|
||||
{
|
||||
result = section.Get<XAiMcpWebSearchToolConfiguration>();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inject Web Search MCP Tool Configuration and Register it ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="configuration"></param>
|
||||
public static void AddXAiMcpWebSearchToolConfiguration(
|
||||
this IServiceCollection source,
|
||||
IConfiguration configuration
|
||||
)
|
||||
{
|
||||
//
|
||||
var config = configuration.GetXAiMcpWebSearchToolConfiguration();
|
||||
source.AddXAiMcpWebSearchToolConfiguration(config);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register Web Search MCP Tool Configuration ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="configuration"></param>
|
||||
public static void AddXAiMcpWebSearchToolConfiguration(
|
||||
this IServiceCollection source,
|
||||
XAiMcpWebSearchToolConfiguration configuration
|
||||
)
|
||||
{
|
||||
//
|
||||
if (configuration.IsNull())
|
||||
{
|
||||
XException.InvalidConfiguration.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
source.AddSingleton(configuration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register Tools which required Dependency Injection Services ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
public static void AddXAiMcpTools(this IServiceCollection source)
|
||||
public static void AddXAiMcpTools(
|
||||
this IServiceCollection source,
|
||||
IConfiguration configuration
|
||||
)
|
||||
{
|
||||
//
|
||||
// User Tools ...
|
||||
source.AddScoped<XUserTools>();
|
||||
|
||||
//
|
||||
#region Web Search Tool ...
|
||||
//
|
||||
// Register Memory Cache which used in Search Service ...
|
||||
source.AddMemoryCache();
|
||||
|
||||
//
|
||||
// Register Search Tool Configuration ...
|
||||
source.AddXAiMcpWebSearchToolConfiguration(configuration);
|
||||
|
||||
//
|
||||
// Register HttpClient ...
|
||||
// Since we Have Falling Back Endpoint, (more than one Endpoint),
|
||||
// we Doesn't pass Base Url ...
|
||||
source.AddHttpClient<IXAiMcpWebSearchService, XAiMcpWebSearchService>();
|
||||
|
||||
//
|
||||
// Register Web Search Tool ...
|
||||
source.AddScoped<XWebSearchTool>();
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user