-
Notifications
You must be signed in to change notification settings - Fork 285
Fix missing MCP test #2925
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?
Fix missing MCP test #2925
Changes from 2 commits
52b53ef
de28682
80e6b2e
8fae2b8
ccab7f1
edd0943
5db169f
adc89d2
39647da
676d70c
98a18af
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 |
|---|---|---|
|
|
@@ -2528,26 +2528,37 @@ public async Task TestRuntimeBaseRouteInNextLinkForPaginatedRestResponse() | |
| /// <param name="expectedStatusCodeForGraphQL">Expected HTTP status code code for the GraphQL request</param> | ||
| [DataTestMethod] | ||
| [TestCategory(TestCategory.MSSQL)] | ||
| [DataRow(true, true, HttpStatusCode.OK, HttpStatusCode.OK, CONFIGURATION_ENDPOINT, DisplayName = "V1 - Both Rest and GraphQL endpoints enabled globally")] | ||
| [DataRow(true, false, HttpStatusCode.OK, HttpStatusCode.NotFound, CONFIGURATION_ENDPOINT, DisplayName = "V1 - Rest enabled and GraphQL endpoints disabled globally")] | ||
| [DataRow(false, true, HttpStatusCode.NotFound, HttpStatusCode.OK, CONFIGURATION_ENDPOINT, DisplayName = "V1 - Rest disabled and GraphQL endpoints enabled globally")] | ||
| [DataRow(true, true, HttpStatusCode.OK, HttpStatusCode.OK, CONFIGURATION_ENDPOINT_V2, DisplayName = "V2 - Both Rest and GraphQL endpoints enabled globally")] | ||
| [DataRow(true, false, HttpStatusCode.OK, HttpStatusCode.NotFound, CONFIGURATION_ENDPOINT_V2, DisplayName = "V2 - Rest enabled and GraphQL endpoints disabled globally")] | ||
| [DataRow(false, true, HttpStatusCode.NotFound, HttpStatusCode.OK, CONFIGURATION_ENDPOINT_V2, DisplayName = "V2 - Rest disabled and GraphQL endpoints enabled globally")] | ||
| public async Task TestGlobalFlagToEnableRestAndGraphQLForHostedAndNonHostedEnvironment( | ||
| [DataRow(true, true, true, HttpStatusCode.OK, HttpStatusCode.OK, HttpStatusCode.OK, CONFIGURATION_ENDPOINT, DisplayName = "V1 - Rest, GraphQL, and MCP enabled globally")] | ||
| [DataRow(true, true, false, HttpStatusCode.OK, HttpStatusCode.OK, HttpStatusCode.NotFound, CONFIGURATION_ENDPOINT, DisplayName = "V1 - Rest and GraphQL enabled, MCP disabled globally")] | ||
| [DataRow(true, false, true, HttpStatusCode.OK, HttpStatusCode.NotFound, HttpStatusCode.OK, CONFIGURATION_ENDPOINT, DisplayName = "V1 - Rest enabled, GraphQL disabled, and MCP enabled globally")] | ||
| [DataRow(true, false, false, HttpStatusCode.OK, HttpStatusCode.NotFound, HttpStatusCode.NotFound, CONFIGURATION_ENDPOINT, DisplayName = "V1 - Rest enabled, GraphQL and MCP enabled globally")] | ||
| [DataRow(false, true, true, HttpStatusCode.NotFound, HttpStatusCode.OK, HttpStatusCode.OK, CONFIGURATION_ENDPOINT, DisplayName = "V1 - Rest disabled, GraphQL and MCP enabled globally")] | ||
| [DataRow(false, true, false, HttpStatusCode.NotFound, HttpStatusCode.OK, HttpStatusCode.NotFound, CONFIGURATION_ENDPOINT, DisplayName = "V1 - Rest disabled, GraphQL enabled, and MCP disabled globally")] | ||
| [DataRow(false, false, true, HttpStatusCode.NotFound, HttpStatusCode.NotFound, HttpStatusCode.OK, CONFIGURATION_ENDPOINT, DisplayName = "V1 - Rest and GraphQL disabled, MCP enabled globally")] | ||
| [DataRow(true, true, true, HttpStatusCode.OK, HttpStatusCode.OK, HttpStatusCode.OK, CONFIGURATION_ENDPOINT_V2, DisplayName = "V2 - Rest, GraphQL, and MCP enabled globally")] | ||
| [DataRow(true, true, false, HttpStatusCode.OK, HttpStatusCode.OK, HttpStatusCode.NotFound, CONFIGURATION_ENDPOINT_V2, DisplayName = "V2 - Rest and GraphQL enabled, MCP disabled globally")] | ||
| [DataRow(true, false, true, HttpStatusCode.OK, HttpStatusCode.NotFound, HttpStatusCode.OK, CONFIGURATION_ENDPOINT_V2, DisplayName = "V2 - Rest enabled, GraphQL disabled, and MCP enabled globally")] | ||
| [DataRow(true, false, false, HttpStatusCode.OK, HttpStatusCode.NotFound, HttpStatusCode.NotFound, CONFIGURATION_ENDPOINT_V2, DisplayName = "V2 - Rest enabled, GraphQL and MCP enabled globally")] | ||
RubenCerna2079 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| [DataRow(false, true, true, HttpStatusCode.NotFound, HttpStatusCode.OK, HttpStatusCode.OK, CONFIGURATION_ENDPOINT_V2, DisplayName = "V2 - Rest disabled, GraphQL and MCP enabled globally")] | ||
| [DataRow(false, true, false, HttpStatusCode.NotFound, HttpStatusCode.OK, HttpStatusCode.NotFound, CONFIGURATION_ENDPOINT_V2, DisplayName = "V2 - Rest disabled, GraphQL enabled, and MCP disabled globally")] | ||
| [DataRow(false, false, true, HttpStatusCode.NotFound, HttpStatusCode.NotFound, HttpStatusCode.OK, CONFIGURATION_ENDPOINT_V2, DisplayName = "V2 - Rest and GraphQL disabled, MCP enabled globally")] | ||
| public async Task TestGlobalFlagToEnableRestGraphQLAndMcpForHostedAndNonHostedEnvironment( | ||
| bool isRestEnabled, | ||
| bool isGraphQLEnabled, | ||
| bool isMcpEnabled, | ||
| HttpStatusCode expectedStatusCodeForREST, | ||
| HttpStatusCode expectedStatusCodeForGraphQL, | ||
| HttpStatusCode expectedStatusCodeForMcp, | ||
| string configurationEndpoint) | ||
| { | ||
| GraphQLRuntimeOptions graphqlOptions = new(Enabled: isGraphQLEnabled); | ||
| RestRuntimeOptions restRuntimeOptions = new(Enabled: isRestEnabled); | ||
| McpRuntimeOptions mcpRuntimeOptions = new(Enabled: isMcpEnabled); | ||
|
|
||
| DataSource dataSource = new(DatabaseType.MSSQL, | ||
| GetConnectionStringFromEnvironmentConfig(environment: TestCategory.MSSQL), Options: null); | ||
|
|
||
| RuntimeConfig configuration = InitMinimalRuntimeConfig(dataSource, graphqlOptions, restRuntimeOptions, null); | ||
| RuntimeConfig configuration = InitMinimalRuntimeConfig(dataSource, graphqlOptions, restRuntimeOptions, mcpRuntimeOptions); | ||
| const string CUSTOM_CONFIG = "custom-config.json"; | ||
| File.WriteAllText(CUSTOM_CONFIG, configuration.ToJson()); | ||
|
|
||
|
|
@@ -2570,6 +2581,7 @@ public async Task TestGlobalFlagToEnableRestAndGraphQLForHostedAndNonHostedEnvir | |
|
|
||
| object payload = new { query }; | ||
|
|
||
| // GraphQL request | ||
| HttpRequestMessage graphQLRequest = new(HttpMethod.Post, "/graphql") | ||
| { | ||
| Content = JsonContent.Create(payload) | ||
|
|
@@ -2578,9 +2590,25 @@ public async Task TestGlobalFlagToEnableRestAndGraphQLForHostedAndNonHostedEnvir | |
| HttpResponseMessage graphQLResponse = await client.SendAsync(graphQLRequest); | ||
| Assert.AreEqual(expectedStatusCodeForGraphQL, graphQLResponse.StatusCode); | ||
|
|
||
| // REST request | ||
| HttpRequestMessage restRequest = new(HttpMethod.Get, "/api/Book"); | ||
| HttpResponseMessage restResponse = await client.SendAsync(restRequest); | ||
| Assert.AreEqual(expectedStatusCodeForREST, restResponse.StatusCode); | ||
|
|
||
| // MCP request | ||
| await Task.Delay(2000); | ||
| object mcpPayload = new | ||
| { | ||
| jsonrpc = "2.0", | ||
| id = 1, | ||
| method = "tools/call" | ||
| }; | ||
| HttpRequestMessage mcpRequest = new(HttpMethod.Post, "/mcp") | ||
RubenCerna2079 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| Content = JsonContent.Create(mcpPayload) | ||
| }; | ||
| HttpResponseMessage mcpResponse = await client.SendAsync(mcpRequest); | ||
RubenCerna2079 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
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. why cant we use the same |
||
| Assert.AreEqual(expectedStatusCodeForMcp, mcpResponse.StatusCode); | ||
RubenCerna2079 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // Hosted Scenario | ||
|
|
@@ -2590,8 +2618,7 @@ public async Task TestGlobalFlagToEnableRestAndGraphQLForHostedAndNonHostedEnvir | |
| { | ||
| JsonContent content = GetPostStartupConfigParams(MSSQL_ENVIRONMENT, configuration, configurationEndpoint); | ||
|
|
||
| HttpResponseMessage postResult = | ||
| await client.PostAsync(configurationEndpoint, content); | ||
| HttpResponseMessage postResult = await client.PostAsync(configurationEndpoint, content); | ||
| Assert.AreEqual(HttpStatusCode.OK, postResult.StatusCode); | ||
|
|
||
| HttpStatusCode restResponseCode = await GetRestResponsePostConfigHydration(client); | ||
|
|
@@ -2602,6 +2629,8 @@ public async Task TestGlobalFlagToEnableRestAndGraphQLForHostedAndNonHostedEnvir | |
|
|
||
| Assert.AreEqual(expected: expectedStatusCodeForGraphQL, actual: graphqlResponseCode); | ||
|
|
||
| HttpStatusCode mcpResponseCode = await GetMcpResponsePostConfigHydration(client); | ||
| Assert.AreEqual(expected: expectedStatusCodeForMcp, actual: mcpResponseCode); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -5330,6 +5359,49 @@ private static async Task<HttpStatusCode> GetGraphQLResponsePostConfigHydration( | |
| return responseCode; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Executing MCP POST requests against the engine until a non-503 error is received. | ||
| /// </summary> | ||
| /// <param name="httpClient">Client used for request execution.</param> | ||
| /// <returns>ServiceUnavailable if service is not successfully hydrated with config, | ||
| /// else the response code from the MCP request</returns> | ||
| private static async Task<HttpStatusCode> GetMcpResponsePostConfigHydration(HttpClient httpClient) | ||
| { | ||
| // Retry request RETRY_COUNT times in 1 second increments to allow required services | ||
| // time to instantiate and hydrate permissions. | ||
| int retryCount = RETRY_COUNT; | ||
| HttpStatusCode responseCode = HttpStatusCode.ServiceUnavailable; | ||
| while (retryCount > 0) | ||
| { | ||
| // Minimal MCP request (list tools) – valid JSON-RPC request | ||
| object payload = new | ||
| { | ||
| jsonrpc = "2.0", | ||
| id = 1, | ||
| method = "tools/call" | ||
| }; | ||
|
|
||
| HttpRequestMessage mcpRequest = new(HttpMethod.Post, "/mcp") | ||
| { | ||
| Content = JsonContent.Create(payload) | ||
| }; | ||
|
|
||
| HttpResponseMessage mcpResponse = await httpClient.SendAsync(mcpRequest); | ||
| responseCode = mcpResponse.StatusCode; | ||
|
|
||
| if (responseCode == HttpStatusCode.ServiceUnavailable) | ||
| { | ||
| retryCount--; | ||
| Thread.Sleep(TimeSpan.FromSeconds(RETRY_WAIT_SECONDS)); | ||
| continue; | ||
|
Comment on lines
+5395
to
+5396
Contributor
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. The function is asynchronous but using |
||
| } | ||
|
|
||
| break; | ||
| } | ||
|
|
||
| return responseCode; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Helper method to instantiate RuntimeConfig object needed for multiple create tests. | ||
| /// </summary> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.