Skip to content

feat(core): add CEP-15 common schema helpers#37

Open
abhayguptas wants to merge 5 commits intoContextVM:masterfrom
abhayguptas:feat/cep-15-common-schema-helpers
Open

feat(core): add CEP-15 common schema helpers#37
abhayguptas wants to merge 5 commits intoContextVM:masterfrom
abhayguptas:feat/cep-15-common-schema-helpers

Conversation

@abhayguptas
Copy link
Copy Markdown

Summary

This PR adds the first CEP-15 implementation building blocks to the SDK.

It introduces helpers for schema normalization and deterministic common-schema hash generation, following the updated CEP-15 draft. The normalization logic recursively removes JSON Schema title and description fields before hashing, so providers with equivalent schemas but different documentation text can still produce the same schema hash.

Changes

  • add normalizeSchema() helper for CEP-15 schema normalization
  • add computeCommonSchemaHash() helper for deterministic schema hashing
  • export the new helpers through the core module
  • add focused unit tests covering normalization and hash behavior

Tests

  • bun test src/core/utils/common-schema.test.ts

Notes

This PR intentionally keeps the scope small and focused on the core compatibility primitives.

It does not yet:

  • inject _meta["io.contextvm/common-schema"].schemaHash into tools/list
  • add CEP-15 i / k discovery tags to 11317 announcement events
  • add transport-layer or end-to-end interoperability wiring

Those changes are planned for the next step once the normalization and hashing behavior is established.

@abhayguptas
Copy link
Copy Markdown
Author

Hi @ContextVM-org,

I started with a small first PR for CEP-15 that only covers the core compatibility primitives.

This PR adds schema normalization and schema-hash helpers, along with focused tests for the updated normalization rules in the CEP. The goal was to make sure the hashing behavior is clear and validated before moving on to transport-layer integration such as injecting _meta.schemaHash into tools/list responses and adding discovery tags to 11317 announcement events.

Focused tests are passing locally. The next step I am planning is to wire these helpers into the server transport/announcement flow.

Copy link
Copy Markdown
Contributor

@ContextVM-org ContextVM-org left a comment

Choose a reason for hiding this comment

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

Looks good, but the current implementation needs a few changes to stay consistent with upstream. We just merged #35 and are already using noble‑hashes there. We also need an RFC 8785 compliant library (or reimplement it ourselves) to canonicalize JSON schemas before hashing.

So far, the best candidates are:

Let’s choose the one you think is best. ‘canonicalize’ appears more lightweight.

Comment thread src/core/utils/common-schema.ts Outdated
Comment thread src/core/utils/common-schema.ts Outdated
@abhayguptas
Copy link
Copy Markdown
Author

Thanks, I updated the CEP-15 helper implementation to align with upstream.

I chose canonicalize over json-canonicalize for two main reasons. First, it is a smaller and more focused dependency for our use case. Second, its package is directly positioned around RFC 8785 / JCS canonicalization, while json-canonicalize documents some differences in its default canonicalize() behavior and recommends canonicalizeEx(...) for full RFC-compatible behavior. Since we only need straightforward RFC 8785 canonicalization before hashing, canonicalize felt like the safer and simpler fit.

I also replaced Node crypto with @noble/hashes to stay consistent with the rest of the SDK, and I narrowed the schema fields from broad unknown types to MCP Tool field types as suggested.

Current changes in this update:

  • use canonicalize for RFC 8785 canonicalization
  • use @noble/hashes instead of crypto
  • narrow inputSchema / outputSchema types using MCP Tool
  • keep the CEP-15 helper tests passing

Verification:

  • bun test src/core/utils/common-schema.test.ts
  • bun run typecheck

Copy link
Copy Markdown
Contributor

@ContextVM-org ContextVM-org 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 about redundant interfaces and types.

Comment thread src/core/utils/common-schema.ts Outdated
Comment thread src/core/utils/common-schema.ts Outdated
Comment thread src/core/utils/common-schema.ts
@abhayguptas
Copy link
Copy Markdown
Author

cc @ContextVM-org

@abhayguptas abhayguptas force-pushed the feat/cep-15-common-schema-helpers branch 2 times, most recently from b3b5f0a to c378208 Compare May 2, 2026 05:41
@abhayguptas abhayguptas force-pushed the feat/cep-15-common-schema-helpers branch from c378208 to 06dfd3f Compare May 2, 2026 05:58
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.

2 participants