-
Notifications
You must be signed in to change notification settings - Fork 174
chore: support schema overrides and custom parserOptions MCP-338 #800
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
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.
Pull request overview
This PR renames createUserConfig to parseUserConfig and adds support for schema overrides and custom parser options. The changes enable more flexible configuration parsing, including custom environment variable prefixes and default value overrides.
Key changes:
- Renamed
createUserConfigtoparseUserConfigthroughout the codebase - Added support for schema overrides through a new
overridesparameter - Exposed
ParserOptionstype anddefaultParserOptionsfor customization - Updated public API exports to reflect the new naming
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/common/config/createUserConfig.ts | Renamed to parseUserConfig.ts; added overrides and parserOptions parameters to support custom schemas and parser configuration |
| tests/unit/common/config.test.ts | Updated all test calls from createUserConfig to parseUserConfig; added tests for schema overrides and custom environment prefixes |
| src/lib.ts | Updated exports to expose parseUserConfig, defaultParserOptions, and ParserOptions type instead of parseCliArgumentsAsUserConfig |
| src/index.ts | Updated import to use parseUserConfig instead of createUserConfig |
| src/transports/base.ts | Updated documentation comments to reference parseUserConfig instead of createUserConfig |
| eslint-rules/enforce-zod-v4.js | Updated allowed file path from createUserConfig.ts to parseUserConfig.ts |
| MCP_SERVER_LIBRARY.md | Updated documentation to reflect parseUserConfig naming and simplified function signature |
| export { Server, type ServerOptions } from "./server.js"; | ||
| export { Session, type SessionOptions } from "./common/session.js"; | ||
| export { type UserConfig, UserConfigSchema } from "./common/config/userConfig.js"; | ||
| export { createUserConfig as parseCliArgumentsAsUserConfig } from "./common/config/createUserConfig.js"; |
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.
so I unfortunately missed that we're doing this; it's weird to have this discrepancy where our external export is named differently than our internal one. To me the idea that the name isn't straightforward was a code smell.
parseCliArgumentsAsUserConfig is inherently misleading though since by default it also parses environment variables. This can mislead users so it's best to rename it.
It is technically a library breaking change though.
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.
Then we anticipate the release with this work will bump major version, correct?
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.
Technically, yes, though to avoid a major version bump, let's re-export with the old name and mark as deprecated?
Pull Request Test Coverage Report for Build 20275512293Details
💛 - Coveralls |
| ```typescript | ||
| function parseCliArgumentsAsUserConfig(options?: { | ||
| args?: string[]; | ||
| helpers?: CreateUserConfigHelpers; |
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.
the concept of CreateUserConfigHelpers was unused.
cveticm
left a comment
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.
LGTM + non-blocking questions for my own understanding
| error: string | undefined; | ||
| } { | ||
| const { error: parseError, warnings, parsed } = parseUserConfigSources(args); | ||
| const schema = overrides |
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.
Non-blocking q: Which takes precedent: env vars or overrides?
I suspect env vars are applied to the UserConfiSchema before we get to this point and so overrides take precedent.
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.
generally overrides are applied to the schema and in practice likely only going to be used to modify the default, i.e.
{
readOnly: UserConfigSchema.shape.readOnly.default(true)
}so any value (CLI, ENV) will override the default.
I will add some documentation to make it clearer
This allows for more flexibility when parsing, including specifying custom defaults, environment prefixes, etc..