Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Core/Services/OpenAPI/OpenApiDocumentor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ private OpenApiDocument BuildOpenApiDocument(RuntimeConfig runtimeConfig, string
Info = new OpenApiInfo
{
Version = ProductInfo.GetProductVersion(),
Title = title
Title = title,
Description = runtimeConfig.Runtime?.Mcp?.Description
},
Servers = new List<OpenApiServer>
{
Expand Down
30 changes: 26 additions & 4 deletions src/Service.Tests/UnitTests/OpenApiDocumentorUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ public void CreateDocument_TableEntity_GeneratesExpectedPathsAndSchemas()
Assert.IsTrue(schemas.TryGetProperty("Book_NoPK", out _));
}

[TestMethod]
public void CreateDocument_McpDescription_PopulatesInfoDescription()
{
const string description = "This server provides access to the company database.";
OpenApiDocumentor documentor = CreateDocumentor(
new Dictionary<string, Entity> { [ENTITY_NAME] = CreateTableEntity(restEnabled: true) },
CreateBookMetadata(),
mcpDescription: description);

documentor.CreateDocument();

Assert.IsTrue(documentor.TryGetDocument(out string? document));
using JsonDocument doc = JsonDocument.Parse(document!);
Assert.AreEqual(description, doc.RootElement.GetProperty("info").GetProperty("description").GetString());
}

[TestMethod]
public void CreateDocument_CalledTwiceWithoutOverride_Throws()
{
Expand Down Expand Up @@ -451,7 +467,8 @@ private static OpenApiDocumentor CreateDocumentor(
IEnumerable<string>? columnNames = null,
bool restEnabledGlobally = true,
bool requestBodyStrict = true,
string? baseRoute = null)
string? baseRoute = null,
string? mcpDescription = null)
{
Mock<ISqlMetadataProvider> mockMetadataProvider = new();
mockMetadataProvider.Setup(x => x.EntityToDatabaseObject).Returns(dbObjects);
Expand Down Expand Up @@ -480,7 +497,7 @@ private static OpenApiDocumentor CreateDocumentor(
Mock<IMetadataProviderFactory> mockFactory = new();
mockFactory.Setup(x => x.GetMetadataProvider(It.IsAny<string>())).Returns(mockMetadataProvider.Object);

RuntimeConfig config = CreateConfig(entities, restEnabledGlobally, requestBodyStrict, baseRoute);
RuntimeConfig config = CreateConfig(entities, restEnabledGlobally, requestBodyStrict, baseRoute, mcpDescription);
RuntimeConfigProvider configProvider = TestHelper.GenerateInMemoryRuntimeConfigProvider(config);

return new OpenApiDocumentor(
Expand All @@ -490,15 +507,20 @@ private static OpenApiDocumentor CreateDocumentor(
logger: NullLogger<OpenApiDocumentor>.Instance);
}

private static RuntimeConfig CreateConfig(Dictionary<string, Entity> entities, bool restEnabledGlobally, bool requestBodyStrict = true, string? baseRoute = null)
private static RuntimeConfig CreateConfig(
Dictionary<string, Entity> entities,
bool restEnabledGlobally,
bool requestBodyStrict = true,
string? baseRoute = null,
string? mcpDescription = null)
{
return new RuntimeConfig(
Schema: "test-schema",
DataSource: new DataSource(DatabaseType: DatabaseType.MSSQL, ConnectionString: string.Empty, Options: null),
Runtime: new(
Rest: new(Enabled: restEnabledGlobally, RequestBodyStrict: requestBodyStrict),
GraphQL: new(),
Mcp: null,
Mcp: mcpDescription is null ? null : new(Description: mcpDescription),
Host: new(Cors: null, Authentication: null, Mode: HostMode.Development),
BaseRoute: baseRoute),
Entities: new(entities));
Expand Down