Skip to content

Commit a3e8601

Browse files
committed
Merge remote-tracking branch 'origin/main' into localden/experimental-inmemory-oauth-3
# Conflicts: # tests/ModelContextProtocol.AspNetCore.Tests/Utils/KestrelInMemoryTest.cs
2 parents 03d0fda + 9d835a0 commit a3e8601

File tree

23 files changed

+111
-119
lines changed

23 files changed

+111
-119
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,24 +166,24 @@ public static class MyPrompts
166166
More control is also available, with fine-grained control over configuring the server and how it should handle client requests. For example:
167167

168168
```csharp
169-
using ModelContextProtocol.Protocol.Transport;
170-
using ModelContextProtocol.Protocol.Types;
169+
using ModelContextProtocol;
170+
using ModelContextProtocol.Protocol;
171171
using ModelContextProtocol.Server;
172172
using System.Text.Json;
173173

174174
McpServerOptions options = new()
175175
{
176-
ServerInfo = new Implementation() { Name = "MyServer", Version = "1.0.0" },
177-
Capabilities = new ServerCapabilities()
176+
ServerInfo = new Implementation { Name = "MyServer", Version = "1.0.0" },
177+
Capabilities = new ServerCapabilities
178178
{
179-
Tools = new ToolsCapability()
179+
Tools = new ToolsCapability
180180
{
181181
ListToolsHandler = (request, cancellationToken) =>
182-
ValueTask.FromResult(new ListToolsResult()
182+
ValueTask.FromResult(new ListToolsResult
183183
{
184184
Tools =
185185
[
186-
new Tool()
186+
new Tool
187187
{
188188
Name = "echo",
189189
Description = "Echoes the input back to the client.",
@@ -212,9 +212,9 @@ McpServerOptions options = new()
212212
throw new McpException("Missing required argument 'message'");
213213
}
214214

215-
return ValueTask.FromResult(new CallToolResponse()
215+
return ValueTask.FromResult(new CallToolResult
216216
{
217-
Content = [new Content() { Text = $"Echo: {message}", Type = "text" }]
217+
Content = [new TextContentBlock { Text = $"Echo: {message}", Type = "text" }]
218218
});
219219
}
220220

samples/EverythingServer/Tools/AnnotatedMessageTool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static IEnumerable<ContentBlock> AnnotatedMessage(MessageType messageType
3939

4040
if (includeImage)
4141
{
42-
contents.Add(new ImageContentBlock()
42+
contents.Add(new ImageContentBlock
4343
{
4444
Data = TinyImageTool.MCP_TINY_IMAGE.Split(",").Last(),
4545
MimeType = "image/png",

samples/EverythingServer/Tools/SampleLlmTool.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public static async Task<string> SampleLLM(
2222

2323
private static CreateMessageRequestParams CreateRequestSamplingParams(string context, string uri, int maxTokens = 100)
2424
{
25-
return new CreateMessageRequestParams()
25+
return new CreateMessageRequestParams
2626
{
27-
Messages = [new SamplingMessage()
27+
Messages = [new SamplingMessage
2828
{
2929
Role = Role.User,
3030
Content = new TextContentBlock { Text = $"Resource {uri} context: {context}" },

samples/TestServerWithHosting/Tools/SampleLlmTool.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public static async Task<string> SampleLLM(
2525

2626
private static CreateMessageRequestParams CreateRequestSamplingParams(string context, string uri, int maxTokens = 100)
2727
{
28-
return new CreateMessageRequestParams()
28+
return new CreateMessageRequestParams
2929
{
30-
Messages = [new SamplingMessage()
30+
Messages = [new SamplingMessage
3131
{
3232
Role = Role.User,
3333
Content = new TextContentBlock { Text = $"Resource {uri} context: {context}" },

src/ModelContextProtocol.Core/AIContentExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,21 +188,21 @@ internal static ContentBlock ToContent(this AIContent content) =>
188188
Text = textContent.Text,
189189
},
190190

191-
DataContent dataContent when dataContent.HasTopLevelMediaType("image") => new ImageContentBlock()
191+
DataContent dataContent when dataContent.HasTopLevelMediaType("image") => new ImageContentBlock
192192
{
193193
Data = dataContent.Base64Data.ToString(),
194194
MimeType = dataContent.MediaType,
195195
},
196196

197-
DataContent dataContent when dataContent.HasTopLevelMediaType("audio") => new AudioContentBlock()
197+
DataContent dataContent when dataContent.HasTopLevelMediaType("audio") => new AudioContentBlock
198198
{
199199
Data = dataContent.Base64Data.ToString(),
200200
MimeType = dataContent.MediaType,
201201
},
202202

203-
DataContent dataContent => new EmbeddedResourceBlock()
203+
DataContent dataContent => new EmbeddedResourceBlock
204204
{
205-
Resource = new BlobResourceContents()
205+
Resource = new BlobResourceContents
206206
{
207207
Blob = dataContent.Base64Data.ToString(),
208208
MimeType = dataContent.MediaType,

src/ModelContextProtocol.Core/Protocol/ContentBlock.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,30 +149,30 @@ public class Converter : JsonConverter<ContentBlock>
149149
Meta = meta,
150150
},
151151

152-
"image" => new ImageContentBlock()
152+
"image" => new ImageContentBlock
153153
{
154154
Data = data ?? throw new JsonException("Image data must be provided for 'image' type."),
155155
MimeType = mimeType ?? throw new JsonException("MIME type must be provided for 'image' type."),
156156
Annotations = annotations,
157157
Meta = meta,
158158
},
159159

160-
"audio" => new AudioContentBlock()
160+
"audio" => new AudioContentBlock
161161
{
162162
Data = data ?? throw new JsonException("Audio data must be provided for 'audio' type."),
163163
MimeType = mimeType ?? throw new JsonException("MIME type must be provided for 'audio' type."),
164164
Annotations = annotations,
165165
Meta = meta,
166166
},
167167

168-
"resource" => new EmbeddedResourceBlock()
168+
"resource" => new EmbeddedResourceBlock
169169
{
170170
Resource = resource ?? throw new JsonException("Resource contents must be provided for 'resource' type."),
171171
Annotations = annotations,
172172
Meta = meta,
173173
},
174174

175-
"resource_link" => new ResourceLinkBlock()
175+
"resource_link" => new ResourceLinkBlock
176176
{
177177
Uri = uri ?? throw new JsonException("URI must be provided for 'resource_link' type."),
178178
Name = name ?? throw new JsonException("Name must be provided for 'resource_link' type."),

src/ModelContextProtocol.Core/Protocol/ProgressNotificationParams.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public sealed class Converter : JsonConverter<ProgressNotificationParams>
9898
return new ProgressNotificationParams
9999
{
100100
ProgressToken = progressToken.GetValueOrDefault(),
101-
Progress = new ProgressNotificationValue()
101+
Progress = new ProgressNotificationValue
102102
{
103103
Progress = progress.GetValueOrDefault(),
104104
Total = total,

src/ModelContextProtocol.Core/Server/AIFunctionMcpServerResource.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,14 +421,14 @@ private AIFunctionMcpServerResource(AIFunction function, ResourceTemplate resour
421421
Contents = aiContents.Select<AIContent, ResourceContents>(
422422
ac => ac switch
423423
{
424-
TextContent tc => new TextResourceContents()
424+
TextContent tc => new TextResourceContents
425425
{
426426
Uri = request.Params!.Uri,
427427
MimeType = ProtocolResourceTemplate.MimeType,
428428
Text = tc.Text
429429
},
430430

431-
DataContent dc => new BlobResourceContents()
431+
DataContent dc => new BlobResourceContents
432432
{
433433
Uri = request.Params!.Uri,
434434
MimeType = dc.MediaType,
@@ -441,7 +441,7 @@ private AIFunctionMcpServerResource(AIFunction function, ResourceTemplate resour
441441

442442
IEnumerable<string> strings => new()
443443
{
444-
Contents = strings.Select<string, ResourceContents>(text => new TextResourceContents()
444+
Contents = strings.Select<string, ResourceContents>(text => new TextResourceContents
445445
{
446446
Uri = request.Params!.Uri,
447447
MimeType = ProtocolResourceTemplate.MimeType,

src/ModelContextProtocol.Core/Server/AIFunctionMcpServerTool.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,6 @@ internal sealed partial class AIFunctionMcpServerTool : McpServerTool
7070
options);
7171
}
7272

73-
// TODO: Fix the need for this suppression.
74-
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:ReflectionToDynamicallyAccessedMembers",
75-
Justification = "AIFunctionFactory ensures that the Type passed to AIFunctionFactoryOptions.CreateInstance has public constructors preserved")]
76-
internal static Func<Type, AIFunctionArguments, object> GetCreateInstanceFunc() =>
77-
static ([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] type, args) => args.Services is { } services ?
78-
ActivatorUtilities.CreateInstance(services, type) :
79-
Activator.CreateInstance(type)!;
80-
8173
private static AIFunctionFactoryOptions CreateAIFunctionFactoryOptions(
8274
MethodInfo method, McpServerToolCreateOptions? options) =>
8375
new()

src/ModelContextProtocol.Core/Server/McpServerExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ public static async Task<ChatResponse> SampleAsync(
103103
{
104104
Role = role,
105105
Content = dataContent.HasTopLevelMediaType("image") ?
106-
new ImageContentBlock()
106+
new ImageContentBlock
107107
{
108108
MimeType = dataContent.MediaType,
109109
Data = dataContent.Base64Data.ToString(),
110110
} :
111-
new AudioContentBlock()
111+
new AudioContentBlock
112112
{
113113
MimeType = dataContent.MediaType,
114114
Data = dataContent.Base64Data.ToString(),
@@ -344,7 +344,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
344344

345345
void Log(LogLevel logLevel, string message)
346346
{
347-
_ = server.SendNotificationAsync(NotificationMethods.LoggingMessageNotification, new LoggingMessageNotificationParams()
347+
_ = server.SendNotificationAsync(NotificationMethods.LoggingMessageNotification, new LoggingMessageNotificationParams
348348
{
349349
Level = McpServer.ToLoggingLevel(logLevel),
350350
Data = JsonSerializer.SerializeToElement(message, McpJsonUtilities.JsonContext.Default.String),

0 commit comments

Comments
 (0)