Skip to content

Commit dc24e39

Browse files
mikekistlerCopilot
andauthored
Apply suggestions from code review
Co-authored-by: Copilot <[email protected]>
1 parent 65b3a9b commit dc24e39

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

src/ModelContextProtocol.Core/Server/McpServer.Methods.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,21 @@ public ValueTask<CreateMessageResult> SampleAsync(
6262

6363
if (options?.Meta is not null)
6464
{
65-
request.Meta = options.Meta;
65+
if (request.Meta is not null)
66+
{
67+
// Merge existing request.Meta and options.Meta, with options.Meta taking precedence
68+
var mergedMeta = new Dictionary<string, object?>(request.Meta);
69+
foreach (var kvp in options.Meta)
70+
{
71+
mergedMeta[kvp.Key] = kvp.Value;
72+
}
73+
request.Meta = mergedMeta;
74+
}
75+
else
76+
{
77+
// Only options.Meta is present
78+
request.Meta = new Dictionary<string, object?>(options.Meta);
79+
}
6680
}
6781

6882
return SendRequestAsync(
@@ -213,7 +227,25 @@ public ValueTask<ListRootsResult> RequestRootsAsync(
213227

214228
if (options?.Meta is not null)
215229
{
216-
request.Meta = options.Meta;
230+
if (request.Meta is null)
231+
{
232+
// No existing meta, just assign
233+
request.Meta = options.Meta;
234+
}
235+
else
236+
{
237+
// Merge existing and options.Meta, options.Meta takes precedence
238+
var merged = new JsonObject();
239+
foreach (var kvp in request.Meta)
240+
{
241+
merged[kvp.Key] = kvp.Value;
242+
}
243+
foreach (var kvp in options.Meta)
244+
{
245+
merged[kvp.Key] = kvp.Value;
246+
}
247+
request.Meta = merged;
248+
}
217249
}
218250

219251
return SendRequestAsync(

0 commit comments

Comments
 (0)