Skip to content

Commit a5b56ea

Browse files
authored
[mcp] Renamed various types and methods to support other MCP features (#8968)
1 parent ec74e8b commit a5b56ea

18 files changed

+94
-93
lines changed

src/HotChocolate/Adapters/src/Adapters.Mcp.Core/Extensions/ServiceCollectionExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ public static void AddMcpSchemaServices(
6161

6262
services
6363
.TryAddSingleton(
64-
static sp => new ToolStorageObserver(
64+
static sp => new McpStorageObserver(
6565
sp.GetRequiredService<ISchemaDefinition>(),
66-
sp.GetRequiredService<ToolRegistry>(),
66+
sp.GetRequiredService<McpFeatureRegistry>(),
6767
sp.GetRequiredService<OperationToolFactory>(),
6868
sp.GetRequiredService<ConcurrentDictionary<string, McpServer>>(),
69-
sp.GetRequiredService<IOperationToolStorage>(),
69+
sp.GetRequiredService<IMcpStorage>(),
7070
sp.GetRequiredService<IMcpDiagnosticEvents>()));
7171

7272
services
@@ -78,7 +78,7 @@ public static void AddMcpSchemaServices(
7878
static sp => sp
7979
.GetRequiredService<IRootServiceProviderAccessor>().ServiceProvider
8080
.GetRequiredService<ILoggerFactory>())
81-
.AddSingleton<ToolRegistry>();
81+
.AddSingleton<McpFeatureRegistry>();
8282

8383
var mcpServers = new ConcurrentDictionary<string, McpServer>();
8484
services.AddSingleton(mcpServers);

src/HotChocolate/Adapters/src/Adapters.Mcp.Core/Handlers/CallToolHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static async ValueTask<CallToolResult> HandleAsync(
2121
CancellationToken cancellationToken)
2222
{
2323
var services = context.Services!;
24-
var registry = services.GetRequiredService<ToolRegistry>();
24+
var registry = services.GetRequiredService<McpFeatureRegistry>();
2525

2626
if (!registry.TryGetTool(context.Params!.Name, out var tool))
2727
{

src/HotChocolate/Adapters/src/Adapters.Mcp.Core/Handlers/ListResourcesHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ internal static class ListResourcesHandler
88
{
99
public static ListResourcesResult Handle(RequestContext<ListResourcesRequestParams> context)
1010
{
11-
var toolRegistry = context.Services!.GetRequiredService<ToolRegistry>();
11+
var registry = context.Services!.GetRequiredService<McpFeatureRegistry>();
1212

1313
var openAiComponentResources =
14-
toolRegistry
14+
registry
1515
.GetTools()
1616
.Select(t => t.OpenAiComponentResource)
1717
.OfType<Resource>()

src/HotChocolate/Adapters/src/Adapters.Mcp.Core/Handlers/ListToolsHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal static class ListToolsHandler
88
{
99
public static ListToolsResult Handle(RequestContext<ListToolsRequestParams> context)
1010
{
11-
var registry = context.Services!.GetRequiredService<ToolRegistry>();
11+
var registry = context.Services!.GetRequiredService<McpFeatureRegistry>();
1212

1313
return new ListToolsResult
1414
{

src/HotChocolate/Adapters/src/Adapters.Mcp.Core/Handlers/ReadResourceHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ internal static class ReadResourceHandler
1010
{
1111
public static ReadResourceResult Handle(RequestContext<ReadResourceRequestParams> context)
1212
{
13-
var toolRegistry = context.Services!.GetRequiredService<ToolRegistry>();
13+
var registry = context.Services!.GetRequiredService<McpFeatureRegistry>();
1414

15-
if (!toolRegistry.TryGetToolByOpenAiComponentResourceUri(context.Params!.Uri, out var tool))
15+
if (!registry.TryGetToolByOpenAiComponentResourceUri(context.Params!.Uri, out var tool))
1616
{
1717
// TODO: See https://github.com/modelcontextprotocol/csharp-sdk/issues/1025.
1818
throw new McpProtocolException(

src/HotChocolate/Adapters/src/Adapters.Mcp.Core/ToolRegistry.cs renamed to src/HotChocolate/Adapters/src/Adapters.Mcp.Core/McpFeatureRegistry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace HotChocolate.Adapters.Mcp;
66

7-
internal sealed class ToolRegistry
7+
internal sealed class McpFeatureRegistry
88
{
99
private FrozenDictionary<string, OperationTool> _tools
1010
= FrozenDictionary<string, OperationTool>.Empty;

src/HotChocolate/Adapters/src/Adapters.Mcp.Core/ToolStorageObserver.cs renamed to src/HotChocolate/Adapters/src/Adapters.Mcp.Core/McpStorageObserver.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111

1212
namespace HotChocolate.Adapters.Mcp;
1313

14-
internal sealed class ToolStorageObserver : IDisposable
14+
internal sealed class McpStorageObserver : IDisposable
1515
{
1616
private readonly SemaphoreSlim _semaphore = new(initialCount: 1, maxCount: 1);
1717
private readonly CancellationTokenSource _cts = new();
1818
private readonly CancellationToken _ct;
1919
private readonly ISchemaDefinition _schema;
20-
private readonly ToolRegistry _registry;
20+
private readonly McpFeatureRegistry _registry;
2121
private readonly OperationToolFactory _toolFactory;
2222
private readonly ConcurrentDictionary<string, McpServer> _mcpServers;
23-
private readonly IOperationToolStorage _storage;
23+
private readonly IMcpStorage _storage;
2424
private readonly IMcpDiagnosticEvents _diagnosticEvents;
2525
private IDisposable? _subscription;
2626
#if NET10_0_OR_GREATER
@@ -32,12 +32,12 @@ private static readonly DocumentValidator s_documentValidator
3232
= DocumentValidatorBuilder.New().AddDefaultRules().Build();
3333
private bool _disposed;
3434

35-
public ToolStorageObserver(
35+
public McpStorageObserver(
3636
ISchemaDefinition schema,
37-
ToolRegistry registry,
37+
McpFeatureRegistry registry,
3838
OperationToolFactory toolFactory,
3939
ConcurrentDictionary<string, McpServer> mcpServers,
40-
IOperationToolStorage storage,
40+
IMcpStorage storage,
4141
IMcpDiagnosticEvents diagnosticEvents)
4242
{
4343
_schema = schema;
@@ -71,7 +71,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
7171

7272
using var scope = _diagnosticEvents.InitializeTools();
7373

74-
foreach (var toolDefinition in await _storage.GetToolsAsync(cancellationToken))
74+
foreach (var toolDefinition in await _storage.GetOperationToolDefinitionsAsync(cancellationToken))
7575
{
7676
var validationResult = s_documentValidator.Validate(_schema, toolDefinition.Document);
7777

src/HotChocolate/Adapters/src/Adapters.Mcp.Core/OperationToolFactory.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,30 +181,30 @@ private static Resource CreateOpenAiComponentResource(
181181
meta["openai/widgetPrefersBorder"] = openAiComponent.PrefersBorder;
182182
}
183183

184-
if (openAiComponent.ContentSecurityPolicy is { } contentSecurityPolicy)
184+
if (openAiComponent.Csp is { } csp)
185185
{
186-
JsonObject? csp = null;
186+
JsonObject? contentSecurityPolicy = null;
187187

188-
if (contentSecurityPolicy.ConnectDomains is { Length: > 0 } connectDomains)
188+
if (csp.ConnectDomains is { Length: > 0 } connectDomains)
189189
{
190-
csp ??= new JsonObject();
191-
csp.Add(
190+
contentSecurityPolicy ??= new JsonObject();
191+
contentSecurityPolicy.Add(
192192
"connect_domains",
193193
new JsonArray(connectDomains.Select(d => JsonValue.Create(d)).ToArray<JsonNode>()));
194194
}
195195

196-
if (contentSecurityPolicy.ResourceDomains is { Length: > 0 } resourceDomains)
196+
if (csp.ResourceDomains is { Length: > 0 } resourceDomains)
197197
{
198-
csp ??= new JsonObject();
199-
csp.Add(
198+
contentSecurityPolicy ??= new JsonObject();
199+
contentSecurityPolicy.Add(
200200
"resource_domains",
201201
new JsonArray(resourceDomains.Select(d => JsonValue.Create(d)).ToArray<JsonNode>()));
202202
}
203203

204-
if (csp is not null)
204+
if (contentSecurityPolicy is not null)
205205
{
206206
meta ??= new JsonObject();
207-
meta.Add("openai/widgetCSP", csp);
207+
meta.Add("openai/widgetCSP", contentSecurityPolicy);
208208
}
209209
}
210210

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace HotChocolate.Adapters.Mcp.Storage;
2+
3+
/// <summary>
4+
/// Provides access to MCP feature definitions with change notification support.
5+
/// Implementations can retrieve definitions from various sources (file system, database, etc.).
6+
/// The Hot Chocolate MCP server will observe the <see cref="IMcpStorage"/>
7+
/// and when changes are detected will phase in new definitions, update definitions, or phase out
8+
/// definitions that have been removed from the storage.
9+
/// </summary>
10+
public interface IMcpStorage : IObservable<OperationToolStorageEventArgs>
11+
{
12+
/// <summary>
13+
/// Retrieves all available operation tool definitions from the storage.
14+
/// </summary>
15+
/// <param name="cancellationToken">Token to cancel the operation.</param>
16+
/// <returns>A collection of all available operation tool definitions.</returns>
17+
ValueTask<IEnumerable<OperationToolDefinition>> GetOperationToolDefinitionsAsync(
18+
CancellationToken cancellationToken = default);
19+
}

src/HotChocolate/Adapters/src/Adapters.Mcp.Core/Storage/IOperationToolStorage.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)