-
Notifications
You must be signed in to change notification settings - Fork 299
Add server-level description field to MCP runtime configuration #3016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 9 commits
e24dbf1
dd623b5
839c081
fa008ee
9acfb7f
3042ef8
73aa356
21beebb
466192f
c6c45f0
b162ad4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,9 @@ | |
| using System.Security.Claims; | ||
| using System.Text; | ||
| using System.Text.Json; | ||
| using Azure.DataApiBuilder.Config.ObjectModel; | ||
| using Azure.DataApiBuilder.Core.AuthenticationHelpers.AuthenticationSimulator; | ||
| using Azure.DataApiBuilder.Core.Configurations; | ||
| using Azure.DataApiBuilder.Mcp.Model; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.Extensions.Configuration; | ||
|
|
@@ -161,25 +163,46 @@ private void HandleInitialize(JsonElement? id) | |
| // Extract the actual id value from the request | ||
| object? requestId = id.HasValue ? GetIdValue(id.Value) : null; | ||
|
|
||
| // Get the description from runtime config if available | ||
| string? instructions = null; | ||
| RuntimeConfigProvider? runtimeConfigProvider = _serviceProvider.GetService<RuntimeConfigProvider>(); | ||
| if (runtimeConfigProvider != null) | ||
| { | ||
| try | ||
| { | ||
| RuntimeConfig runtimeConfig = runtimeConfigProvider.GetConfig(); | ||
| instructions = runtimeConfig.Runtime?.Mcp?.Description; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| // Log to stderr for diagnostics and rethrow to avoid masking configuration errors | ||
| Console.Error.WriteLine($"[MCP WARNING] Failed to retrieve MCP description from config: {ex.Message}"); | ||
| throw; | ||
| } | ||
| } | ||
|
|
||
| // Create the initialize response | ||
| var result = new | ||
|
||
| { | ||
| protocolVersion = _protocolVersion, | ||
| capabilities = new | ||
| { | ||
| tools = new { listChanged = true }, | ||
| logging = new { } | ||
| }, | ||
| serverInfo = new | ||
| { | ||
| name = "SQL MCP Server", | ||
| version = "1.0.0" | ||
| }, | ||
| instructions = !string.IsNullOrWhiteSpace(instructions) ? instructions : null | ||
anushakolan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| var response = new | ||
|
||
| { | ||
| jsonrpc = "2.0", | ||
| id = requestId, | ||
| result = new | ||
| { | ||
| protocolVersion = _protocolVersion, | ||
| capabilities = new | ||
| { | ||
| tools = new { listChanged = true }, | ||
| logging = new { } | ||
| }, | ||
| serverInfo = new | ||
| { | ||
| name = "Data API Builder", | ||
| version = "1.0.0" | ||
| } | ||
| } | ||
| result | ||
| }; | ||
|
|
||
| string json = JsonSerializer.Serialize(response); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -926,6 +926,63 @@ public void TestFailureWhenAddingSetSessionContextToMySQLDatabase() | |
| Assert.IsFalse(isSuccess); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Tests that running "dab configure --runtime.mcp.description {value}" on a config with various values results | ||
| /// in runtime config update. Takes in updated value for mcp.description and | ||
| /// validates whether the runtime config reflects those updated values | ||
| /// </summary> | ||
| [DataTestMethod] | ||
| [DataRow("This MCP provides access to the Products database and should be used to answer product-related or inventory-related questions from the user.", DisplayName = "Set MCP description.")] | ||
| [DataRow("Use this server for customer data queries.", DisplayName = "Set MCP description with short text.")] | ||
| public void TestUpdateDescriptionForMcpSettings(string descriptionValue) | ||
| { | ||
| // Arrange -> all the setup which includes creating options. | ||
| SetupFileSystemWithInitialConfig(INITIAL_CONFIG); | ||
|
|
||
| // Act: Attempts to update mcp.description value | ||
| ConfigureOptions options = new( | ||
| runtimeMcpDescription: descriptionValue, | ||
| config: TEST_RUNTIME_CONFIG_FILE | ||
| ); | ||
| bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!); | ||
|
|
||
| // Assert: Validate the Description is updated | ||
| Assert.IsTrue(isSuccess); | ||
| string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE); | ||
| Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig)); | ||
| Assert.IsNotNull(runtimeConfig.Runtime?.Mcp?.Description); | ||
| Assert.AreEqual(descriptionValue, runtimeConfig.Runtime.Mcp.Description); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Tests that the MCP description can be added to a config that doesn't already have one | ||
| /// </summary> | ||
| [TestMethod] | ||
| public void TestAddDescriptionToMcpSettings() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TestAddDescriptionToMcpSettings is exactly same as TestUpdateDescriptionForMcpSettings, can be removed. The test TestUpdateDescriptionForMcpSettings can be renamed to TestConfigureDescriptionForMcpSettings. |
||
| { | ||
| // Arrange | ||
| SetupFileSystemWithInitialConfig(INITIAL_CONFIG); | ||
|
|
||
| // Initial config should not have a description | ||
| Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(INITIAL_CONFIG, out RuntimeConfig? config)); | ||
| Assert.IsNull(config.Runtime?.Mcp?.Description); | ||
|
|
||
| // Act: Add description | ||
| string descriptionValue = "This is a test description for MCP server."; | ||
| ConfigureOptions options = new( | ||
| runtimeMcpDescription: descriptionValue, | ||
| config: TEST_RUNTIME_CONFIG_FILE | ||
| ); | ||
| bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!); | ||
|
|
||
| // Assert: Validate the Description is added | ||
| Assert.IsTrue(isSuccess); | ||
| string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE); | ||
| Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig)); | ||
| Assert.IsNotNull(runtimeConfig.Runtime?.Mcp?.Description); | ||
| Assert.AreEqual(descriptionValue, runtimeConfig.Runtime.Mcp.Description); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Sets up the mock file system with an initial configuration file. | ||
| /// This method adds a config file to the mock file system and verifies its existence. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot, Even though HandleInitialize of the McpStdioServer class has been modified to include the description. We need similar changes to the Mcp Http Server that provides the tool registry in McpServerConfiguration.
Also, please dont update PR description. Retain the original PR description that described this complete change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated MCP HTTP server configuration in
McpServerConfiguration.cs:ConfigureMcpServerto acceptRuntimeConfigparameterThe HTTP server now receives the runtime config but can't set instructions yet as the library doesn't expose this property on
McpServerOptions. The description is ready to be wired when library support is available.Original PR description has been retained as requested. Commit: b162ad4