diff --git a/Interfaces/IXAiMcpServerProvider.cs b/Interfaces/IXAiMcpServerProvider.cs
index 0cd7940..251263e 100644
--- a/Interfaces/IXAiMcpServerProvider.cs
+++ b/Interfaces/IXAiMcpServerProvider.cs
@@ -1,12 +1,203 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Linq.Expressions;
+using System.Threading;
using System.Threading.Tasks;
+using ModelContextProtocol.Client;
+using xAiModels.Models.Dtos;
+using xAiModels.Models.Entities;
+using xIdentityModels.Models;
+using xModels.Dtos;
namespace xAiApi.Interfaces
{
public interface IXAiMcpServerProvider
{
-
+ //
+ #region Manager ...
+ ///
+ /// Get a List Of Available Tools which Provided using registered Mcp Servers ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task> GetAvailableToolsAsync(
+ bool forceOwner = false,
+ XUserClaimsInfoDto userInfo = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Test Specified Mcp Server ...
+ ///
+ ///
+ ///
+ ///
+ Task TestServerAsync(
+ XAiMcpServerDto server,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Force Refresh Mcp Servers ...
+ ///
+ ///
+ Task RefreshAsync();
+ #endregion
+
+ //
+ #region Actions ...
+ ///
+ /// Add an Mcp Server ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task AddMcpServer(
+ XAiMcpServerDto item,
+ string connectionId = null,
+ XUserClaimsInfoDto userInfo = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Update Specified Mcp Server ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task UpdateMcpServer(
+ Guid id,
+ XAiMcpServerDto item,
+ string connectionId = null,
+ XUserClaimsInfoDto userInfo = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Remove Specified Mcp Server ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task RemoveMcpServer(
+ Guid id,
+ string connectionId = null,
+ XUserClaimsInfoDto userInfo = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Disable Specified Mcp Server ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task DisableMcpServer(
+ Guid id,
+ string connectionId = null,
+ XUserClaimsInfoDto userInfo = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Enable Specified Mcp Server ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task EnableMcpServer(
+ Guid id,
+ string connectionId = null,
+ XUserClaimsInfoDto userInfo = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Toggle Specified Mcp Server ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task ToggleMcpServer(
+ Guid id,
+ string connectionId = null,
+ XUserClaimsInfoDto userInfo = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Retrieve all Mcp Server ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task> GetAll(
+ bool forceOwner = false,
+ XUserClaimsInfoDto userInfo = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Find Specified Mcp Server ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task FindOne(
+ Expression> predicate,
+ bool forceOwner = false,
+ XUserClaimsInfoDto userInfo = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Find a Collection of Specified Mcp Servers ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task> FindMany(
+ Expression> predicate,
+ bool forceOwner = false,
+ XUserClaimsInfoDto userInfo = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Query Registered Mcp Servers ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task> Query(
+ XQuery query,
+ bool forceOwner = false,
+ XUserClaimsInfoDto userInfo = null,
+ CancellationToken cancellationToken = default
+ );
+ #endregion
}
}
\ No newline at end of file
diff --git a/Providers/XAiMcpServerProvider.cs b/Providers/XAiMcpServerProvider.cs
index 6b83d07..6b527ae 100644
--- a/Providers/XAiMcpServerProvider.cs
+++ b/Providers/XAiMcpServerProvider.cs
@@ -77,6 +77,13 @@ namespace xAiApi.Providers
//
#region Manager ...
+ ///
+ /// Get a List Of Available Tools which Provided using registered Mcp Servers ...
+ ///
+ ///
+ ///
+ ///
+ ///
public async Task> GetAvailableToolsAsync(
bool forceOwner = false,
XUserClaimsInfoDto userInfo = null,
@@ -162,6 +169,12 @@ namespace xAiApi.Providers
}
}
+ ///
+ /// Test Specified Mcp Server ...
+ ///
+ ///
+ ///
+ ///
public async Task TestServerAsync(
XAiMcpServerDto server,
CancellationToken cancellationToken = default
@@ -190,6 +203,10 @@ namespace xAiApi.Providers
}
}
+ ///
+ /// Force Refresh Mcp Servers ...
+ ///
+ ///
public async Task RefreshAsync()
{
//
@@ -281,6 +298,17 @@ namespace xAiApi.Providers
source: result,
cancellationToken: cancellationToken
);
+
+ //
+ await initLock.WaitAsync(cancellationToken);
+ try
+ {
+ await ConnectAndValidateAsync(result, cancellationToken);
+ }
+ finally
+ {
+ initLock.Release();
+ }
}
//
@@ -367,6 +395,25 @@ namespace xAiApi.Providers
source: result,
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,
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;
+ //
+ 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;
}
@@ -570,10 +651,25 @@ namespace xAiApi.Providers
);
var result = !exists.IsNullOrDefault() && exists.Enabled;
+ //
+ if (result)
+ {
+ //
+ await initLock.WaitAsync(cancellationToken);
+ try
+ {
+ await ConnectAndValidateAsync(exists, cancellationToken);
+ }
+ finally
+ {
+ initLock.Release();
+ }
+ }
+
//
return result;
}
-
+
///
/// Toggle Specified Mcp Server ...
///
@@ -632,6 +728,32 @@ namespace xAiApi.Providers
);
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;
}
@@ -780,7 +902,15 @@ namespace xAiApi.Providers
//
return result;
}
-
+
+ ///
+ /// Find a Collection of Specified Mcp Servers ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
public async Task> FindMany(
Expression> predicate,
bool forceOwner = false,
@@ -845,6 +975,14 @@ namespace xAiApi.Providers
return result;
}
+ ///
+ /// Query Registered Mcp Servers ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
public async Task> Query(
XQuery query,
bool forceOwner = false,