Skip to content

feat(deps): make chrono optional behind a default feature - #1474

Open
andreinknv wants to merge 2 commits into
modelcontextprotocol:mainfrom
andreinknv:chrono-optional
Open

andreinknv wants to merge 2 commits into
modelcontextprotocol:mainfrom
andreinknv:chrono-optional

Conversation

@andreinknv

@andreinknv andreinknv commented Nov 18, 2026 •

Copy link
Copy Markdown

Closes #1469.

Discussed in #1469. A downstream test there confirms that chrono drops out of the dependency tree and cargo deny check advisories passes without an ignore.

Motivation

chrono is marked unmaintained (RUSTSEC-2026-0543). rmcp depends on it unconditionally, so downstream cargo deny / cargo audit runs fail on it.

Changes

  • The clock, the RFC 3339 timestamps in tasks and Annotations::with_timestamp_now, and the ServiceError::Timeout message now use jiff 1 (default-features = false, features = ["std"]) and a small private time module. Output is unchanged: +00:00 offset, 0/3/6/9 fractional digits, and PT30S / PT1.5S / P0D.
  • New default feature chrono. It keeps Annotations::for_resource and Annotations::with_timestamp (which take chrono::DateTime<Utc>) and enables schemars?/chrono04.
  • The tests that used chrono directly now use jiff.
  • The crate README has a "Building without chrono" section with the default-features = false snippet.

Compatibility

Nothing changes with default features. cargo semver-checks reports "no semver update required" for default features and for all features except local. With default-features = false, rmcp no longer depends on chrono, except through oauth2 5 when an auth feature is enabled.

wasm32-unknown-unknown behaves as before. chrono (as configured since #234) and jiff both read the clock through std::time::SystemTime::now(), which panics on that target, and neither pulls in js-sys. A browser build that wants a working clock can enable jiff's js feature; before, the equivalent was chrono's wasmbind.

Tests

  • New unit tests pin the timestamp and duration text against chrono's previous output, including the full ServiceError::Timeout message.
  • cargo test --all-features: 1213 passed. cargo test -p rmcp --lib --no-default-features: 208 passed.
  • Clippy -D warnings with all features, with all features except local, and with 8 smaller feature sets, including none. Nightly fmt, nightly docs with --cfg docsrs -Dwarnings, and cargo +1.88.0 check --all-targets --all-features all pass.
  • wasm, on main and on this branch: a probe that calls Annotations::with_timestamp_now traps on wasm32-unknown-unknown exactly like a direct SystemTime::now() call, with no imports in the module; on wasm32-wasip1 both print the same timestamp format; examples/wasi builds for wasm32-wasip2.

Follow-up plan

  1. Add a setter that needs no chrono, for example Annotations::with_last_modified taking an RFC 3339 string or a jiff::Timestamp.
  2. In a later minor release, deprecate Annotations::for_resource and Annotations::with_timestamp, pointing at that setter.
  3. In the next major release, remove chrono from the default features.

AI assistance: I used an AI coding assistant (Claude Code) to write most of this change and draft this text; I reviewed and tested it.

🤖 Generated with Claude Code

chrono is marked unmaintained by RUSTSEC-2026-0543. Use jiff for the clock and the
RFC 3339 task and annotation timestamps, keeping the exact previous output
(`+00:00` offset, 0/3/6/9 fractional digits), and format the request timeout
message without chrono (`PT30S`, `P0D`).

The new default `chrono` feature keeps `Annotations::for_resource` and
`Annotations::with_timestamp` (which take `chrono::DateTime<Utc>`) and schemars'
`chrono04` support. With default features disabled, rmcp no longer depends on
chrono unless an `auth` feature pulls it in through oauth2.
@andreinknv
andreinknv requested a review from a team as a code owner November 18, 2026 13:04
@github-actions github-actions Bot added T-documentation Documentation improvements T-test Testing related changes T-config Configuration file changes T-core Core library changes T-model Model/data structure changes labels Nov 18, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T13:32:39.940858Z 9043cdf New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown
Contributor

@michaelneale is on triage rotation this week and is the reviewer for this one.

Labels come from the PR labeler. Please review the change.

Automated triage. Labels are a first pass and the assigned maintainer has the final say.

@jokemanfire jokemanfire left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verified at a95b804 from the code and a local A/B run, not the description.

What I ran (Linux, stable 1.96; Windows and MSRV not run here)

  • A scratch example (not committed) that formats the same values both ways: chrono::DateTime::to_rfc3339() vs Annotations::with_timestamp(..).last_modified, and format!("request timeout after {}", chrono::Duration::from_std(d).unwrap_or_default()) vs ServiceError::Timeout{d}.to_string().
  • 14 timestamps: seconds 0, pre-epoch (-1s + 500ms), 2099, and every fractional shape (1ns, 1µs, 1ms, 100ms, 123ms, 123456µs, 123456789ns, 999999999ns).
  • 12 durations: zero, 1ns, 1µs, 1ms, 1.5s, 30s, 5400s, 86400s, i64::MAX ms exactly, one nanosecond past it, and Duration::MAX.
  • Result: 26/26 identical, including the 0/3/6/9 fractional-digit rule, the +00:00 offset, and the overflow quirk where chrono::Duration::from_std fails and unwrap_or_default() prints P0D — your too_long branch reproduces that exactly.
  • cargo tree -p rmcp -i chrono: default features → chrono v0.4.40 (direct, plus through schemars 1.2.3); --no-default-features --features server,macros → not in the tree at all. Your opt-out claim holds.

Code read

  • time::rfc3339 is only reachable from now_rfc3339, so the sign of subsec_nanosecond() for pre-epoch values never reaches it; the digit selection matches SecondsFormat::AutoSi. The #[cfg(any(client, server))] on Iso8601Duration matches where ServiceError::Timeout exists.
  • with_timestamp_now no longer routes through with_timestamp, which is what keeps it available without the chrono feature — correct, since with_timestamp keeps using chrono's own to_rfc3339 and the two agree (probe above).

Two things worth settling before merge

  1. Default users still trip the advisory. chrono is in default, so cargo tree -i chrono still shows it for anyone who does not add default-features = false. That is fine as a staged change, but it means the people who filed #1469 (plain rmcp = "3") see no difference in cargo deny check advisories, and the opt-out is not documented anywhere a downstream would look. I would like the README and CHANGELOG to carry the exact snippet (default-features = false plus the feature list they actually need) and one line on the plan to flip the default at the next major. Right now the README change is one line and does not say this.

  2. The flip is a hard API break, and the migration path is invisible. With the feature off, Annotations::for_resource and with_timestamp vanish; at the flip every caller panics at compile time with no replacement that accepts a timestamp. Cheap way to make the eventual break a non-event: add an untyped with_last_modified_rfc3339(&str) (or a jiff-typed setter) now so non-chrono users have a supported path, and #[deprecated(note = "…")] on the chrono setters in a later release before the default changes. Not required for this PR, but it should be in the PR body as the follow-up plan.

Question: which wasm targets did you verify?

jiff's docs for Timestamp::now() say it "may also panic when SystemTime::now() itself panics. The most common context in which this happens is on the wasm32-unknown-unknown target… you should enable Jiff's js feature". This PR deletes the two target-specific chrono blocks, and CHANGELOG.md:1087 records #234 as "disable wasmbind in chrono for wasm32-unknown-unknown", so that target has been deliberately configured before. I read the old config as panicking the same way (no wasmbind), i.e. parity, but I did not build for wasm32-unknown-unknown to prove it — CI only builds examples/wasi for wasm32-wasip2, which has a real clock. One sentence in the PR body saying "wasm32-unknown-unknown behaves as before / now needs jiff/js" would close it.

None of this blocks the dependency change itself, which I could not fault: the formatting is byte-identical on everything I threw at it and the feature wiring does what it says.

Show the `default-features = false` snippet, what is unavailable without the `chrono`
feature, that the `auth` features still pull chrono in through oauth2, and the plan to
drop `chrono` from the default features in the next major release.
@andreinknv

Copy link
Copy Markdown
Author

Thanks for checking it so thoroughly.

1. Docs. 9043cdf adds a "Building without chrono" section to the crate README, which is also the crate-level rustdoc. It covers the default-features = false snippet, what goes away without chrono, the auth/oauth2 caveat, cargo tree -i chrono, and the plan for the next major. cargo tree finds no chrono with the snippet's feature set, and the nightly docs build passes with --cfg docsrs -Dwarnings.

I left CHANGELOG.md alone because release-plz writes it in the release PR; every commit that touches it is a chore: release. The entry will come from this PR's title. For the release PR, a note could read:

With the new default chrono feature turned off, rmcp no longer depends on chrono (except through oauth2 for the auth features). See "Building without chrono" in the README.

If you'd rather have it under [Unreleased] in this PR, I'll add it.

2. Migration path. It's now in the PR body as a follow-up plan: a setter that needs no chrono, then deprecating the chrono setters in a later minor, then flipping the default at the next major. I can add the setter in this PR if you'd prefer it now.

3. wasm. wasm32-unknown-unknown behaves as before. I built a small cdylib probe against main (3.11.0) and against this branch. It calls Annotations::default().with_timestamp_now(), plus std::time::SystemTime::now() directly as a control, and I ran it in Node:

  • main (chrono 0.4.45) and this branch (jiff 1.0.1, with and without the chrono feature): the module has no imports, so no js-sys. The probe and the control both trap with unreachable, so the clock panics the same way it did before.
  • wasm32-wasip1 under Node's WASI: both versions print a timestamp in the same format, for example 2026-11-18T13:25:46.986149+00:00.
  • examples/wasi builds for wasm32-wasip2, as in CI.

With rmcp's default features, wasm32-unknown-unknown doesn't compile on either main or this branch, because uuid needs a randomness source there. That hasn't changed. I added a sentence on wasm to the PR body.

AI assistance: I used an AI coding assistant (Claude Code) to run these checks and draft this reply; I reviewed the results.

🤖 Generated with Claude Code

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-config Configuration file changes T-core Core library changes T-documentation Documentation improvements T-model Model/data structure changes T-test Testing related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chrono is flagged unmaintained (RUSTSEC-2026-0543): any plan to move to jiff/time or make it optional?

2 participants