Skip to content

Commit 3948822

Browse files
author
Jerry Nixon
committed
Tweaking tooling adding tests
1 parent 8d015c0 commit 3948822

20 files changed

Lines changed: 235 additions & 147 deletions

src/.filenesting.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"help": "https://go.microsoft.com/fwlink/?linkid=866610"
3+
4+
"root": true,
5+
"dependentFileProviders": {
6+
"add": {
7+
"addedExtension": {}
8+
}
9+
}
10+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
<IsTestProject>true</IsTestProject>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" />
14+
<PackageReference Include="Microsoft.AspNetCore.TestHost" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" />
16+
<PackageReference Include="Microsoft.OpenApi" />
17+
<PackageReference Include="Microsoft.OpenApi.Readers" />
18+
<PackageReference Include="Moq" />
19+
<PackageReference Include="MSTest.TestAdapter" />
20+
<PackageReference Include="MSTest.TestFramework" />
21+
<PackageReference Include="coverlet.collector">
22+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
23+
<PrivateAssets>all</PrivateAssets>
24+
</PackageReference>
25+
<PackageReference Include="HotChocolate" />
26+
<PackageReference Include="Newtonsoft.Json" />
27+
<PackageReference Include="System.IO.Abstractions.TestingHelpers" />
28+
<PackageReference Include="Verify.MSTest" />
29+
<PackageReference Include="Verify.DiffPlex" />
30+
</ItemGroup>
31+
32+
<ItemGroup>
33+
<ProjectReference Include="..\Azure.DataApiBuilder.Mcp\Azure.DataApiBuilder.Mcp.csproj" />
34+
</ItemGroup>
35+
36+
<ItemGroup>
37+
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
38+
</ItemGroup>
39+
40+
</Project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
namespace Azure.DataApiBuilder.Mcp.Tests
5+
{
6+
[TestClass]
7+
public class McpExtensionsTests
8+
{
9+
[TestMethod]
10+
public void Test()
11+
{
12+
Assert.IsTrue(true);
13+
}
14+
}
15+
}

src/Azure.DataApiBuilder.Mcp/Extensions.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ public static IServiceCollection AddDabMcpServer(this IServiceCollection service
2020
{
2121
if (runtimeConfigProvider.TryGetConfig(out RuntimeConfig? runtimeConfig))
2222
{
23-
_mcpOptions = runtimeConfig?.Ai?.Mcp ?? throw new NullReferenceException("Configuration is required.");
23+
_mcpOptions = runtimeConfig?.Mcp ?? throw new NullReferenceException("Configuration is required.");
2424
}
2525

26-
services.AddDmlTools(_mcpOptions);
27-
28-
services
26+
_ = services
27+
.AddDmlTools(_mcpOptions)
2928
.AddMcpServer()
3029
.AddMcpHealthChecks()
3130
.WithHttpTransport();

src/Azure.DataApiBuilder.Mcp/Tools/SchemaLogic.cs renamed to src/Azure.DataApiBuilder.Mcp/GraphQL/SchemaLogic.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,9 @@ private static List<object> BuildFieldsFromSchema(IObjectType objectType)
331331
{
332332
Name = value.field.Name,
333333
Type = MapGraphQLTypeToString(value.field.Type),
334-
Nullable = isNullable,
335-
HasDefault = hasDefaultValue,
336-
ReadOnly = isStoredProcedure || isAutoGenerated, // All stored procedure fields arereadonly
334+
Required = !isNullable,
335+
// HasDefault = hasDefaultValue,
336+
// ReadOnly = isStoredProcedure || isAutoGenerated, // All stored procedure fields arereadonly
337337
Description = value.field.Description ?? $"Field {value.field.Name} of type {GetBaseTypeName(value.field.Type)}"
338338
});
339339
}
@@ -432,21 +432,21 @@ private async Task<object> BuildActionParametersFromSchema(EntityActionOperation
432432
case EntityActionOperation.Create:
433433
return new
434434
{
435-
Entity = "String!",
435+
Entity = entityName,
436436
Fields = await GetCreateFieldParametersFromSchema(entityName)
437437
};
438438

439439
case EntityActionOperation.Update:
440440
return new
441441
{
442-
Entity = "String!",
442+
Entity = entityName,
443443
Fields = await GetUpdateFieldParametersFromSchema(entityName)
444444
};
445445

446446
case EntityActionOperation.Read:
447447
return new
448448
{
449-
Entity = "String!",
449+
Entity = entityName,
450450
Filters = "Object",
451451
First = "Int",
452452
After = "String"
@@ -455,14 +455,14 @@ private async Task<object> BuildActionParametersFromSchema(EntityActionOperation
455455
case EntityActionOperation.Delete:
456456
return new
457457
{
458-
Entity = "String!",
458+
Entity = entityName,
459459
Id = GetPrimaryKeyParametersFromSchema(objectType)
460460
};
461461

462462
case EntityActionOperation.Execute:
463463
return new
464464
{
465-
Entity = "String!",
465+
Entity = entityName,
466466
Fields = await GetStoredProcedureParametersFromSchema(entityName)
467467
};
468468

src/Azure.DataApiBuilder.Mcp/Health/ClientConnectionHealthCheck.cs renamed to src/Azure.DataApiBuilder.Mcp/Health/Checks/McpRegistrationCheck.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
using Microsoft.Extensions.Logging;
77
using ModelContextProtocol.Client;
88

9-
namespace Azure.DataApiBuilder.Mcp.Health;
9+
namespace Azure.DataApiBuilder.Mcp.Health.Checks;
1010

1111
/// <summary>
1212
/// Attempts to connect to local MCP SSE endpoint and list tools.
1313
/// </summary>
14-
public sealed class ClientConnectionHealthCheck : IHealthCheck
14+
public sealed class McpRegistrationCheck : IHealthCheck
1515
{
1616
private readonly IHttpContextAccessor _http;
17-
private readonly ILogger<ClientConnectionHealthCheck> _logger;
17+
private readonly ILogger<McpRegistrationCheck> _logger;
1818
private readonly ILoggerFactory _loggerFactory;
1919

20-
public ClientConnectionHealthCheck(IHttpContextAccessor http, ILogger<ClientConnectionHealthCheck> logger, ILoggerFactory loggerFactory)
20+
public McpRegistrationCheck(IHttpContextAccessor http, ILogger<McpRegistrationCheck> logger, ILoggerFactory loggerFactory)
2121
{
2222
_http = http;
2323
_logger = logger;

src/Azure.DataApiBuilder.Mcp/Health/Extensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System.Diagnostics.CodeAnalysis;
5+
using Azure.DataApiBuilder.Mcp.Health.Checks;
56
using Microsoft.AspNetCore.Builder;
67
using Microsoft.AspNetCore.Routing;
78
using Microsoft.Extensions.DependencyInjection;
@@ -16,8 +17,7 @@ public static IMcpServerBuilder AddMcpHealthChecks(this IMcpServerBuilder builde
1617
{
1718
_ = builder.Services.AddHttpContextAccessor();
1819
_ = builder.Services.AddHealthChecks()
19-
.AddCheck<ClientConnectionHealthCheck>("MCP Registration", tags: [MCP_TAG])
20-
.AddCheck<ListEntitiesHealthCheck>("MCP Tool: list_entities", tags: [MCP_TAG]);
20+
.AddCheck<McpRegistrationCheck>("MCP Registration", tags: [MCP_TAG]);
2121
return builder;
2222
}
2323

src/Azure.DataApiBuilder.Mcp/Health/ListEntitiesHealthCheck.cs

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

src/Azure.DataApiBuilder.Mcp/Health/McpHealthCheckOptions.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,17 @@ public class McpHealthCheckOptions : HealthCheckOptions
2121

2222
public McpHealthCheckOptions(string tag)
2323
{
24-
ResultStatusCodes.Clear();
25-
ResultStatusCodes.Add(HealthStatus.Healthy, StatusCodes.Status200OK);
26-
ResultStatusCodes.Add(HealthStatus.Degraded, StatusCodes.Status200OK);
27-
ResultStatusCodes.Add(HealthStatus.Unhealthy, StatusCodes.Status503ServiceUnavailable);
28-
2924
AllowCachingResponses = true;
30-
3125
ResponseWriter = WriteAsync;
32-
3326
Predicate = r => r.Tags.Contains(tag);
3427
}
3528

36-
private Task WriteAsync(HttpContext context, HealthReport report)
29+
private async Task WriteAsync(HttpContext context, HealthReport report)
3730
{
31+
string json = await new Tools
32+
.SchemaLogic(context.RequestServices)
33+
.GetEntityMetadataAsJsonAsync();
34+
3835
var response = new
3936
{
4037
status = report.Status.ToString(),
@@ -45,10 +42,11 @@ private Task WriteAsync(HttpContext context, HealthReport report)
4542
status = kvp.Value.Status.ToString(),
4643
description = kvp.Value.Description,
4744
data = kvp.Value.Data
48-
})
45+
}),
46+
describe_entities = JsonDocument.Parse(json)
4947
};
5048

5149
context.Response.ContentType = "application/json";
52-
return context.Response.WriteAsync(JsonSerializer.Serialize(response, _jsonOptions));
50+
await context.Response.WriteAsync(JsonSerializer.Serialize(response, _jsonOptions));
5351
}
5452
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using System.ComponentModel;
5+
using ModelContextProtocol.Server;
6+
7+
namespace Azure.DataApiBuilder.Mcp.Tools;
8+
9+
public static partial class Dml
10+
{
11+
[McpServerTool, Description("Do not use this as it is not functional.")]
12+
public static Task<string> CreateEntityRecordAsync() => throw new NotImplementedException();
13+
}

0 commit comments

Comments
 (0)