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:
parent
802424ee08
commit
55bda787ae
23 changed files with 108 additions and 108 deletions
10
README.md
10
README.md
|
|
@ -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.",
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class AnnotatedMessageTool
|
|||
|
||||
if (includeImage)
|
||||
{
|
||||
contents.Add(new ImageContentBlock()
|
||||
contents.Add(new ImageContentBlock
|
||||
{
|
||||
Data = TinyImageTool.MCP_TINY_IMAGE.Split(",").Last(),
|
||||
MimeType = "image/png",
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@ public class SampleLlmTool
|
|||
|
||||
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}" },
|
||||
|
|
|
|||
|
|
@ -25,9 +25,9 @@ public sealed class SampleLlmTool
|
|||
|
||||
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}" },
|
||||
|
|
|
|||
|
|
@ -188,21 +188,21 @@ public static class AIContentExtensions
|
|||
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,
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ public abstract class 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."),
|
||||
|
|
@ -157,7 +157,7 @@ public abstract class ContentBlock
|
|||
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."),
|
||||
|
|
@ -165,14 +165,14 @@ public abstract class ContentBlock
|
|||
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."),
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ public sealed class ProgressNotificationParams : NotificationParams
|
|||
return new ProgressNotificationParams
|
||||
{
|
||||
ProgressToken = progressToken.GetValueOrDefault(),
|
||||
Progress = new ProgressNotificationValue()
|
||||
Progress = new ProgressNotificationValue
|
||||
{
|
||||
Progress = progress.GetValueOrDefault(),
|
||||
Total = total,
|
||||
|
|
|
|||
|
|
@ -421,14 +421,14 @@ internal sealed class AIFunctionMcpServerResource : McpServerResource
|
|||
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,
|
||||
|
|
@ -441,7 +441,7 @@ internal sealed class AIFunctionMcpServerResource : McpServerResource
|
|||
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -103,12 +103,12 @@ public static class McpServerExtensions
|
|||
{
|
||||
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(),
|
||||
|
|
@ -344,7 +344,7 @@ public static class McpServerExtensions
|
|||
|
||||
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),
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ public abstract class MapMcpTests(ITestOutputHelper testOutputHelper) : KestrelI
|
|||
// 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,
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ public partial class SseIntegrationTests(ITestOutputHelper outputHelper) : Kestr
|
|||
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",
|
||||
|
|
@ -222,7 +222,7 @@ public partial class SseIntegrationTests(ITestOutputHelper outputHelper) : Kestr
|
|||
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",
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class SseServerIntegrationTestFixture : IAsyncDisposable
|
|||
|
||||
public SseServerIntegrationTestFixture()
|
||||
{
|
||||
var socketsHttpHandler = new SocketsHttpHandler()
|
||||
var socketsHttpHandler = new SocketsHttpHandler
|
||||
{
|
||||
ConnectCallback = (context, token) =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ public class StreamableHttpClientConformanceTests(ITestOutputHelper outputHelper
|
|||
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),
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public class KestrelInMemoryTest : LoggedTest
|
|||
Builder.Services.AddSingleton<IConnectionListenerFactory>(_inMemoryTransport);
|
||||
Builder.Services.AddSingleton(XunitLoggerProvider);
|
||||
|
||||
HttpClient = new HttpClient(new SocketsHttpHandler()
|
||||
HttpClient = new HttpClient(new SocketsHttpHandler
|
||||
{
|
||||
ConnectCallback = (context, token) =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ internal static class Program
|
|||
|
||||
McpServerOptions options = new()
|
||||
{
|
||||
Capabilities = new ServerCapabilities()
|
||||
Capabilities = new ServerCapabilities
|
||||
{
|
||||
Tools = ConfigureTools(),
|
||||
Resources = ConfigureResources(),
|
||||
|
|
@ -75,7 +75,7 @@ internal static class Program
|
|||
if (_minimumLoggingLevel is not null)
|
||||
{
|
||||
var logLevel = loggingLevels[random.Next(loggingLevels.Length)];
|
||||
await server.SendMessageAsync(new JsonRpcNotification()
|
||||
await server.SendMessageAsync(new JsonRpcNotification
|
||||
{
|
||||
Method = NotificationMethods.LoggingMessageNotification,
|
||||
Params = JsonSerializer.SerializeToNode(new LoggingMessageNotificationParams
|
||||
|
|
@ -111,11 +111,11 @@ internal static 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.",
|
||||
|
|
@ -132,7 +132,7 @@ internal static class Program
|
|||
}
|
||||
"""),
|
||||
},
|
||||
new Tool()
|
||||
new Tool
|
||||
{
|
||||
Name = "echoSessionId",
|
||||
Description = "Echoes the session id back to the client.",
|
||||
|
|
@ -142,7 +142,7 @@ internal static class Program
|
|||
}
|
||||
""", McpJsonUtilities.DefaultOptions),
|
||||
},
|
||||
new Tool()
|
||||
new Tool
|
||||
{
|
||||
Name = "sampleLLM",
|
||||
Description = "Samples from an LLM using MCP's sampling feature.",
|
||||
|
|
@ -175,14 +175,14 @@ internal static 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 }]
|
||||
};
|
||||
|
|
@ -198,7 +198,7 @@ internal static class Program
|
|||
var sampleResult = await request.Server.SampleAsync(CreateRequestSamplingParams(prompt.ToString(), "sampleLLM", Convert.ToInt32(maxTokens.GetRawText())),
|
||||
cancellationToken);
|
||||
|
||||
return new CallToolResult()
|
||||
return new CallToolResult
|
||||
{
|
||||
Content = [new TextContentBlock { Text = $"LLM sampling result: {(sampleResult.Content as TextContentBlock)?.Text}" }]
|
||||
};
|
||||
|
|
@ -217,27 +217,27 @@ internal static 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",
|
||||
|
|
@ -254,7 +254,7 @@ internal static class Program
|
|||
List<PromptMessage> messages = [];
|
||||
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." },
|
||||
|
|
@ -264,20 +264,20 @@ internal static 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"
|
||||
|
|
@ -289,7 +289,7 @@ internal static class Program
|
|||
throw new McpException($"Unknown prompt: {request.Params?.Name}", McpErrorCode.InvalidParams);
|
||||
}
|
||||
|
||||
return new GetPromptResult()
|
||||
return new GetPromptResult
|
||||
{
|
||||
Messages = messages
|
||||
};
|
||||
|
|
@ -328,13 +328,13 @@ internal static 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",
|
||||
|
|
@ -344,13 +344,13 @@ internal static 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",
|
||||
|
|
@ -365,10 +365,10 @@ internal static 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",
|
||||
|
|
@ -400,7 +400,7 @@ internal static class Program
|
|||
{
|
||||
nextCursor = Convert.ToBase64String(Encoding.UTF8.GetBytes(endIndex.ToString()));
|
||||
}
|
||||
return new ListResourcesResult()
|
||||
return new ListResourcesResult
|
||||
{
|
||||
NextCursor = nextCursor,
|
||||
Resources = resources.GetRange(startIndex, endIndex - startIndex)
|
||||
|
|
@ -422,10 +422,10 @@ internal static 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",
|
||||
|
|
@ -438,7 +438,7 @@ internal static 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]
|
||||
};
|
||||
|
|
@ -523,9 +523,9 @@ internal static class Program
|
|||
|
||||
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}" },
|
||||
|
|
|
|||
|
|
@ -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
|
||||
};
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public partial class McpClientResourceTemplateTests : ClientServerTestBase
|
|||
protected override void ConfigureServices(ServiceCollection services, IMcpServerBuilder mcpServerBuilder)
|
||||
{
|
||||
mcpServerBuilder.WithReadResourceHandler((request, cancellationToken) =>
|
||||
new ValueTask<ReadResourceResult>(new ReadResourceResult()
|
||||
new ValueTask<ReadResourceResult>(new ReadResourceResult
|
||||
{
|
||||
Contents = [new TextResourceContents { Text = request.Params?.Uri ?? string.Empty }]
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ public partial class McpServerBuilderExtensionsPromptsTests : ClientServerTestBa
|
|||
case "FirstCustomPrompt":
|
||||
case "SecondCustomPrompt":
|
||||
case "FinalCustomPrompt":
|
||||
return new GetPromptResult()
|
||||
return new GetPromptResult
|
||||
{
|
||||
Messages = [new() { Role = Role.User, Content = new TextContentBlock { Text = $"hello from {request.Params.Name}" } }],
|
||||
};
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ public partial class McpServerBuilderExtensionsResourcesTests : ClientServerTest
|
|||
case "test://Resource3":
|
||||
case "test://ResourceTemplate1":
|
||||
case "test://ResourceTemplate2":
|
||||
return new ReadResourceResult()
|
||||
return new ReadResourceResult
|
||||
{
|
||||
Contents = [new TextResourceContents { Text = request.Params?.Uri ?? "(null)" }]
|
||||
};
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ public partial class McpServerBuilderExtensionsToolsTests : ClientServerTestBase
|
|||
case "FirstCustomTool":
|
||||
case "SecondCustomTool":
|
||||
case "FinalCustomTool":
|
||||
return new CallToolResult()
|
||||
return new CallToolResult
|
||||
{
|
||||
Content = [new TextContentBlock { Text = $"{request.Params.Name}Result" }],
|
||||
};
|
||||
|
|
@ -671,7 +671,7 @@ public partial class McpServerBuilderExtensionsToolsTests : ClientServerTestBase
|
|||
|
||||
await client.SendNotificationAsync(
|
||||
NotificationMethods.CancelledNotification,
|
||||
parameters: new CancelledNotificationParams()
|
||||
parameters: new CancelledNotificationParams
|
||||
{
|
||||
RequestId = requestId,
|
||||
},
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue