Add more tests (#51)

* Add more tests

* Fix some code smells

* Remove more code smells

* Combine "ServerIntegrationTests" and "ClientIntegrationTests" because both are client integration tests just using different servers

* Clean up resources after test

* Improve kill logic for spawned child processes

* Improved testability for Stdio

* Fix SseIntegration tests
This commit is contained in:
Toni Wenzel 2025-03-12 18:55:52 +01:00 • committed by GitHub
commit b5076263d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -116,7 +116,7 @@ public static partial class McpServerBuilderExtensions
if (toolTypes.Count == 0)
throw new ArgumentException("No types with marked methods found in the assembly.", nameof(assembly));
return WithTools(builder, toolTypes.ToArray());
return WithTools(builder, [.. toolTypes]);
}
private static Tool CreateTool(MethodInfo method, McpToolAttribute mcpAttribute)
@ -187,7 +187,7 @@ public static partial class McpServerBuilderExtensions
BindingFlags.DoNotWrapExceptions |
#endif
BindingFlags.Default;
result = method.Invoke(objectInstance, InvokeFlags, binder: null, parameters.ToArray(), culture: null);
result = method.Invoke(objectInstance, InvokeFlags, binder: null, [.. parameters], culture: null);
}
catch (TargetInvocationException e) when (e.InnerException is not null)
{
@ -206,7 +206,7 @@ public static partial class McpServerBuilderExtensions
return new CallToolResponse { Content = [new Content() { Text = resultString, Type = "text" }] };
if (result is string[] resultStringArray)
return new CallToolResponse { Content = resultStringArray.Select(s => new Content() { Text = s, Type = "text" }).ToList() };
return new CallToolResponse { Content = [.. resultStringArray.Select(s => new Content() { Text = s, Type = "text" })] };
if (result is null)
return new CallToolResponse { Content = [new Content() { Text = "null" }] };