Skip to content

Fix enum serialization #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

zaevi
Copy link
Contributor

@zaevi zaevi commented Mar 22, 2025

Motivation and Context

Use JsonStringEnumMemberName for Role and LoggingLevel enum to ensure their serialization is lower-case.

Remove McpClientExtensions.ToJsonValue(LoggingLevel) since serializing issue is fixed.

How Has This Been Tested?

Tested in reproduction for #55.

Breaking Changes

N/A

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

N/A

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes enum serialization issues by replacing JsonPropertyName with JsonStringEnumMemberName for the Role and LoggingLevel enums to ensure their JSON output is in lower-case. It also removes the obsolete ToJsonValue extension method from the MCP client, simplifying the request creation for logging level changes.

  • Updated the Role enum to use JsonStringEnumMemberName.
  • Updated the LoggingLevel enum accordingly.
  • Removed the ToJsonValue method from McpClientExtensions and updated its usage.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/ModelContextProtocol/Protocol/Types/Role.cs Uses JsonStringEnumMemberName for lower-case serialization of Role.
src/ModelContextProtocol/Protocol/Types/LoggingLevel.cs Uses JsonStringEnumMemberName for each enum value for consistency.
src/ModelContextProtocol/Client/McpClientExtensions.cs Removes the obsolete ToJsonValue conversion in favor of direct enum usage.

Tip: Copilot code review supports C#, Go, Java, JavaScript, Markdown, Python, Ruby and TypeScript, with more languages coming soon. Learn more

@stephentoub
Copy link
Contributor

stephentoub commented Mar 22, 2025

Thanks. Can you please add tests?

@zaevi zaevi force-pushed the fix_enum_serialization branch from 5db3040 to b9964e2 Compare March 22, 2025 18:00
@zaevi
Copy link
Contributor Author

zaevi commented Mar 22, 2025

Added basic serialization tests for enums

@eiriktsarpalis eiriktsarpalis force-pushed the fix_enum_serialization branch from 1b0c65d to e729a1c Compare March 24, 2025 12:33
@eiriktsarpalis
Copy link
Contributor

Added the ContextInclusion enum in the mix since it was missing attributes altogether.

@eiriktsarpalis eiriktsarpalis merged commit 96ba2fa into modelcontextprotocol:main Mar 24, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PromptMessage Roles do not serialize with lowercase enum values
3 participants