Skip to content

Styling: remove a few redundant parens from object initializer expressions. #548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,17 @@ using System.Text.Json;

McpServerOptions options = new()
{
ServerInfo = new Implementation() { Name = "MyServer", Version = "1.0.0" },
Capabilities = new ServerCapabilities()
ServerInfo = new Implementation { Name = "MyServer", Version = "1.0.0" },
Capabilities = new ServerCapabilities
{
Tools = new ToolsCapability()
Tools = new ToolsCapability
{
ListToolsHandler = (request, cancellationToken) =>
ValueTask.FromResult(new ListToolsResult()
ValueTask.FromResult(new ListToolsResult
{
Tools =
[
new Tool()
new Tool
{
Name = "echo",
Description = "Echoes the input back to the client.",
Expand Down
2 changes: 1 addition & 1 deletion samples/EverythingServer/Tools/AnnotatedMessageTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static IEnumerable<ContentBlock> AnnotatedMessage(MessageType messageType

if (includeImage)
{
contents.Add(new ImageContentBlock()
contents.Add(new ImageContentBlock
{
Data = TinyImageTool.MCP_TINY_IMAGE.Split(",").Last(),
MimeType = "image/png",
Expand Down
4 changes: 2 additions & 2 deletions samples/EverythingServer/Tools/SampleLlmTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public static async Task<string> SampleLLM(

private static CreateMessageRequestParams CreateRequestSamplingParams(string context, string uri, int maxTokens = 100)
{
return new CreateMessageRequestParams()
return new CreateMessageRequestParams
{
Messages = [new SamplingMessage()
Messages = [new SamplingMessage
{
Role = Role.User,
Content = new TextContentBlock { Text = $"Resource {uri} context: {context}" },
Expand Down
4 changes: 2 additions & 2 deletions samples/TestServerWithHosting/Tools/SampleLlmTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public static async Task<string> SampleLLM(

private static CreateMessageRequestParams CreateRequestSamplingParams(string context, string uri, int maxTokens = 100)
{
return new CreateMessageRequestParams()
return new CreateMessageRequestParams
{
Messages = [new SamplingMessage()
Messages = [new SamplingMessage
{
Role = Role.User,
Content = new TextContentBlock { Text = $"Resource {uri} context: {context}" },
Expand Down
8 changes: 4 additions & 4 deletions src/ModelContextProtocol.Core/AIContentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,21 +188,21 @@ internal static ContentBlock ToContent(this AIContent content) =>
Text = textContent.Text,
},

DataContent dataContent when dataContent.HasTopLevelMediaType("image") => new ImageContentBlock()
DataContent dataContent when dataContent.HasTopLevelMediaType("image") => new ImageContentBlock
{
Data = dataContent.Base64Data.ToString(),
MimeType = dataContent.MediaType,
},

DataContent dataContent when dataContent.HasTopLevelMediaType("audio") => new AudioContentBlock()
DataContent dataContent when dataContent.HasTopLevelMediaType("audio") => new AudioContentBlock
{
Data = dataContent.Base64Data.ToString(),
MimeType = dataContent.MediaType,
},

DataContent dataContent => new EmbeddedResourceBlock()
DataContent dataContent => new EmbeddedResourceBlock
{
Resource = new BlobResourceContents()
Resource = new BlobResourceContents
{
Blob = dataContent.Base64Data.ToString(),
MimeType = dataContent.MediaType,
Expand Down
8 changes: 4 additions & 4 deletions src/ModelContextProtocol.Core/Protocol/ContentBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,30 +149,30 @@ public class Converter : JsonConverter<ContentBlock>
Meta = meta,
},

"image" => new ImageContentBlock()
"image" => new ImageContentBlock
{
Data = data ?? throw new JsonException("Image data must be provided for 'image' type."),
MimeType = mimeType ?? throw new JsonException("MIME type must be provided for 'image' type."),
Annotations = annotations,
Meta = meta,
},

"audio" => new AudioContentBlock()
"audio" => new AudioContentBlock
{
Data = data ?? throw new JsonException("Audio data must be provided for 'audio' type."),
MimeType = mimeType ?? throw new JsonException("MIME type must be provided for 'audio' type."),
Annotations = annotations,
Meta = meta,
},

"resource" => new EmbeddedResourceBlock()
"resource" => new EmbeddedResourceBlock
{
Resource = resource ?? throw new JsonException("Resource contents must be provided for 'resource' type."),
Annotations = annotations,
Meta = meta,
},

"resource_link" => new ResourceLinkBlock()
"resource_link" => new ResourceLinkBlock
{
Uri = uri ?? throw new JsonException("URI must be provided for 'resource_link' type."),
Name = name ?? throw new JsonException("Name must be provided for 'resource_link' type."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public sealed class Converter : JsonConverter<ProgressNotificationParams>
return new ProgressNotificationParams
{
ProgressToken = progressToken.GetValueOrDefault(),
Progress = new ProgressNotificationValue()
Progress = new ProgressNotificationValue
{
Progress = progress.GetValueOrDefault(),
Total = total,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,14 +421,14 @@ private AIFunctionMcpServerResource(AIFunction function, ResourceTemplate resour
Contents = aiContents.Select<AIContent, ResourceContents>(
ac => ac switch
{
TextContent tc => new TextResourceContents()
TextContent tc => new TextResourceContents
{
Uri = request.Params!.Uri,
MimeType = ProtocolResourceTemplate.MimeType,
Text = tc.Text
},

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

IEnumerable<string> strings => new()
{
Contents = strings.Select<string, ResourceContents>(text => new TextResourceContents()
Contents = strings.Select<string, ResourceContents>(text => new TextResourceContents
{
Uri = request.Params!.Uri,
MimeType = ProtocolResourceTemplate.MimeType,
Expand Down
6 changes: 3 additions & 3 deletions src/ModelContextProtocol.Core/Server/McpServerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ public static async Task<ChatResponse> SampleAsync(
{
Role = role,
Content = dataContent.HasTopLevelMediaType("image") ?
new ImageContentBlock()
new ImageContentBlock
{
MimeType = dataContent.MediaType,
Data = dataContent.Base64Data.ToString(),
} :
new AudioContentBlock()
new AudioContentBlock
{
MimeType = dataContent.MediaType,
Data = dataContent.Base64Data.ToString(),
Expand Down Expand Up @@ -344,7 +344,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except

void Log(LogLevel logLevel, string message)
{
_ = server.SendNotificationAsync(NotificationMethods.LoggingMessageNotification, new LoggingMessageNotificationParams()
_ = server.SendNotificationAsync(NotificationMethods.LoggingMessageNotification, new LoggingMessageNotificationParams
{
Level = McpServer.ToLoggingLevel(logLevel),
Data = JsonSerializer.SerializeToElement(message, McpJsonUtilities.JsonContext.Default.String),
Expand Down
2 changes: 1 addition & 1 deletion tests/ModelContextProtocol.AspNetCore.Tests/MapMcpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected async Task<IMcpClient> ConnectAsync(
// Default behavior when no options are provided
path ??= UseStreamableHttp ? "/" : "/sse";

await using var transport = new SseClientTransport(transportOptions ?? new SseClientTransportOptions()
await using var transport = new SseClientTransport(transportOptions ?? new SseClientTransportOptions
{
Endpoint = new Uri($"http://localhost{path}"),
TransportMode = UseStreamableHttp ? HttpTransportMode.StreamableHttp : HttpTransportMode.Sse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public async Task AdditionalHeaders_AreSent_InGetAndPostRequests()
app.MapMcp();
await app.StartAsync(TestContext.Current.CancellationToken);

var sseOptions = new SseClientTransportOptions()
var sseOptions = new SseClientTransportOptions
{
Endpoint = new Uri("http://localhost/sse"),
Name = "In-memory SSE Client",
Expand All @@ -222,7 +222,7 @@ public async Task EmptyAdditionalHeadersKey_Throws_InvalidOperationException()
app.MapMcp();
await app.StartAsync(TestContext.Current.CancellationToken);

var sseOptions = new SseClientTransportOptions()
var sseOptions = new SseClientTransportOptions
{
Endpoint = new Uri("http://localhost/sse"),
Name = "In-memory SSE Client",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class SseServerIntegrationTestFixture : IAsyncDisposable

public SseServerIntegrationTestFixture()
{
var socketsHttpHandler = new SocketsHttpHandler()
var socketsHttpHandler = new SocketsHttpHandler
{
ConnectCallback = (context, token) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private async Task StartAsync(bool enableDelete = false)
return Results.Json(new JsonRpcResponse
{
Id = request.Id,
Result = JsonSerializer.SerializeToNode(new CallToolResult()
Result = JsonSerializer.SerializeToNode(new CallToolResult
{
Content = [new TextContentBlock { Text = parameters.Arguments["message"].ToString() }],
}, McpJsonUtilities.DefaultOptions),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public KestrelInMemoryTest(ITestOutputHelper testOutputHelper)
Builder.Services.AddSingleton<IConnectionListenerFactory>(_inMemoryTransport);
Builder.Services.AddSingleton(XunitLoggerProvider);

HttpClient = new HttpClient(new SocketsHttpHandler()
HttpClient = new HttpClient(new SocketsHttpHandler
{
ConnectCallback = (context, token) =>
{
Expand Down
Loading
Loading