Skip to content

Add type compatibility test between SDK and spec types #729

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

ochafik
Copy link
Contributor

@ochafik ochafik commented Jul 3, 2025

Test that the TS SDK types are in sync w/ the Spec types

Note: ModelHint, ModelPreferences, Annotations are not in the SDK yet, incubating them in a63aeeb

Motivation and Context

#727 cc/ @ihrpr

How Has This Been Tested?

  • Checked that npm run test failes w/ human-readable message before Rename reject to decline #727

    CleanShot 2025-07-03 at 21 23 01@2x

  • Did spot tests of editing either the sdk types or the spec types, e.g. switching fields between optional & required, renaming, altering strings

Breaking Changes

None

Types of changes

  • Test
  • 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

Types in the TS SDK are derived from Zod schemas, while the ones in the specs are written by hand. This causes a few type discrepancies, which are temptatively ironed out using ham-handed type mappings:

  • ZodObject.passthrough() feature introduces {[key: string]: unknown} passthroughs: we undo this w/ RemovePassthrough<T>
  • Fields w/ z.unknown() are treated as optional; we undo this w/ MakeUnknownsNotOptional<T>, with the exception of _meta fields
@ochafik ochafik marked this pull request as ready for review July 3, 2025 20:13
@ochafik ochafik requested review from ihrpr and dsp-ant July 3, 2025 20:24
@ihrpr ihrpr mentioned this pull request Jul 7, 2025
9 tasks
Copy link
Contributor

@ihrpr ihrpr left a comment

Choose a reason for hiding this comment

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

some comments after a quick scan , will review today/tomorrow

}
function checkResourceReference(
sdk: RemovePassthrough<SDKTypes.ResourceReference>,
spec: SpecTypes.ResourceTemplateReference
Copy link
Contributor

Choose a reason for hiding this comment

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

should it be resource? (SpecTypes.ResourceReference)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh good catch! Actually ResourceReference now only exists in the SDK and is aliased to ResourceTemplateReference, which is already tested. Removed checkResourceReference

.gitignore Outdated
@@ -69,6 +69,9 @@ web_modules/
# Output of 'npm pack'
*.tgz

# Output of 'npm run fetch:spec-types'
src/spec.types.ts
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a way to do it without creating a file in src?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point thx, moved it to top-level which is only marginally better. Happy to create another tmp dir if you think it's cleaner (dist seems a no-go)

Copy link
Contributor Author

@ochafik ochafik left a comment

Choose a reason for hiding this comment

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

Thanks!!

.gitignore Outdated
@@ -69,6 +69,9 @@ web_modules/
# Output of 'npm pack'
*.tgz

# Output of 'npm run fetch:spec-types'
src/spec.types.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point thx, moved it to top-level which is only marginally better. Happy to create another tmp dir if you think it's cleaner (dist seems a no-go)

}
function checkResourceReference(
sdk: RemovePassthrough<SDKTypes.ResourceReference>,
spec: SpecTypes.ResourceTemplateReference
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh good catch! Actually ResourceReference now only exists in the SDK and is aliased to ResourceTemplateReference, which is already tested. Removed checkResourceReference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants