-
Notifications
You must be signed in to change notification settings - Fork 273
Fix enum schema generation to use string values instead of numeric values #248
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
Conversation
…lues Co-authored-by: nikolapeja6 <[email protected]>
@nikolapeja6 this looks good, but we must resolve the conflicts. Also, I think that it doesn't necessarily handle all cases of enums we already have. In some places, we explicitly define strings which is not great, and that should be chnged to. In different, we do this correctly much like we do this in utils, but we didn't update the code to reuse the same logic. Let's fix that. |
- Updated repos.ts to use PullRequestStatus enum with getEnumKeys() - Updated workitems.ts to use Operation enum for patch operations - Updated workitems.ts to use QueryExpand enum for query expansion - Added conversion functions to handle enum value transformations - All enum schemas now generate string types instead of numeric types - Updated handlers to properly convert enum values for API calls Co-authored-by: kboom <[email protected]>
✅ Done! I've resolved the merge conflicts and replaced hardcoded string enums with proper Azure DevOps API enums: Merge conflicts resolved:
Enum standardization completed:
All enum schemas now consistently generate string types using the Commit: 6e1737f |
Co-authored-by: kboom <[email protected]>
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
… array Co-authored-by: nikolapeja6 <[email protected]>
PR is ready to be merged - @microsoft/azure-devops-mcp-maintainers please approve. |
… undefined values - Added safeEnumConvert utility function to validate enum keys before conversion - Updated all enum conversions in builds.ts and releases.ts to use safe validation - Fixed test cases to use correct string enum keys instead of numeric values - Ensures API calls receive valid enum values or undefined instead of accessing invalid keys Co-authored-by: aaudzei <[email protected]>
Co-authored-by: aaudzei <[email protected]>
test/src/tools/builds.test.ts
Outdated
buildId: 123, | ||
stageName: "Build", | ||
status: StageUpdateType.Retry, | ||
status: "Retry" as keyof typeof StageUpdateType, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot , handler accepts status: string
. There is no need for type casting.
Apply to the rest of changes in this file as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed unnecessary type casting from all instances of status
parameter in the builds test file. The handler accepts status: string
so no type casting to keyof typeof StageUpdateType
is needed.
Commit: 944fd41
Co-authored-by: aaudzei <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.slice(0, top); | ||
} | ||
|
||
function pullRequestStatusStringToInt(status: string): number { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we do this automatically? Do we really have to enumerate all of enums values?
Problem
When using the Azure DevOps MCP server, enum parameters in tool function declarations were generating numeric values (e.g.,
0, 1, 2
) in the JSON schema, but the MCP API expects string representations (e.g.,"None", "LastModifiedAscending", "LastModifiedDescending"
).This resulted in API errors like:
The issue affected several tools including:
build_get_definitions
(queryOrder parameter)build_get_builds
(queryOrder parameter)build_update_build_stage
(status parameter)release_get_definitions
(expand, queryOrder parameters)release_get_releases
(statusFilter, queryOrder, expand parameters)Root Cause
The issue was caused by using
z.nativeEnum()
with TypeScript numeric enums from theazure-devops-node-api
package. Whenzod-to-json-schema
processesz.nativeEnum()
, it generates:But the MCP protocol expects:
Solution
getEnumKeys()
inutils.ts
to extract string keys from TypeScript numeric enumsbuilds.ts
andreleases.ts
to usez.enum(getEnumKeys(EnumType))
instead ofz.nativeEnum(EnumType)
Changes
Files Modified:
src/utils.ts
- AddedgetEnumKeys()
utility functionsrc/tools/builds.ts
- Replaced 3 instances ofz.nativeEnum()
with string-based enumssrc/tools/releases.ts
- Replaced 5 instances ofz.nativeEnum()
with string-based enumstest/src/tools/builds.test.ts
- Updated tests to use string enum valuestest/src/enum-schema.test.ts
- Added comprehensive enum schema validation testsBefore/After Comparison:
Before (generates numeric schema):
After (generates string schema):
The tool handlers now properly convert string values back to numeric for API calls:
Testing
"type": "string"
instead of"type": "number"
Fixes #183
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.