Context for coding agents working in keycardai/java-sdk. CLAUDE.md points here.
The Keycard Java SDK: a Gradle multi-module build (Kotlin DSL) publishing to Maven Central under group ai.keycard. Every module releases together under one lockstep version (version= in gradle.properties).
| Module | Package | What it is | Depends on |
|---|---|---|---|
keycard-oauth |
ai.keycard.oauth |
OAuth 2.0 for Keycard zones: token exchange, client credentials, auth code + PKCE, device grant, DCR, discovery, UserInfo, credentials, JWT/JWKS verification, AccessContext. Only runtime dep: Nimbus JOSE + JWT. | none |
keycard-spiffe |
ai.keycard.spiffe |
SPIFFE JWT-SVID workload identity source (Preview). Separate so keycard-oauth never pulls in gRPC. |
oauth |
keycard-mcp |
ai.keycard.mcp |
MCP server auth on Jakarta Servlet 6.0: bearer filter, metadata servlets, grant filter. Servlet API is compileOnlyApi, rewritten to provided in the POM. |
oauth |
keycard-spring-boot-starter |
ai.keycard.spring.boot |
Spring Boot 4 auto-configuration on Spring Security's resource server, @KeycardGrant |
mcp |
keycard-a2a |
ai.keycard.a2a |
Agent-to-agent delegation over A2A 1.0 | oauth |
keycard-bom |
java-platform BOM pinning every module to one version |
all |
- Dependency direction: everything builds on
keycard-oauth. Keep its runtime deps to Nimbus only (no Jackson; seedocs/idiom-profile.md, JSON). - New modules must be added to
settings.gradle.ktsand tokeycard-bom's constraints. build-logic/holds the convention plugins every module applies instead of configuring itself:keycard.java-library:--release 17,-Xlint:all -Werror -parameters, Javadoc-Xdoclint:all -Werror, JSpecify asapi, JUnit Jupiter + AssertJ for tests, Spotless with palantir-java-format,Automatic-Module-Name=ai.keycard.<module>, LICENSE in every jar.keycard.publishing:com.vanniktech.maven.publishto Central, POM metadata, signing only whensigningInMemoryKeyis set.
- Versions live in
gradle/libs.versions.toml.settings.gradle.ktssetsFAIL_ON_PROJECT_REPOS, so do not add repositories in module builds. examples/(mcp-server-servlet,mcp-server-spring-ai,a2a-delegation) are separate Gradle builds that consume the SDK from source viaincludeBuild("../..").- Design reference:
docs/idiom-profile.md(how the shared contract maps to Java, with reasons),docs/conformance-report.md,docs/releasing.md.
JDK 17 or newer. Always use the wrapper.
./gradlew build publishToMavenLocal --console=plain # compile, tests, Javadoc, spotlessCheck, every module
examples/mcp-server-servlet/bin/selftest
examples/a2a-delegation/bin/selftest
examples/mcp-server-spring-ai/bin/selftest- CI (
.github/workflows/ci.yml) runs the above on Temurin 17, 21 and 25. Bytecode is always--release 17, so do not use APIs newer than 17. - Format before pushing:
./gradlew spotlessApply(buildfails onspotlessCheck). - Warnings are errors, including Javadoc. Every public type and member needs Javadoc.
- Release script job, Python 3.12 and
pip install commitizen==4.19.2:python3 -m unittest discover -s scripts -p 'test_*.py' -vpython3 scripts/changelog.py check-drift(.cz.tomlvsgradle.properties)- on PRs:
python3 scripts/changelog.py validate "origin/<base>"andcz check --message "<PR title>"
From .cz.toml and docs/releasing.md:
- Accepted types (
schema_pattern):feat,fix,refactor,perf,build,revert,docs,chore,style,test,ci(andbump, the release app's subject). - Scope is free-form or omitted (
feat(oauth):,fix(mcp,spring):,test(examples):): every module ships together, so the scope only documents what changed. - Releasable:
feat(minor),fix,refactor,perf,build,revert(patch).docs,chore,style,test,cinever cut a release. - Breaking:
!before the colon or aBREAKING CHANGE:footer. Whilemajor_version_zero = truea major lands as a minor. - PRs are squash-merged, so the PR title becomes the commit subject on
mainand decides the release. CI checks the title and re-checks on edit. - Flow: merge to
mainrunsmain.yml, which callsbump-package.yml(scripts/bump_package.py). The release app opens and merges a bump PR and tagsv<version>;release.ymlpublishes every module to Central. - Never hand-edit the version in
gradle.properties,.cz.tomlor the README install snippets, orCHANGELOG.md.cz bumpowns them andcheck-driftfails CI on a mismatch.
- Behavior shared across the Keycard SDKs is defined in
keycardai/keycard-sdk-spec. A contract change starts as a spec PR there, then is implemented here against that spec's Unit Tests rows. - Conformance tests are named for the spec row they implement (
@DisplayName("row 4: ...")), so a reviewer can diff a suite against its spec table. Keep that naming; extra Java-specific tests carry no row number.
- Module tests are hermetic: they run against
StubZone, an in-process authorization server on the JDKHttpServer, inkeycard-oauth/src/testFixtures. Other modules use it viatestImplementation(testFixtures(project(":keycard-oauth"))). Test fixtures are excluded from published artifacts. - No WireMock or MockWebServer; keep the test classpath as small as the runtime one.
- The
bin/selftestscripts are hermetic end-to-end checks against a stub zone, run in CI. - Live coverage against real zones belongs to the eval in
keycardai/templates.
See docs/idiom-profile.md for the full table. Short form:
- Sync and blocking API, thread-safe internals. No
CompletableFuturetwins. - Builders for anything with optional inputs, static factories for small required-only types, records for values.
- Unchecked exceptions rooted at
KeycardException;retryable()is computed at construction. java.timetypes and an injectableClock(andSleeperfor waits);Optionalonly on return values.- JSpecify
@NullMarkedpackages. - HTTP through
java.net.http.HttpClientbehindKeycardHttpTransport; every request bounded byfetchTimeout(default 10 seconds); no hidden retries. - No implicit environment reads. Exceptions:
FileTokenSourcepath discovery andCredentialDiscovery.discover(env)where the caller passes the env map. keycard-spiffeneeds a native gRPC transport chosen by the application at runtime.CODEOWNERS:@keycardai/engineeringowns everything.