Audit protocol types (#892)

This commit is contained in:
Mackinnon Buck 2025-11-04 18:41:10 -05:00 • committed by GitHub
commit 121929da36
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 262 additions and 168 deletions

View file

@ -288,6 +288,7 @@ public abstract class MapMcpTests(ITestOutputHelper testOutputHelper) : KestrelI
Content = new TextContentBlock { Text = prompt },
}
],
MaxTokens = 1000
};
await server.SampleAsync(samplingRequest, cancellationToken);

View file

@ -201,7 +201,11 @@ public class StatelessServerTests(ITestOutputHelper outputHelper) : KestrelInMem
var requestSamplingEx = await Assert.ThrowsAsync<InvalidOperationException>(() => server.SampleAsync([]));
Assert.Equal(expectedSamplingErrorMessage, requestSamplingEx.Message);
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => server.SendRequestAsync(new JsonRpcRequest { Method = RequestMethods.SamplingCreateMessage }));
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => server.SendRequestAsync(new JsonRpcRequest
{
Id = default,
Method = RequestMethods.SamplingCreateMessage
}));
return ex.Message;
}
@ -216,7 +220,11 @@ public class StatelessServerTests(ITestOutputHelper outputHelper) : KestrelInMem
var requestRootsEx = Assert.Throws<InvalidOperationException>(() => server.RequestRootsAsync(new()));
Assert.Equal(expectedRootsErrorMessage, requestRootsEx.Message);
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => server.SendRequestAsync(new JsonRpcRequest { Method = RequestMethods.RootsList }));
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => server.SendRequestAsync(new JsonRpcRequest
{
Id = default,
Method = RequestMethods.RootsList
}));
return ex.Message;
}
@ -228,10 +236,14 @@ public class StatelessServerTests(ITestOutputHelper outputHelper) : KestrelInMem
// Even when the client has elicitation support, it should not be advertised in stateless mode.
Assert.Null(server.ClientCapabilities);
var requestElicitationEx = Assert.Throws<InvalidOperationException>(() => server.ElicitAsync(new()));
var requestElicitationEx = Assert.Throws<InvalidOperationException>(() => server.ElicitAsync(new() { Message = string.Empty }));
Assert.Equal(expectedElicitationErrorMessage, requestElicitationEx.Message);
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => server.SendRequestAsync(new JsonRpcRequest { Method = RequestMethods.ElicitationCreate }));
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => server.SendRequestAsync(new JsonRpcRequest
{
Id = default,
Method = RequestMethods.ElicitationCreate
}));
return ex.Message;
}

View file

@ -540,7 +540,7 @@ public class StreamableHttpServerConformanceTests(ITestOutputHelper outputHelper
SetSessionId(sessionId);
// Call the subscribe method to capture the McpServer instance.
using var response = await HttpClient.PostAsync("", JsonContent(Request("resources/subscribe")), TestContext.Current.CancellationToken);
using var response = await HttpClient.PostAsync("", JsonContent(SubscribeToResource("file:///test")), TestContext.Current.CancellationToken);
var rpcResponse = await AssertSingleSseResponseAsync(response);
AssertType<EmptyResult>(rpcResponse.Result);
Assert.NotNull(capturedServer);
@ -629,6 +629,11 @@ public class StreamableHttpServerConformanceTests(ITestOutputHelper outputHelper
{"name":"{{{toolName}}}","arguments":{{{arguments}}},"_meta":{"progressToken":"abc123"}}
""");
private string SubscribeToResource(string uri) =>
Request("resources/subscribe", $$"""
{"uri":"{{uri}}"}
""");
private static InitializeResult AssertServerInfo(JsonRpcResponse rpcResponse)
{
var initializeResult = AssertType<InitializeResult>(rpcResponse.Result);