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

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

* Fix build error.
This commit is contained in:
Eirik Tsarpalis 2025-06-26 16:55:54 +03:00 • committed by GitHub
commit 55bda787ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -28,7 +28,7 @@ public class Program
private static void ConfigureOptions(McpServerOptions options)
{
options.Capabilities = new ServerCapabilities()
options.Capabilities = new ServerCapabilities
{
Tools = new(),
Resources = new(),
@ -41,9 +41,9 @@ public class Program
#region Helped method
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}" },
@ -63,13 +63,13 @@ public class Program
string uri = $"test://static/resource/{i + 1}";
if (i % 2 == 0)
{
resources.Add(new Resource()
resources.Add(new Resource
{
Uri = uri,
Name = $"Resource {i + 1}",
MimeType = "text/plain"
});
resourceContents.Add(new TextResourceContents()
resourceContents.Add(new TextResourceContents
{
Uri = uri,
MimeType = "text/plain",
@ -79,13 +79,13 @@ public class Program
else
{
var buffer = Encoding.UTF8.GetBytes($"Resource {i + 1}: This is a base64 blob");
resources.Add(new Resource()
resources.Add(new Resource
{
Uri = uri,
Name = $"Resource {i + 1}",
MimeType = "application/octet-stream"
});
resourceContents.Add(new BlobResourceContents()
resourceContents.Add(new BlobResourceContents
{
Uri = uri,
MimeType = "application/octet-stream",
@ -102,11 +102,11 @@ public class Program
{
ListToolsHandler = async (request, cancellationToken) =>
{
return new ListToolsResult()
return new ListToolsResult
{
Tools =
[
new Tool()
new Tool
{
Name = "echo",
Description = "Echoes the input back to the client.",
@ -123,7 +123,7 @@ public class Program
}
""", McpJsonUtilities.DefaultOptions),
},
new Tool()
new Tool
{
Name = "echoSessionId",
Description = "Echoes the session id back to the client.",
@ -133,7 +133,7 @@ public class Program
}
""", McpJsonUtilities.DefaultOptions),
},
new Tool()
new Tool
{
Name = "sampleLLM",
Description = "Samples from an LLM using MCP's sampling feature.",
@ -169,14 +169,14 @@ public class Program
{
throw new McpException("Missing required argument 'message'", McpErrorCode.InvalidParams);
}
return new CallToolResult()
return new CallToolResult
{
Content = [new TextContentBlock { Text = $"Echo: {message}" }]
};
}
else if (request.Params.Name == "echoSessionId")
{
return new CallToolResult()
return new CallToolResult
{
Content = [new TextContentBlock { Text = request.Server.SessionId ?? string.Empty }]
};
@ -192,7 +192,7 @@ public class Program
var sampleResult = await request.Server.SampleAsync(CreateRequestSamplingParams(prompt.ToString(), "sampleLLM", Convert.ToInt32(maxTokens.ToString())),
cancellationToken);
return new CallToolResult()
return new CallToolResult
{
Content = [new TextContentBlock { Text = $"LLM sampling result: {(sampleResult.Content as TextContentBlock)?.Text}" }]
};
@ -208,10 +208,10 @@ public class Program
ListResourceTemplatesHandler = async (request, cancellationToken) =>
{
return new ListResourceTemplatesResult()
return new ListResourceTemplatesResult
{
ResourceTemplates = [
new ResourceTemplate()
new ResourceTemplate
{
UriTemplate = "test://dynamic/resource/{id}",
Name = "Dynamic Resource",
@ -245,7 +245,7 @@ public class Program
nextCursor = Convert.ToBase64String(Encoding.UTF8.GetBytes(endIndex.ToString()));
}
return new ListResourcesResult()
return new ListResourcesResult
{
NextCursor = nextCursor,
Resources = resources.GetRange(startIndex, endIndex - startIndex)
@ -266,10 +266,10 @@ public class Program
throw new McpException($"Invalid resource URI: '{request.Params.Uri}'", McpErrorCode.InvalidParams);
}
return new ReadResourceResult()
return new ReadResourceResult
{
Contents = [
new TextResourceContents()
new TextResourceContents
{
Uri = request.Params.Uri,
MimeType = "text/plain",
@ -282,7 +282,7 @@ public class Program
ResourceContents? contents = resourceContents.FirstOrDefault(r => r.Uri == request.Params.Uri) ??
throw new McpException($"Resource not found: '{request.Params.Uri}'", McpErrorCode.InvalidParams);
return new ReadResourceResult()
return new ReadResourceResult
{
Contents = [contents]
};
@ -292,27 +292,27 @@ public class Program
{
ListPromptsHandler = async (request, cancellationToken) =>
{
return new ListPromptsResult()
return new ListPromptsResult
{
Prompts = [
new Prompt()
new Prompt
{
Name = "simple_prompt",
Description = "A prompt without arguments"
},
new Prompt()
new Prompt
{
Name = "complex_prompt",
Description = "A prompt with arguments",
Arguments =
[
new PromptArgument()
new PromptArgument
{
Name = "temperature",
Description = "Temperature setting",
Required = true
},
new PromptArgument()
new PromptArgument
{
Name = "style",
Description = "Output style",
@ -332,7 +332,7 @@ public class Program
List<PromptMessage> messages = new();
if (request.Params.Name == "simple_prompt")
{
messages.Add(new PromptMessage()
messages.Add(new PromptMessage
{
Role = Role.User,
Content = new TextContentBlock { Text = "This is a simple prompt without arguments." },
@ -342,20 +342,20 @@ public class Program
{
string temperature = request.Params.Arguments?["temperature"].ToString() ?? "unknown";
string style = request.Params.Arguments?["style"].ToString() ?? "unknown";
messages.Add(new PromptMessage()
messages.Add(new PromptMessage
{
Role = Role.User,
Content = new TextContentBlock { Text = $"This is a complex prompt with arguments: temperature={temperature}, style={style}" },
});
messages.Add(new PromptMessage()
messages.Add(new PromptMessage
{
Role = Role.Assistant,
Content = new TextContentBlock { Text = "I understand. You've provided a complex prompt with temperature and style arguments. How would you like me to proceed?" },
});
messages.Add(new PromptMessage()
messages.Add(new PromptMessage
{
Role = Role.User,
Content = new ImageContentBlock()
Content = new ImageContentBlock
{
Data = MCP_TINY_IMAGE,
MimeType = "image/png"
@ -367,7 +367,7 @@ public class Program
throw new McpException($"Unknown prompt: {request.Params.Name}", McpErrorCode.InvalidParams);
}
return new GetPromptResult()
return new GetPromptResult
{
Messages = messages
};