Skip to content

Commit 137597a

Browse files
authored
Merge branch 'main' into dependabot/nuget/testing-frameworks-485962a2b3
2 parents 046554a + 5651e9e commit 137597a

84 files changed

Lines changed: 3316 additions & 489 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Directory.Packages.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<System8Version>8.0.22</System8Version>
55
<System9Version>9.0.11</System9Version>
66
<System10Version>10.0.3</System10Version>
7-
<MicrosoftExtensionsVersion>10.2.0</MicrosoftExtensionsVersion>
7+
<MicrosoftExtensionsVersion>10.3.0</MicrosoftExtensionsVersion>
88
</PropertyGroup>
99

1010
<!-- Product dependencies shared -->
@@ -87,7 +87,7 @@
8787
<PackageVersion Include="Serilog.Sinks.Console" Version="6.1.1" />
8888
<PackageVersion Include="Serilog.Sinks.Debug" Version="3.0.0" />
8989
<PackageVersion Include="Serilog.Sinks.File" Version="7.0.0" />
90-
<PackageVersion Include="Serilog" Version="4.3.0" />
90+
<PackageVersion Include="Serilog" Version="4.3.1" />
9191
<PackageVersion Include="System.Linq.AsyncEnumerable" Version="$(System10Version)" />
9292
<PackageVersion Include="xunit.v3" Version="3.2.2" />
9393
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5" />

src/ModelContextProtocol.AspNetCore/StreamableHttpHandler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ internal static void InitializeSseResponse(HttpContext context)
339339

340340
// Make sure we disable all response buffering for SSE.
341341
context.Response.Headers.ContentEncoding = "identity";
342+
context.Response.Headers["X-Accel-Buffering"] = "no";
342343
context.Features.GetRequiredFeature<IHttpResponseBodyFeature>().DisableBuffering();
343344
}
344345

src/ModelContextProtocol.Core/Client/McpClient.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ public abstract partial class McpClient : McpSession
3535
/// <remarks>
3636
/// <para>
3737
/// This property contains instructions provided by the server during initialization that explain
38-
/// how to effectively use its capabilities. These instructions can include details about available
39-
/// tools, expected input formats, limitations, or any other helpful information.
38+
/// how to effectively use its capabilities. They should focus on guidance that helps a model
39+
/// use the server effectively and should avoid duplicating tool, prompt, or resource descriptions.
4040
/// </para>
4141
/// <para>
42-
/// This can be used by clients to improve an LLM's understanding of available tools, prompts, and resources.
42+
/// This can be used by clients to improve an LLM's understanding of how to use the server.
4343
/// It can be thought of like a "hint" to the model and can be added to a system prompt.
4444
/// </para>
4545
/// </remarks>

src/ModelContextProtocol.Core/Protocol/CreateMessageRequestParams.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,38 @@ public sealed class CreateMessageRequestParams : RequestParams
3333
/// Gets or sets the maximum number of tokens to generate in the LLM response, as requested by the server.
3434
/// </summary>
3535
/// <remarks>
36+
/// <para>
3637
/// A token is generally a word or part of a word in the text. Setting this value helps control
3738
/// response length and computation time. The client can choose to sample fewer tokens than requested.
39+
/// </para>
40+
/// <para>
41+
/// The client must respect the <see cref="MaxTokens"/> parameter.
42+
/// </para>
3843
/// </remarks>
3944
[JsonPropertyName("maxTokens")]
4045
public required int MaxTokens { get; set; }
4146

4247
/// <summary>
4348
/// Gets or sets the messages requested by the server to be included in the prompt.
4449
/// </summary>
50+
/// <remarks>
51+
/// The list of messages in a sampling request should not be retained between separate requests.
52+
/// </remarks>
4553
[JsonPropertyName("messages")]
4654
public IList<SamplingMessage> Messages { get; set; } = [];
4755

4856
/// <summary>
4957
/// Gets or sets optional metadata to pass through to the LLM provider.
5058
/// </summary>
5159
/// <remarks>
60+
/// <para>
5261
/// The format of this metadata is provider-specific and can include model-specific settings or
5362
/// configuration that isn't covered by standard parameters. This allows for passing custom parameters
5463
/// that are specific to certain AI models or providers.
64+
/// </para>
65+
/// <para>
66+
/// The client may modify or ignore metadata.
67+
/// </para>
5568
/// </remarks>
5669
[JsonPropertyName("metadata")]
5770
public JsonElement? Metadata { get; set; }
@@ -90,6 +103,9 @@ public sealed class CreateMessageRequestParams : RequestParams
90103
/// sequence exactly matches one of the provided sequences. Common uses include ending markers like "END", punctuation
91104
/// like ".", or special delimiter sequences like "###".
92105
/// </para>
106+
/// <para>
107+
/// The client may modify or ignore stop sequences.
108+
/// </para>
93109
/// </remarks>
94110
[JsonPropertyName("stopSequences")]
95111
public IList<string>? StopSequences { get; set; }
@@ -106,18 +122,34 @@ public sealed class CreateMessageRequestParams : RequestParams
106122
/// <summary>
107123
/// Gets or sets the temperature to use for sampling, as requested by the server.
108124
/// </summary>
125+
/// <remarks>
126+
/// <para>
127+
/// Temperature controls randomness in model responses. Higher values produce higher randomness,
128+
/// and lower values produce more stable output. The valid range depends on the model provider.
129+
/// </para>
130+
/// <para>
131+
/// The client may modify or ignore this value.
132+
/// </para>
133+
/// </remarks>
109134
[JsonPropertyName("temperature")]
110135
public float? Temperature { get; set; }
111136

112137
/// <summary>
113138
/// Gets or sets tools that the model can use during generation.
114139
/// </summary>
140+
/// <remarks>
141+
/// The tool definitions in this array are scoped to this sampling request.
142+
/// They do not need to correspond to tools registered on the server via <see cref="RequestMethods.ToolsList"/>.
143+
/// </remarks>
115144
[JsonPropertyName("tools")]
116145
public IList<Tool>? Tools { get; set; }
117146

118147
/// <summary>
119148
/// Gets or sets controls for how the model uses tools.
120149
/// </summary>
150+
/// <remarks>
151+
/// This controls whether and how the model uses the request-scoped <see cref="Tools"/> during sampling.
152+
/// </remarks>
121153
[JsonPropertyName("toolChoice")]
122154
public ToolChoice? ToolChoice { get; set; }
123155

src/ModelContextProtocol.Core/Protocol/CreateMessageResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public sealed class CreateMessageResult : Result
4141
/// <remarks>
4242
/// Standard values include:
4343
/// <list type="bullet">
44-
/// <item><term>endTurn</term><description>The model naturally completed its response.</description></item>
44+
/// <item><term>endTurn</term><description>The participant is yielding the conversation to the other party.</description></item>
4545
/// <item><term>maxTokens</term><description>The response was truncated due to reaching token limits.</description></item>
4646
/// <item><term>stopSequence</term><description>A specific stop sequence was encountered during generation.</description></item>
4747
/// <item><term>toolUse</term><description>The model wants to use one or more tools.</description></item>

src/ModelContextProtocol.Core/Protocol/InitializeResult.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ public sealed class InitializeResult : Result
6565
/// </summary>
6666
/// <remarks>
6767
/// <para>
68-
/// These instructions provide guidance to clients on how to effectively use the server's capabilities.
69-
/// They can include details about available tools, expected input formats, limitations,
70-
/// or any other information that helps clients interact with the server properly.
68+
/// These instructions should focus on guidance that helps a model use the server effectively,
69+
/// such as workflow tips, capability relationships, and server-specific conventions.
70+
/// They should avoid repeating tool descriptions, prompt descriptions, or resource descriptions
71+
/// that are already available through other protocol responses.
7172
/// </para>
7273
/// <para>
7374
/// Client applications often use these instructions as system messages for LLM interactions

src/ModelContextProtocol.Core/Protocol/ReadResourceRequestParams.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,18 @@ namespace ModelContextProtocol.Protocol;
77
/// Represents the parameters used with a <see cref="RequestMethods.ResourcesRead"/> request from a client to get a resource provided by a server.
88
/// </summary>
99
/// <remarks>
10+
/// <para>
1011
/// The server will respond with a <see cref="ReadResourceResult"/> containing the resulting resource data.
12+
/// </para>
13+
/// <para>
14+
/// Alternatively, if the resource URI uses the <c>https://</c> scheme, clients may fetch the resource
15+
/// directly from the web instead of using <see cref="RequestMethods.ResourcesRead"/>.
16+
/// Servers should only use the <c>https://</c> scheme when the client is able to fetch and load the
17+
/// resource directly on its own.
18+
/// </para>
19+
/// <para>
1120
/// See the <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">schema</see> for details.
21+
/// </para>
1222
/// </remarks>
1323
public sealed class ReadResourceRequestParams : RequestParams
1424
{

src/ModelContextProtocol.Core/Server/McpServerOptions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ public sealed class McpServerOptions
5454
/// </summary>
5555
/// <remarks>
5656
/// These instructions are sent to clients during the initialization handshake and provide
57-
/// guidance on how to effectively use the server's capabilities. They can include details
58-
/// about available tools, expected input formats, limitations, or other helpful information.
57+
/// guidance on how to effectively use the server's capabilities. They should focus on
58+
/// information that helps models use the server effectively and should not duplicate
59+
/// tool, prompt, or resource descriptions already exposed elsewhere.
5960
/// Client applications typically use these instructions as system messages for LLM interactions
6061
/// to provide context about available functionality.
6162
/// </remarks>

tests/ModelContextProtocol.AspNetCore.Tests/ClientConformanceTests.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Diagnostics;
22
using System.Text;
3+
using System.Text.RegularExpressions;
34
using ModelContextProtocol.Tests.Utils;
45

56
namespace ModelContextProtocol.ConformanceTests;
@@ -118,10 +119,32 @@ public async Task RunConformanceTest(string scenario)
118119
);
119120
}
120121

122+
var output = outputBuilder.ToString();
123+
var error = errorBuilder.ToString();
124+
var success = process.ExitCode == 0 || HasOnlyWarnings(output, error);
125+
121126
return (
122-
Success: process.ExitCode == 0,
123-
Output: outputBuilder.ToString(),
124-
Error: errorBuilder.ToString()
127+
Success: success,
128+
Output: output,
129+
Error: error
125130
);
126131
}
132+
133+
/// <summary>
134+
/// Checks if the conformance test output indicates that all checks passed with only
135+
/// warnings (no actual failures). The conformance runner exits with code 1 for warnings,
136+
/// but warnings represent acceptable behavior (e.g., timing tolerances in CI environments).
137+
/// </summary>
138+
private static bool HasOnlyWarnings(string output, string error)
139+
{
140+
// The conformance runner outputs a summary line like:
141+
// "Passed: 2/2, 0 failed, 1 warnings"
142+
// If there are 0 failures but warnings > 0, the test behavior is acceptable.
143+
var combined = output + error;
144+
var match = Regex.Match(combined, @"(?<failed>\d+) failed, (?<warnings>\d+) warnings");
145+
return match.Success
146+
&& match.Groups["failed"].Value == "0"
147+
&& int.TryParse(match.Groups["warnings"].Value, out var warnings)
148+
&& warnings > 0;
149+
}
127150
}

tests/ModelContextProtocol.AspNetCore.Tests/SseServerIntegrationTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public async Task EventSourceResponse_Includes_ExpectedHeaders()
2626
Assert.NotNull(sseResponse.Headers.CacheControl);
2727
Assert.True(sseResponse.Headers.CacheControl.NoStore);
2828
Assert.True(sseResponse.Headers.CacheControl.NoCache);
29+
Assert.Equal("no", Assert.Single(sseResponse.Headers.GetValues("X-Accel-Buffering")));
2930
}
3031

3132
[Fact]

0 commit comments

Comments
 (0)