Skip to content

feat(context): add programmatic context schema discovery - #1980

Open
nchalaisRocket wants to merge 3 commits into
finos:mainfrom
nchalaisRocket:feat/context-schema-discovery
Open

feat(context): add programmatic context schema discovery#1980
nchalaisRocket wants to merge 3 commits into
finos:mainfrom
nchalaisRocket:feat/context-schema-discovery

Conversation

@nchalaisRocket

Copy link
Copy Markdown

Describe your change

This PR adds programmatic context schema discovery to @finos/fdc3-context (and, by re-export, @finos/fdc3).

Today the standardized context JSON Schemas are the single source of truth for context definitions, but they are only used at build time (to generate ContextTypes.ts) and are not available to consumers at runtime. This makes it hard for tooling — resolvers, validators, form/UI generators, documentation, and agents bridging FDC3 onto other protocols (e.g. MCP) — to reason about the set of available context types and their shapes without hard-coding or re-bundling the schemas.

This change exposes the schemas at runtime via a small accessor API:

Function Description
getContextTypes(): string[] Sorted list of standardized context type ids that have a published JSON Schema.
getContextSchema(type): ContextSchema | undefined The JSON Schema for a context type, or undefined.
getAllContextSchemas(): Record<string, ContextSchema> Map of every context type id to its JSON Schema.
getContextSchemaMetadata(type): ContextSchemaMetadata | undefined Lightweight metadata (title, description, $id, examples).
isStandardContextType(type): boolean Whether an id corresponds to a standardized context type.

Implementation notes:

  • The registry is generated from the existing schemas/context/*.schema.json files via a new schemagen build step (generateContextSchemas.cjs), wired into npm run generate. It therefore stays automatically in sync with the source-of-truth schemas — no hand-maintained duplication.
  • The abstract base context type (fdc3.context) is intentionally excluded, as it is not a concrete, broadcastable context type.
  • All returned values are defensive copies.
  • No changes to the Desktop Agent API, DACP wire protocol, or context type schemas themselves — this is purely additive, read-only, and requires no Desktop Agent connection.
  • Added unit tests, a spec section (website/docs/context/spec.md → "Programmatic Schema Discovery"), package README docs, and a CHANGELOG entry. Full monorepo npm run build and the @finos/fdc3-context test suite pass.

Related Issue

No existing issue — raising this to propose and discuss the feature. Happy to open a tracking issue if the maintainers prefer. This is intended as a starting point for discussion.

Contributor License Agreement

  • I acknowledge that a contributor license agreement is required and that I have one in place or will seek to put one in place ASAP.

Review Checklist

  • Issue: If a change was made to the FDC3 Standard, was an issue linked above? (feature raised for discussion; no issue yet)
  • CHANGELOG: Is a CHANGELOG.md entry included?
  • API changes: Does this PR include changes to any of the FDC3 APIs (DesktopAgent, Channel, PrivateChannel, Listener, Bridging)? — No. This adds library accessor functions to @finos/fdc3-context; the Desktop Agent API and wire protocols are unchanged.
  • Context types: Were new Context type schemas created or modified in this PR? — No. Existing schemas are read and exposed unchanged; code generation (npm run build) was run and the generated registry checked in.

@nchalaisRocket
nchalaisRocket requested a review from a team as a code owner July 13, 2026 15:43
@netlify

netlify Bot commented Jul 13, 2026

Copy link
Copy Markdown

Deploy Preview for fdc3 ready!

Name Link
🔨 Latest commit 3ba04e0
🔍 Latest deploy log https://app.netlify.com/projects/fdc3/deploys/6a74d88f540d24000836699f
😎 Deploy Preview https://deploy-preview-1980.preview-fdc3.finos.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 13, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: nchalaisRocket / name: nchalaisRocket (07594ea)

@nchalaisRocket
nchalaisRocket force-pushed the feat/context-schema-discovery branch 3 times, most recently from 543e02e to 07594ea Compare July 15, 2026 13:49
Expose the standardized FDC3 context JSON Schemas at runtime from
@finos/fdc3-context (re-exported from @finos/fdc3) so applications and
tooling can enumerate context types and retrieve their schemas without a
Desktop Agent connection.

Adds getContextTypes(), getContextSchema(), getAllContextSchemas(),
getContextSchemaMetadata() and isStandardContextType(). The registry is
generated from the existing schema files (single source of truth) via a
new schemagen build step, keeping it automatically in sync. The abstract
base context type is excluded and all returned values are defensive copies.

Includes tests, spec documentation and a CHANGELOG entry.
@nchalaisRocket
nchalaisRocket force-pushed the feat/context-schema-discovery branch from 07594ea to ef8bece Compare July 15, 2026 14:00
@codecov-commenter

codecov-commenter commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.32%. Comparing base (15931ac) to head (f27421c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1980   +/-   ##
=======================================
  Coverage   95.32%   95.32%           
=======================================
  Files          85       85           
  Lines        6698     6698           
  Branches      788      782    -6     
=======================================
  Hits         6385     6385           
  Misses        313      313           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kriswest kriswest left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please do raise an issue for this proposed change describing the use cases - we use issues for release milestone planning so all PRs should (for anything other than project governance/infrastructure maintenance) should have an associated issue.

Generating a copy of every schema as a javascript object to facilitate this access at runtime seems wasteful when the schema files themselves are bundled (

"schemas/**/*.json",
) and could be loaded instead... There would be no need for a generation step reducing complexity.

However, one generation step is desired already for #1852, where an enum and union of the known types is desired (similar to your getContextTypes function). That could be dealt with here in fdc3-context (where should have been moved to previously) and then re-exported by fdc3-standard.

@nchalaisRocket

Copy link
Copy Markdown
Author

Thanks for the review @kriswest!

  • Issue: raised Provide programmatic (runtime) access to standardized context type schemas #1993 describing the use cases (agents/protocol bridges, validation, dynamic UI/forms, docs tooling). Happy to refine it.
  • Avoiding a generated copy of the schemas: agreed — that's wasteful given the schema files are already bundled/emitted to dist/schemas (and resolveJsonModule is enabled). I'll rework getContextSchema/getAllContextSchemas to load the bundled schemas instead of shipping a duplicate JS object, and drop the standalone generation step for the copy.
  • Aligning with Automate maintenance of ContextTypes and IntentTypes enums and type in fdc3-standard #1852: makes sense to fold this in. I'll move the auto-maintained ContextTypes enum / ContextType union generation into fdc3-context (derived from the schemas), re-export from fdc3-standard/fdc3 to avoid a breaking change, and have getContextTypes() build on that single generation step rather than a separate one.

I'll push a revised implementation along those lines. Let me know if you'd prefer #1852 handled as a separate PR that this one builds on, or all together here.

@kriswest

Copy link
Copy Markdown
Contributor

Let me know if you'd prefer #1852 handled as a separate PR that this one builds on, or all together here.

Personally, I'm happy to deal with both issues in one PR/review. I support the schema access use case and am very happy to see a new contributor taking it on, alongside overlapping work we've already committed to!

@kriswest

Copy link
Copy Markdown
Contributor

n.b. isStandardContextType(type): boolean is already a function in fdc3-standard that could be maintained in fdc3-context and reexported also

@thorsent

Copy link
Copy Markdown
Contributor

"Today the standardized context JSON Schemas are the single source of truth for context definitions" - this is not true. The schemas must represent the actual apps which are available in any given system (which will rarely conform to the standard definitions, and certainly wouldn't support all of them in any given configuration).

Agreed that such a feature would allow agents to interoperate with FDC3 in a very powerful way but it involves multiple changes to the specification, not a library commit that reads from hardcoded files:

1 - an expansion of appd to support context schemas (which would be loaded by desktop agents)
2 - specification of a standardized function where a desktop agent can be queried for available schemas

@kriswest

Copy link
Copy Markdown
Contributor

@thorsent makes a good point - this will of course only enable retrieval of the standard schemas. Apps can define their own context types and there would end up being no way to retrieve those schemas (a context does not link to its schema). There is a very old issue open for the AppD to be able to do that: #719 then as @thorsent indicates a desktop agent could make all schemas from all appDs it is aware of available.

However, I don't think that negates the value of improving access to the standard's own schemas. But, depending on your use case, further work my be needed!

@thorsent

Copy link
Copy Markdown
Contributor

@kriswest we wouldn't want to expose the standard schemas in totum (as implemented here) because it would imply that the running instance contains apps which support those contexts.

A coding agent might desire a complete set, which it could already obtain from the source code. But a runtime agent really needs to know what is actually available at runtime. Even if the hardcoded list were filtered by availability the net result would be that the agent has access to partial information at best, which would result (I think) in confused developers and agents.

I don't think it's that much extra specification to implement a more complete solution. The question is whether there's an appetite to expand the spec in this direction.

@kriswest

Copy link
Copy Markdown
Contributor

This proposal doesn't expose anything through the Desktop Agent API, only from the fdc3-context and fdc3 libs. I read this as relating to cases where you already know its one of the standardized types that you are working with and want to gather context (about the the context type) to generate a valid instance of a context type - rather than discovering what's in use through the Desktop Agent or AppD.. On that level it seems reasonable - but definitely does not solve a wider problem where a firm defines their own context - in our case we provide our own library for that includes our custom schemas and types (+the FDC3 standard ones for convenience).

Hence a question to @nchalaisRocket: is the problem you want to solve tightly scoped to the standard types. Or are you interested in a general solution? As discussed here a general solution is possible but would require us to evolve the AppD servers and Desktop Agent API to manage and expose additional data, which could then include custom/proprietary types. We've had a related issue open for many years, but the use cases have grown due to AI. There is another issue open that relates to that:

@nchalaisRocket

Copy link
Copy Markdown
Author

Thanks @kriswest and @thorsent, good points from both of you.

On scope: this PR is small on purpose. It just lets you read the standard context schemas straight from the library. The idea is simple. Say you already know you're working with an fdc3.instrument and you want its schema so you can build or check a valid one. It doesn't touch the Desktop Agent API or AppD, and it doesn't try to say anything about what a running system actually supports.

Tom, fair point on the "single source of truth" wording. I only meant that the schema files are the official definition of the standard types, not what's available at runtime. I'll fix that and make the scope clear.

Runtime discovery of what a DA or AppD actually offers, custom types included (#719 / #1713), is clearly the bigger goal, but that's a real spec change and out of scope here. I'd keep it separate. This PR just gives it a solid starting point for the standard types.
Based on your feedback, here's what I'll change:

  • Drop the copied schemas and load the bundled files instead, so nothing is duplicated.
  • Fold in Automate maintenance of ContextTypes and IntentTypes enums and type in fdc3-standard #1852: generate the ContextTypes enum and the StandardContextType / ExperimentalContextType / ContextType types in fdc3-context, and re-export them from fdc3-standard / fdc3 (no breaking change, and the enum is no longer deprecated).
  • Move isStandardContextType into fdc3-context and re-export it too, good call Tom.
  • Tidy up the docs and rebase to clear the conflict with main.

Does that sound reasonable? Standard schemas here, runtime discovery as its own thing.

thanks a lot for your kind reviews

@kriswest

Copy link
Copy Markdown
Contributor

This did sound reasonable to me - please do update it as described when you have a minute and we'll try and get it merged.

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.

Provide programmatic (runtime) access to standardized context type schemas

4 participants