[WIP] Upgrade MCP C# SDK to 1.2.0 for host extension#224
Draft
liliankasem wants to merge 3 commits intomainfrom
Draft
[WIP] Upgrade MCP C# SDK to 1.2.0 for host extension#224liliankasem wants to merge 3 commits intomainfrom
liliankasem wants to merge 3 commits intomainfrom
Conversation
Upgrade ModelContextProtocol from 0.4.0-preview.3 to 1.2.0 and System.Net.ServerSentEvents from 10.0.0 to 10.0.5 in the host extension (Extensions.Mcp) project. Changes: - StreamableHttpTransport: rewrite for init-only SDK properties - StreamableHttpRequestHandler: update session creation methods - ToolReturnValueBinder: StructuredContent JsonNode? -> JsonElement? - ResourceReturnValueBinder: use BlobResourceContents.FromBytes() - ToolInvocationContext: Arguments IReadOnlyDictionary -> IDictionary - PromptInvocationContext: Arguments IReadOnlyDictionary -> IDictionary - Test helpers: suppress MCPEXP002, use 3-arg RequestContext ctor - Test assertions: serialize via base types for polymorphic converters Part 1 of #222 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
SDK 1.2.0 made StreamableHttpServerTransport.SessionId init-only but still readable. The previous change introduced a local _sessionId field that shadowed Transport.SessionId, creating a divergence risk. Since nothing mutates SessionId after construction, remove the local field, delegate the getter to Transport.SessionId (single source of truth), and throw on the setter to make init-only semantics explicit — matching the pattern already used by SseStreamTransport. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… 3-arg RequestContext, fix release notes - Restore InvalidOperationException guard in DeserializeToStructuredContent for JSON null input (JsonElement.ValueKind check replaces the old ?? throw pattern that doesn't work with value types) - Migrate all test helpers from obsolete 2-arg RequestContext constructor to the 3-arg overload, removing all MCP9003 pragma suppressions - Fix release notes PR reference from #222 to #224 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Upgrade ModelContextProtocol from 0.4.0-preview.3 to 1.2.0 and System.Net.ServerSentEvents from 10.0.0 to 10.0.5 in the host extension (Extensions.Mcp) project.
StreamableHttpTransport rewrite
SDK 1.2.0 made all StreamableHttpServerTransport properties init-only (SessionId, Stateless,
OnSessionInitialized). We can no longer set them post-construction, so all config moved into
the constructor and object initializer. We also keep a local _sessionId field because our
wrapper needs a mutable SessionId while the SDK's is immutable after init.
OnInitRequestReceived → OnSessionInitialized
The old callback was removed. The replacement has a different signature (non-nullable
InitializeRequestParams, added CancellationToken). Since it's also init-only, we pass it
through the constructor instead of the old setter pattern.
IsStateless vs Stateless
These are two separate properties on different layers — Stateless on the SDK transport
(init-only), IsStateless on our McpExtensionTransport wrapper (used by our session management).
Both must be set; not redundant.
ToolInvocationContext.Arguments: IReadOnlyDictionary → IDictionary
The SDK changed CallToolRequestParams.Arguments to IDictionary. Our property is assigned
directly from it, so types need to match. All consumers only read from it.
Serialization: must use base types
The critical discovery: ReadOnlyMemory properties (Data, Blob) must be
serialized/deserialized via base types (ContentBlock, ResourceContents), not concrete types (
ImageContentBlock, BlobResourceContents). The MCP SDK's custom polymorphic converter only
activates through the base type. Direct concrete type serialization uses STJ's default base64
converter, causing double base64 encoding. This was the root cause of all remaining test
failures.
Other type changes
Encoding.UTF8.GetBytes(base64String))
10.0.5 to fix NuGet downgrade error
Issue describing the changes in this PR
resolves #221
Pull request checklist
release_notes.mdAdditional information
Additional PR information