Skip to content

Commit 051aee8

Browse files
committed
update merge
1 parent 3ce1ad2 commit 051aee8

21 files changed

Lines changed: 402 additions & 387 deletions

src/ManagedCode.MCPGateway/Catalog/Internal/Sources/McpGatewayToolSourceRegistrations.cs

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,19 @@ internal sealed record McpGatewayLoadedTool(
2424
ToolTaskSupport? TaskSupport = null
2525
);
2626

27-
internal sealed record McpGatewayLoadedPrompt(
28-
string Name,
29-
string? Title,
30-
string? Description,
31-
IReadOnlyList<PromptArgument> Arguments
32-
);
27+
internal sealed record McpGatewayLoadedPrompt(Prompt ProtocolPrompt)
28+
{
29+
public string Name => ProtocolPrompt.Name;
30+
31+
public string? Title => ProtocolPrompt.Title;
32+
33+
public string? Description => ProtocolPrompt.Description;
34+
35+
public IReadOnlyList<PromptArgument> Arguments =>
36+
ProtocolPrompt.Arguments as IReadOnlyList<PromptArgument>
37+
?? ProtocolPrompt.Arguments?.ToArray()
38+
?? [];
39+
}
3340

3441
internal sealed record McpGatewayLoadedResource(Resource Resource);
3542

@@ -199,18 +206,21 @@ CancellationToken cancellationToken
199206
_prompts
200207
.Values.OrderBy(static prompt => prompt.Name, StringComparer.Ordinal)
201208
.Select(static prompt => new McpGatewayLoadedPrompt(
202-
prompt.Name,
203-
prompt.DisplayName,
204-
prompt.Description,
205-
prompt
206-
.Arguments.Select(static argument => new PromptArgument
207-
{
208-
Name = argument.Name,
209-
Title = argument.DisplayName,
210-
Description = argument.Description,
211-
Required = argument.IsRequired,
212-
})
213-
.ToList()
209+
new Prompt
210+
{
211+
Name = prompt.Name,
212+
Title = prompt.DisplayName,
213+
Description = prompt.Description,
214+
Arguments = prompt
215+
.Arguments.Select(static argument => new PromptArgument
216+
{
217+
Name = argument.Name,
218+
Title = argument.DisplayName,
219+
Description = argument.Description,
220+
Required = argument.IsRequired,
221+
})
222+
.ToList(),
223+
}
214224
))
215225
.ToList()
216226
);
@@ -525,12 +535,7 @@ CancellationToken cancellationToken
525535
var prompts = await client.ListPromptsAsync(new RequestOptions(), cancellationToken);
526536
return prompts
527537
.Where(static prompt => !string.IsNullOrWhiteSpace(prompt.Name))
528-
.Select(static prompt => new McpGatewayLoadedPrompt(
529-
Name: prompt.Name.Trim(),
530-
Title: prompt.Title,
531-
Description: prompt.Description,
532-
Arguments: prompt.ProtocolPrompt.Arguments?.ToList() ?? []
533-
))
538+
.Select(static prompt => new McpGatewayLoadedPrompt(prompt.ProtocolPrompt))
534539
.ToList();
535540
}
536541

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using ModelContextProtocol.Protocol;
2+
3+
namespace ManagedCode.MCPGateway;
4+
5+
internal static class McpGatewayProtocolPrimitive
6+
{
7+
public static Prompt Clone(Prompt prompt) =>
8+
new()
9+
{
10+
Name = prompt.Name,
11+
Title = prompt.Title,
12+
Description = prompt.Description,
13+
Arguments = prompt.Arguments?.Select(ClonePromptArgument).ToList(),
14+
Icons = CloneIcons(prompt.Icons),
15+
Meta = McpGatewayProtocolTool.CloneMeta(prompt.Meta),
16+
};
17+
18+
public static Resource Clone(Resource resource) =>
19+
new()
20+
{
21+
Name = resource.Name,
22+
Title = resource.Title,
23+
Uri = resource.Uri,
24+
Description = resource.Description,
25+
MimeType = resource.MimeType,
26+
Annotations = CloneAnnotations(resource.Annotations),
27+
Size = resource.Size,
28+
Icons = CloneIcons(resource.Icons),
29+
Meta = McpGatewayProtocolTool.CloneMeta(resource.Meta),
30+
};
31+
32+
public static ResourceTemplate Clone(ResourceTemplate template) =>
33+
new()
34+
{
35+
Name = template.Name,
36+
Title = template.Title,
37+
UriTemplate = template.UriTemplate,
38+
Description = template.Description,
39+
MimeType = template.MimeType,
40+
Annotations = CloneAnnotations(template.Annotations),
41+
Icons = CloneIcons(template.Icons),
42+
Meta = McpGatewayProtocolTool.CloneMeta(template.Meta),
43+
};
44+
45+
public static PromptArgument ClonePromptArgument(PromptArgument argument) =>
46+
new()
47+
{
48+
Name = argument.Name,
49+
Title = argument.Title,
50+
Description = argument.Description,
51+
Required = argument.Required,
52+
};
53+
54+
public static IList<Icon>? CloneIcons(IList<Icon>? icons) =>
55+
icons?.Select(static icon => new Icon
56+
{
57+
Source = icon.Source,
58+
MimeType = icon.MimeType,
59+
Sizes = icon.Sizes?.ToArray(),
60+
Theme = icon.Theme,
61+
}).ToList();
62+
63+
private static Annotations? CloneAnnotations(Annotations? annotations) =>
64+
annotations is null
65+
? null
66+
: new Annotations
67+
{
68+
Audience = annotations.Audience?.ToArray(),
69+
Priority = annotations.Priority,
70+
LastModified = annotations.LastModified,
71+
};
72+
}

src/ManagedCode.MCPGateway/Gateway/Internal/Serialization/McpGatewayProtocolSchema.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ namespace ManagedCode.MCPGateway;
44

55
internal static class McpGatewayProtocolSchema
66
{
7-
private const string TypePropertyName = "type";
8-
private const string ObjectTypeName = "object";
7+
private const string JsonSchemaTypePropertyName = "type";
8+
private const string JsonSchemaObjectTypeName = "object";
99

1010
public static bool IsToolObjectSchema(JsonElement schema) =>
1111
schema.ValueKind == JsonValueKind.Object
12-
&& schema.TryGetProperty(TypePropertyName, out var type)
12+
&& schema.TryGetProperty(JsonSchemaTypePropertyName, out var type)
1313
&& type.ValueKind == JsonValueKind.String
14-
&& string.Equals(type.GetString(), ObjectTypeName, StringComparison.Ordinal);
14+
&& type.ValueEquals(JsonSchemaObjectTypeName);
1515
}

src/ManagedCode.MCPGateway/Hosting/Internal/Server/McpGatewayMcpServerHandlers.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,7 @@ await promptNotificationManager.RegisterDownstreamServerAsync(
188188
? McpGatewayMcpServerProtocolMapper.CreateErrorPromptResult(
189189
$"Prompt '{exportedPromptName}' was not found."
190190
)
191-
: new GetPromptResult
192-
{
193-
Description = promptResult.Description,
194-
Messages = promptResult
195-
.Messages.Select(McpGatewayMcpServerProtocolMapper.ToProtocolPromptMessage)
196-
.Where(static message => message is not null)
197-
.Cast<PromptMessage>()
198-
.ToList(),
199-
};
191+
: promptResult.ProtocolResult;
200192
}
201193

202194
public async ValueTask<ListResourcesResult> ListResourcesAsync(

0 commit comments

Comments
 (0)