last ...
This commit is contained in:
@@ -1,12 +1,203 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using ModelContextProtocol.Client;
|
||||||
|
using xAiModels.Models.Dtos;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
using xIdentityModels.Models;
|
||||||
|
using xModels.Dtos;
|
||||||
|
|
||||||
namespace xAiApi.Interfaces
|
namespace xAiApi.Interfaces
|
||||||
{
|
{
|
||||||
public interface IXAiMcpServerProvider
|
public interface IXAiMcpServerProvider
|
||||||
{
|
{
|
||||||
|
//
|
||||||
|
#region Manager ...
|
||||||
|
/// <summary>
|
||||||
|
/// Get a List Of Available Tools which Provided using registered Mcp Servers ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="forceOwner"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IList<McpClientTool>> GetAvailableToolsAsync(
|
||||||
|
bool forceOwner = false,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test Specified Mcp Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="server"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<string> TestServerAsync(
|
||||||
|
XAiMcpServerDto server,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Force Refresh Mcp Servers ...
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task RefreshAsync();
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Actions ...
|
||||||
|
/// <summary>
|
||||||
|
/// Add an Mcp Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XAiMcpServerDto> AddMcpServer(
|
||||||
|
XAiMcpServerDto item,
|
||||||
|
string connectionId = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update Specified Mcp Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XAiMcpServerDto> UpdateMcpServer(
|
||||||
|
Guid id,
|
||||||
|
XAiMcpServerDto item,
|
||||||
|
string connectionId = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove Specified Mcp Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XAiMcpServerDto> RemoveMcpServer(
|
||||||
|
Guid id,
|
||||||
|
string connectionId = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Disable Specified Mcp Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<bool> DisableMcpServer(
|
||||||
|
Guid id,
|
||||||
|
string connectionId = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enable Specified Mcp Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<bool> EnableMcpServer(
|
||||||
|
Guid id,
|
||||||
|
string connectionId = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Toggle Specified Mcp Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<bool> ToggleMcpServer(
|
||||||
|
Guid id,
|
||||||
|
string connectionId = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve all Mcp Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="forceOwner"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<XAiMcpServerDto>> GetAll(
|
||||||
|
bool forceOwner = false,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Find Specified Mcp Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="forceOwner"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XAiMcpServerDto> FindOne(
|
||||||
|
Expression<Func<XAiMcpServer, bool>> predicate,
|
||||||
|
bool forceOwner = false,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Find a Collection of Specified Mcp Servers ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="forceOwner"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<XAiMcpServerDto>> FindMany(
|
||||||
|
Expression<Func<XAiMcpServer, bool>> predicate,
|
||||||
|
bool forceOwner = false,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Query Registered Mcp Servers ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="forceOwner"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XQueryResult<XAiMcpServerDto>> Query(
|
||||||
|
XQuery query,
|
||||||
|
bool forceOwner = false,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,6 +77,13 @@ namespace xAiApi.Providers
|
|||||||
|
|
||||||
//
|
//
|
||||||
#region Manager ...
|
#region Manager ...
|
||||||
|
/// <summary>
|
||||||
|
/// Get a List Of Available Tools which Provided using registered Mcp Servers ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="forceOwner"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public async Task<IList<McpClientTool>> GetAvailableToolsAsync(
|
public async Task<IList<McpClientTool>> GetAvailableToolsAsync(
|
||||||
bool forceOwner = false,
|
bool forceOwner = false,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
XUserClaimsInfoDto userInfo = null,
|
||||||
@@ -162,6 +169,12 @@ namespace xAiApi.Providers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test Specified Mcp Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="server"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public async Task<string> TestServerAsync(
|
public async Task<string> TestServerAsync(
|
||||||
XAiMcpServerDto server,
|
XAiMcpServerDto server,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
@@ -190,6 +203,10 @@ namespace xAiApi.Providers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Force Refresh Mcp Servers ...
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
public async Task RefreshAsync()
|
public async Task RefreshAsync()
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -281,6 +298,17 @@ namespace xAiApi.Providers
|
|||||||
source: result,
|
source: result,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
await initLock.WaitAsync(cancellationToken);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await ConnectAndValidateAsync(result, cancellationToken);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
initLock.Release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -367,6 +395,25 @@ namespace xAiApi.Providers
|
|||||||
source: result,
|
source: result,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
await initLock.WaitAsync(cancellationToken);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Remove Exists ...
|
||||||
|
tools.Remove(result.Id);
|
||||||
|
clients.Remove(result.Id);
|
||||||
|
mcpServers.Remove(result.Id);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Update ...
|
||||||
|
await ConnectAndValidateAsync(result, cancellationToken);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
initLock.Release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -436,6 +483,21 @@ namespace xAiApi.Providers
|
|||||||
source: result,
|
source: result,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
await initLock.WaitAsync(cancellationToken);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Remove Exists ...
|
||||||
|
tools.Remove(result.Id);
|
||||||
|
clients.Remove(result.Id);
|
||||||
|
mcpServers.Remove(result.Id);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
initLock.Release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -504,6 +566,25 @@ namespace xAiApi.Providers
|
|||||||
);
|
);
|
||||||
var result = !exists.IsNullOrDefault() && !exists.Enabled;
|
var result = !exists.IsNullOrDefault() && !exists.Enabled;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
await initLock.WaitAsync(cancellationToken);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Remove Exists ...
|
||||||
|
tools.Remove(exists.Id);
|
||||||
|
clients.Remove(exists.Id);
|
||||||
|
mcpServers.Remove(exists.Id);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
initLock.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -570,10 +651,25 @@ namespace xAiApi.Providers
|
|||||||
);
|
);
|
||||||
var result = !exists.IsNullOrDefault() && exists.Enabled;
|
var result = !exists.IsNullOrDefault() && exists.Enabled;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
await initLock.WaitAsync(cancellationToken);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await ConnectAndValidateAsync(exists, cancellationToken);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
initLock.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Toggle Specified Mcp Server ...
|
/// Toggle Specified Mcp Server ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -632,6 +728,32 @@ namespace xAiApi.Providers
|
|||||||
);
|
);
|
||||||
var result = !exists.IsNullOrDefault();
|
var result = !exists.IsNullOrDefault();
|
||||||
|
|
||||||
|
//
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
await initLock.WaitAsync(cancellationToken);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (exists.Enabled)
|
||||||
|
{
|
||||||
|
await ConnectAndValidateAsync(exists, cancellationToken);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Remove Exists ...
|
||||||
|
tools.Remove(exists.Id);
|
||||||
|
clients.Remove(exists.Id);
|
||||||
|
mcpServers.Remove(exists.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
initLock.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -780,7 +902,15 @@ namespace xAiApi.Providers
|
|||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Find a Collection of Specified Mcp Servers ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="forceOwner"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public async Task<IEnumerable<XAiMcpServerDto>> FindMany(
|
public async Task<IEnumerable<XAiMcpServerDto>> FindMany(
|
||||||
Expression<Func<XAiMcpServer, bool>> predicate,
|
Expression<Func<XAiMcpServer, bool>> predicate,
|
||||||
bool forceOwner = false,
|
bool forceOwner = false,
|
||||||
@@ -845,6 +975,14 @@ namespace xAiApi.Providers
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Query Registered Mcp Servers ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="forceOwner"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public async Task<XQueryResult<XAiMcpServerDto>> Query(
|
public async Task<XQueryResult<XAiMcpServerDto>> Query(
|
||||||
XQuery query,
|
XQuery query,
|
||||||
bool forceOwner = false,
|
bool forceOwner = false,
|
||||||
|
|||||||
Reference in New Issue
Block a user