Skip to content

Commit 0f94c49

Browse files
committed
Tool Routing
1 parent 11fb085 commit 0f94c49

40 files changed

+1523
-155
lines changed

.github/workflows/image.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,8 @@ jobs:
3434
- name: Restore dependencies
3535
run: dotnet restore dotnet/Microsoft.McpGateway.sln --runtime linux-x64
3636

37-
- name: Publish and push the container image
38-
run: dotnet publish dotnet/Microsoft.McpGateway.Service/src/Microsoft.McpGateway.Service.csproj --configuration Release --no-restore /p:PublishProfile=github.pubxml /p:ContainerRepository=${{ github.repository }}
37+
- name: Publish and push the mcp-gateway container image
38+
run: dotnet publish dotnet/Microsoft.McpGateway.Service/src/Microsoft.McpGateway.Service.csproj --configuration Release --no-restore /p:PublishProfile=github.pubxml /p:ContainerRepository=${{ github.repository_owner }}/mcp-gateway
39+
40+
- name: Publish and push the tool-gateway container image
41+
run: dotnet publish dotnet/Microsoft.McpGateway.Tools/src/Microsoft.McpGateway.Tools.csproj --configuration Release --no-restore /p:PublishProfile=github.pubxml /p:ContainerRepository=${{ github.repository_owner }}/tool-gateway

deployment/infra/azure-deployment.bicep

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,20 @@ resource cacheContainer 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/cont
399399
}
400400
}
401401

402+
resource toolContainer 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2023-04-15' = {
403+
name: 'ToolContainer'
404+
parent: cosmosDbSqlDb
405+
properties: {
406+
resource: {
407+
id: 'ToolContainer'
408+
partitionKey: {
409+
paths: ['/id']
410+
kind: 'Hash'
411+
}
412+
}
413+
}
414+
}
415+
402416
// Cosmos DB Data Contributor Role Assignment to UAI
403417
resource cosmosDbRoleAssignment 'Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignments@2022-11-15' = {
404418
parent: cosmosDb

deployment/k8s/cloud-deployment-template.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,49 @@ data:
118118
ContainerRegistrySettings__Endpoint: "mgreg${IDENTIFIER}.azurecr.io"
119119

120120
PublicOrigin: "http://${IDENTIFIER}.${REGION}.cloudapp.azure.com/"
121+
---
122+
apiVersion: apps/v1
123+
kind: StatefulSet
124+
metadata:
125+
name: toolgateway
126+
namespace: adapter
127+
spec:
128+
serviceName: toolgateway-service
129+
replicas: 1
130+
selector:
131+
matchLabels:
132+
app: toolgateway
133+
template:
134+
metadata:
135+
labels:
136+
app: toolgateway
137+
azure.workload.identity/use: "true"
138+
adapter/type: "mcp"
139+
spec:
140+
serviceAccountName: mcpgateway-sa
141+
containers:
142+
- name: toolgateway-container
143+
image: ghcr.io/microsoft/tool-gateway:latest
144+
ports:
145+
- containerPort: 8000
146+
env:
147+
- name: ASPNETCORE_ENVIRONMENT
148+
value: "Production"
149+
envFrom:
150+
- configMapRef:
151+
name: app-config
152+
---
153+
apiVersion: v1
154+
kind: Service
155+
metadata:
156+
name: toolgateway-service
157+
namespace: adapter
158+
spec:
159+
clusterIP: "None"
160+
selector:
161+
app: toolgateway
162+
ports:
163+
- protocol: TCP
164+
port: 8000
165+
targetPort: 8000
166+
---

dotnet/Directory.Packages.props

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
44
</PropertyGroup>
55
<ItemGroup>
6+
<PackageVersion Include="Azure.Identity" Version="1.17.0" />
67
<PackageVersion Include="FluentAssertions" Version="8.2.0" />
7-
<PackageVersion Include="KubernetesClient" Version="16.0.7" />
8+
<PackageVersion Include="KubernetesClient" Version="18.0.5" />
89
<PackageVersion Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.23.0" />
910
<PackageVersion Include="Microsoft.Azure.Cosmos" Version="3.51.0" />
1011
<PackageVersion Include="Microsoft.Extensions.Caching.Cosmos" Version="1.7.0" />
@@ -14,6 +15,7 @@
1415
<PackageVersion Include="Moq" Version="4.20.72" />
1516
<PackageVersion Include="MSTest" Version="3.6.4" />
1617
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
17-
<PackageVersion Include="ModelContextProtocol.AspNetCore" Version="0.3.0-preview.2" />
18+
<PackageVersion Include="ModelContextProtocol" Version="0.4.0-preview.3" />
19+
<PackageVersion Include="ModelContextProtocol.AspNetCore" Version="0.4.0-preview.3" />
1820
</ItemGroup>
19-
</Project>
21+
</Project>

dotnet/Microsoft.McpGateway.Management/src/Contracts/AdapterData.cs

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Microsoft.McpGateway.Management.Contracts
88
{
99
/// <summary>
10-
/// This class represents the data for an adapter, including its name, image details, protocol, connection type, environment variables, and description.
10+
/// This class represents the data for an adapter, including its name, image details, environment variables, and description.
1111
/// </summary>
1212
public class AdapterData
1313
{
@@ -30,18 +30,6 @@ public class AdapterData
3030
[JsonPropertyOrder(3)]
3131
public required string ImageVersion { get; set; }
3232

33-
/// <summary>
34-
/// The protocol used by the adapter. Default is MCP.
35-
/// </summary>
36-
[JsonPropertyOrder(6)]
37-
public ServerProtocol Protocol { get; set; } = ServerProtocol.MCP;
38-
39-
/// <summary>
40-
/// The connection type used by the adapter. Default is SSE.
41-
/// </summary>
42-
[JsonPropertyOrder(7)]
43-
public ConnectionType ConnectionType { get; set; } = ConnectionType.StreamableHttp;
44-
4533
/// <summary>
4634
/// Environment key variables in M3 service for the adapter.
4735
/// </summary>
@@ -57,13 +45,13 @@ public class AdapterData
5745
/// <summary>
5846
/// A description of the adapter.
5947
/// </summary>
60-
[JsonPropertyOrder(8)]
48+
[JsonPropertyOrder(6)]
6149
public string Description { get; set; } = string.Empty;
6250

6351
/// <summary>
6452
/// Indicates whether to use workload identity for the deployed adapter instance. Default is false.
6553
/// </summary>
66-
[JsonPropertyOrder(9)]
54+
[JsonPropertyOrder(7)]
6755
public bool UseWorkloadIdentity { get; set; } = false;
6856

6957
public AdapterData(
@@ -73,8 +61,6 @@ public AdapterData(
7361
Dictionary<string, string>? environmentVariables = null,
7462
int? replicaCount = 1,
7563
string description = "",
76-
ServerProtocol protocol = ServerProtocol.MCP,
77-
ConnectionType connectionType = ConnectionType.StreamableHttp,
7864
bool useWorkloadIdentity = false)
7965
{
8066
ArgumentException.ThrowIfNullOrEmpty(name);
@@ -84,8 +70,6 @@ public AdapterData(
8470
Name = name;
8571
ImageName = imageName;
8672
ImageVersion = imageVersion;
87-
Protocol = protocol;
88-
ConnectionType = connectionType;
8973
EnvironmentVariables = environmentVariables ?? [];
9074
ReplicaCount = replicaCount ?? 1;
9175
Description = description;
@@ -94,17 +78,4 @@ public AdapterData(
9478

9579
public AdapterData() { }
9680
}
97-
98-
[JsonConverter(typeof(JsonStringEnumConverter))]
99-
public enum ConnectionType
100-
{
101-
SSE,
102-
StreamableHttp,
103-
}
104-
105-
[JsonConverter(typeof(JsonStringEnumConverter))]
106-
public enum ServerProtocol
107-
{
108-
MCP
109-
}
11081
}

dotnet/Microsoft.McpGateway.Management/src/Contracts/AdapterResource.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class AdapterResource : AdapterData
3030
public DateTimeOffset LastUpdatedAt { get; set; }
3131

3232
public AdapterResource(AdapterData adapterData, string createdBy, DateTimeOffset createdAt, DateTimeOffset lastUpdatedAt)
33-
: base(adapterData.Name, adapterData.ImageName, adapterData.ImageVersion, adapterData.EnvironmentVariables, adapterData.ReplicaCount, adapterData.Description, adapterData.Protocol, adapterData.ConnectionType, adapterData.UseWorkloadIdentity)
33+
: base(adapterData.Name, adapterData.ImageName, adapterData.ImageVersion, adapterData.EnvironmentVariables, adapterData.ReplicaCount, adapterData.Description, adapterData.UseWorkloadIdentity)
3434
{
3535
CreatedBy = createdBy;
3636
CreatedAt = createdAt;
@@ -47,8 +47,6 @@ public static AdapterResource Create(AdapterData data, string createdBy, DateTim
4747
EnvironmentVariables = data.EnvironmentVariables,
4848
ReplicaCount = data.ReplicaCount,
4949
Description = data.Description,
50-
Protocol = data.Protocol,
51-
ConnectionType = data.ConnectionType,
5250
CreatedBy = createdBy,
5351
CreatedAt = createdAt,
5452
LastUpdatedAt = DateTime.UtcNow,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
namespace Microsoft.McpGateway.Management.Contracts
5+
{
6+
/// <summary>
7+
/// Defines the type of MCP resource being deployed.
8+
/// </summary>
9+
public enum ResourceType
10+
{
11+
/// <summary>
12+
/// Represents an adapter resource.
13+
/// </summary>
14+
Adapter,
15+
16+
/// <summary>
17+
/// Represents a tool resource.
18+
/// </summary>
19+
Tool
20+
}
21+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using System.Text.Json.Serialization;
5+
6+
namespace Microsoft.McpGateway.Management.Contracts
7+
{
8+
/// <summary>
9+
/// Represents the data for a tool deployment, including image details and the tool definition.
10+
/// </summary>
11+
public class ToolData : AdapterData
12+
{
13+
/// <summary>
14+
/// The MCP tool definition as JSON.
15+
/// This contains the tool's name, description, input schema, etc.
16+
/// </summary>
17+
[JsonPropertyOrder(10)]
18+
public required ToolDefinition ToolDefinition { get; set; }
19+
20+
public ToolData(
21+
string name,
22+
string imageName,
23+
string imageVersion,
24+
ToolDefinition toolDefinition,
25+
Dictionary<string, string>? environmentVariables = null,
26+
int? replicaCount = 1,
27+
string description = "",
28+
bool useWorkloadIdentity = false)
29+
: base(name, imageName, imageVersion, environmentVariables, replicaCount, description, useWorkloadIdentity)
30+
{
31+
if (name != toolDefinition.Name)
32+
{
33+
throw new ArgumentException("Tool name in ToolData must match the name in ToolDefinition.");
34+
}
35+
36+
ToolDefinition = toolDefinition;
37+
}
38+
39+
public ToolData() { }
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using System.Text.Json.Serialization;
5+
using ModelContextProtocol.Protocol;
6+
7+
namespace Microsoft.McpGateway.Management.Contracts
8+
{
9+
/// <summary>
10+
/// Represents an MCP tool definition.
11+
/// Combines the MCP Tool contract with execution metadata.
12+
/// </summary>
13+
public class ToolDefinition
14+
{
15+
/// <summary>
16+
/// The MCP Tool definition (contains name, description, input schema).
17+
/// </summary>
18+
[JsonPropertyName("tool")]
19+
public required Tool Tool { get; set; }
20+
21+
/// <summary>
22+
/// The unique name of the tool (derived from Tool.Name for convenience).
23+
/// </summary>
24+
[JsonIgnore]
25+
public string Name => Tool.Name;
26+
27+
/// <summary>
28+
/// The port for the execution service endpoint.
29+
/// Defaults to 443.
30+
/// </summary>
31+
[JsonPropertyName("port")]
32+
public int Port { get; set; } = 443;
33+
34+
/// <summary>
35+
/// The path for the execution service endpoint.
36+
/// Defaults to "/score".
37+
/// </summary>
38+
[JsonPropertyName("path")]
39+
public string Path { get; set; } = "/score";
40+
}
41+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using System.Text.Json;
5+
using System.Text.Json.Serialization;
6+
7+
namespace Microsoft.McpGateway.Management.Contracts
8+
{
9+
/// <summary>
10+
/// Represents a tool resource with metadata.
11+
/// </summary>
12+
public class ToolResource : ToolData
13+
{
14+
[JsonPropertyOrder(-1)]
15+
[JsonPropertyName("id")]
16+
public required string Id { get; set; }
17+
18+
/// <summary>
19+
/// The ID of the user who created the tool.
20+
/// </summary>
21+
[JsonPropertyOrder(30)]
22+
public required string CreatedBy { get; set; }
23+
24+
/// <summary>
25+
/// The date and time when the tool was created.
26+
/// </summary>
27+
[JsonPropertyOrder(31)]
28+
public DateTimeOffset CreatedAt { get; set; }
29+
30+
/// <summary>
31+
/// The date and time when the tool was last updated.
32+
/// </summary>
33+
[JsonPropertyOrder(32)]
34+
public DateTimeOffset LastUpdatedAt { get; set; }
35+
36+
public static ToolResource Create(ToolData data, string createdBy, DateTimeOffset createdAt) =>
37+
new()
38+
{
39+
Id = data.Name,
40+
Name = data.Name,
41+
ImageName = data.ImageName,
42+
ImageVersion = data.ImageVersion,
43+
EnvironmentVariables = data.EnvironmentVariables,
44+
ReplicaCount = data.ReplicaCount,
45+
Description = data.Description,
46+
UseWorkloadIdentity = data.UseWorkloadIdentity,
47+
ToolDefinition = data.ToolDefinition,
48+
CreatedBy = createdBy,
49+
CreatedAt = createdAt,
50+
LastUpdatedAt = DateTimeOffset.UtcNow,
51+
};
52+
53+
public ToolResource() { }
54+
}
55+
}

0 commit comments

Comments
 (0)