Skip to content

Commit 76b4d4f

Browse files
Upgrade MCP Packages to Stable Version (#3177)
## Why make this change? - We were using the preview versions for the MCP packages, we need to upgrade to the latest stable version in order to be able to publish the new stable release for 1.7 ## What is this change? We update the MCP packages to version `1.0.0`, we also needed to update other sections of our MCP in order to comply with the new version. - Get rid of the `Type` in the `TextBlock` method, as it is now a `ReadOnly` type. - Move the `ListToolsHandler` and `CallToolHandler` outside of the `Capabilities` property as it no longer supports them, now it only supports `ListChanged` which sends notifications if any tools are added or deleted. ## How was this tested? This is only a refactoring, so it only needs to pass the current tests.
1 parent 8eeceb3 commit 76b4d4f

3 files changed

Lines changed: 57 additions & 59 deletions

File tree

src/Azure.DataApiBuilder.Mcp/Core/McpServerConfiguration.cs

Lines changed: 53 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -22,71 +22,69 @@ internal static IServiceCollection ConfigureMcpServer(this IServiceCollection se
2222
services.AddMcpServer(options =>
2323
{
2424
options.ServerInfo = new() { Name = McpProtocolDefaults.MCP_SERVER_NAME, Version = McpProtocolDefaults.MCP_SERVER_VERSION };
25-
options.Capabilities = new()
25+
})
26+
.WithHttpTransport()
27+
.WithListToolsHandler(
28+
(request, ct) =>
2629
{
27-
Tools = new()
30+
McpToolRegistry? toolRegistry = request.Services?.GetRequiredService<McpToolRegistry>();
31+
if (toolRegistry == null)
2832
{
29-
ListToolsHandler = (request, ct) =>
30-
{
31-
McpToolRegistry? toolRegistry = request.Services?.GetRequiredService<McpToolRegistry>();
32-
if (toolRegistry == null)
33-
{
34-
throw new InvalidOperationException("Tool registry is not available.");
35-
}
33+
throw new InvalidOperationException("Tool registry is not available.");
34+
}
3635

37-
List<Tool> tools = toolRegistry.GetAllTools().ToList();
36+
List<Tool> tools = toolRegistry.GetAllTools().ToList();
3837

39-
return ValueTask.FromResult(new ListToolsResult
40-
{
41-
Tools = tools
42-
});
43-
},
44-
CallToolHandler = async (request, ct) =>
45-
{
46-
McpToolRegistry? toolRegistry = request.Services?.GetRequiredService<McpToolRegistry>();
47-
if (toolRegistry == null)
48-
{
49-
throw new InvalidOperationException("Tool registry is not available.");
50-
}
38+
return ValueTask.FromResult(new ListToolsResult
39+
{
40+
Tools = tools
41+
});
42+
}
43+
)
44+
.WithCallToolHandler(
45+
async (request, ct) =>
46+
{
47+
McpToolRegistry? toolRegistry = request.Services?.GetRequiredService<McpToolRegistry>();
48+
if (toolRegistry == null)
49+
{
50+
throw new InvalidOperationException("Tool registry is not available.");
51+
}
5152

52-
string? toolName = request.Params?.Name;
53-
if (string.IsNullOrEmpty(toolName))
54-
{
55-
throw new McpException("Tool name is required.");
56-
}
53+
string? toolName = request.Params?.Name;
54+
if (string.IsNullOrEmpty(toolName))
55+
{
56+
throw new McpException("Tool name is required.");
57+
}
5758

58-
if (!toolRegistry.TryGetTool(toolName, out IMcpTool? tool))
59-
{
60-
throw new McpException($"Unknown tool: '{toolName}'");
61-
}
59+
if (!toolRegistry.TryGetTool(toolName, out IMcpTool? tool))
60+
{
61+
throw new McpException($"Unknown tool: '{toolName}'");
62+
}
6263

63-
JsonDocument? arguments = null;
64-
if (request.Params?.Arguments != null)
65-
{
66-
// Convert IReadOnlyDictionary<string, JsonElement> to JsonDocument
67-
Dictionary<string, object?> jsonObject = new();
68-
foreach (KeyValuePair<string, JsonElement> kvp in request.Params.Arguments)
69-
{
70-
jsonObject[kvp.Key] = kvp.Value;
71-
}
64+
JsonDocument? arguments = null;
65+
if (request.Params?.Arguments != null)
66+
{
67+
// Convert IReadOnlyDictionary<string, JsonElement> to JsonDocument
68+
Dictionary<string, object?> jsonObject = new();
69+
foreach (KeyValuePair<string, JsonElement> kvp in request.Params.Arguments)
70+
{
71+
jsonObject[kvp.Key] = kvp.Value;
72+
}
7273

73-
string json = JsonSerializer.Serialize(jsonObject);
74-
arguments = JsonDocument.Parse(json);
75-
}
74+
string json = JsonSerializer.Serialize(jsonObject);
75+
arguments = JsonDocument.Parse(json);
76+
}
7677

77-
try
78-
{
79-
return await tool!.ExecuteAsync(arguments, request.Services!, ct);
80-
}
81-
finally
82-
{
83-
arguments?.Dispose();
84-
}
85-
}
78+
try
79+
{
80+
return await tool!.ExecuteAsync(arguments, request.Services!, ct);
8681
}
87-
};
88-
})
89-
.WithHttpTransport();
82+
finally
83+
{
84+
arguments?.Dispose();
85+
}
86+
}
87+
);
9088

9189
return services;
9290
}

src/Azure.DataApiBuilder.Mcp/Utils/McpResponseBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static CallToolResult BuildSuccessResult(
3434
{
3535
Content = new List<ContentBlock>
3636
{
37-
new TextContentBlock { Type = "text", Text = output }
37+
new TextContentBlock { Text = output }
3838
}
3939
};
4040
}
@@ -67,7 +67,7 @@ public static CallToolResult BuildErrorResult(
6767
{
6868
Content = new List<ContentBlock>
6969
{
70-
new TextContentBlock { Type = "text", Text = output }
70+
new TextContentBlock { Text = output }
7171
},
7272
IsError = true
7373
};

src/Directory.Packages.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.10" />
3030
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="8.0.10" />
3131
<PackageVersion Include="Microsoft.Azure.Cosmos" Version="3.38.1" />
32-
<PackageVersion Include="ModelContextProtocol" Version="0.3.0-preview.4" />
33-
<PackageVersion Include="ModelContextProtocol.AspNetCore" Version="0.3.0-preview.4" />
32+
<PackageVersion Include="ModelContextProtocol" Version="1.0.0" />
33+
<PackageVersion Include="ModelContextProtocol.AspNetCore" Version="1.0.0" />
3434
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />
3535
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0" />
3636
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" />

0 commit comments

Comments
 (0)