Morphir.Mep 0.5.0-alpha.6

Prefix Reserved
This is a prerelease version of Morphir.Mep.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Morphir.Mep --version 0.5.0-alpha.6
                    
NuGet\Install-Package Morphir.Mep -Version 0.5.0-alpha.6
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Morphir.Mep" Version="0.5.0-alpha.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Morphir.Mep" Version="0.5.0-alpha.6" />
                    
Directory.Packages.props
<PackageReference Include="Morphir.Mep" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Morphir.Mep --version 0.5.0-alpha.6
                    
#r "nuget: Morphir.Mep, 0.5.0-alpha.6"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Morphir.Mep@0.5.0-alpha.6
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Morphir.Mep&version=0.5.0-alpha.6&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Morphir.Mep&version=0.5.0-alpha.6&prerelease
                    
Install as a Cake Tool

Morphir.Mep

The Morphir Extension Protocol SDK for morphir-dotnet hosts and guests provides JSON-RPC 2.0 messages, Content-Length framing, the session lifecycle and model transport on MEP 0.2.0-draft.1. Bounded generation is an explicit opt-in to MEP 0.2.0-draft.2. The core SDK is tracked by #512 and add-mep-core. The roadmap is the Morphir extension model PRD, step 1.

Layers

Layer File What it does
Wire types Wire.fs Records and unions of the pinned contract, with parsed values (ProtocolVersion, SemanticVersion, Sha256Digest, RequestId). MepJson is generated from this file at build time by Morphir.Myriad.SystemTextJson. There is no reflection serializer.
Model transport ModelTransport.fs Tuple selection, the host check of a selection, envelope creation and admission. Pure functions.
Bounded generation ModelAccess.fs Complete tuple selection, start admission and the per-connection operation and round ledger.
Message codec Rpc.fs Classifies a JSON-RPC message by its members (JsonRpcMessage), keeps params raw, and writes messages. This is the only hand-written JSON.
Dispatcher Dispatcher.fs DispatchAsync(bytes, ct) returns the reply bytes, or none for a notification. A method table maps method names to typed handlers; a gate refuses a method before its handler runs.
Framing Framing.fs Content-Length frames on a Stream: header blocks up to 8192 bytes, bodies up to 64 MiB, checked before the body is read. A refused frame ends the connection.
Connection Connection.fs Reads frames, dispatches inbound requests concurrently, matches inbound responses to the pending-request table, and sends and receives $/cancelRequest.
Session Session.fs The pure lifecycle rules (Lifecycle.admit) and version negotiation, shared by hosts and guests.
Channel Channel.fs How a host session reaches its guest: a framed stream pair, or ISingleMessageChannel for a guest that takes one message per call. SessionFailure says why a single-message session ended.
Peers Peers.fs Guest (lifecycle methods, gate, extension methods) and HostSession (refuses to send what the guest must refuse).

On the guest side, the stream path (Connection) and the single-message path (Dispatcher.DispatchAsync) use the same dispatcher, so they give the same bytes. On the host side, HostSession holds a channel and applies the same lifecycle, version and model-transport rules on either. Starting a guest process is not in this project: a process host connects a HostSession to the child's streams.

Channels

A host session sends a request and waits for its reply, and sends notifications. It does both through a channel (CHAN-1). HostSession checks each request against the lifecycle state before it uses the channel, so a request refused on one channel is refused on the other with the same error, and the guest never receives it.

Channel Constructor What the guest is
Framed stream pair HostSession(input, output, host, offer) A process with Content-Length frames on its standard streams. Requests run concurrently and are matched by id; a cancelled request sends $/cancelRequest; the guest can send morphir.progress.
Single message HostSession(channel, host, offer) A guest that takes one whole message per call, such as the handle export of a WASM guest. The runtime implements ISingleMessageChannel; tests/Morphir.Mep.AotProbe has a C# implementation.

ISingleMessageChannel has two members. Both take the method name, the bytes of one complete UTF-8 JSON-RPC message with no Content-Length header, and a cancellation token. Both return the bytes of the message the guest returned, or null when it returned none.

  • RequestAsync calls the guest with a request.
  • NotifyAsync calls the guest with a notification, or withholds it when the guest's runtime does not deliver notifications to that guest. A withheld notification does not call the guest. HostSession always sends morphir.initialized and morphir.exit; the runtime decides whether the guest receives them.

The implementation passes bytes and does not check them. HostSession applies these rules to a single-message guest:

  • One call at a time. A request waits until no other call is inside the guest.
  • A request takes exactly one reply: the response or error response with the request's id. No bytes, a response for another id, a request or notification (such as morphir.progress), bytes that are not a JSON-RPC message, or a reply over ContentLengthFraming.MaxBodyBytes fail the session.
  • A notification takes no reply. Bytes returned for one fail the session.
  • The host never sends $/cancelRequest. When a request's token is cancelled, the channel stops the call and ends it with OperationCanceledException. The request ends with -32800 and the session ends.
  • An exception from the channel fails the session.
  • After the session fails, no message reaches the guest. Failure (C#: FailureOrNull()) says why, as a SessionFailure. The request that failed gets -32800 when it was cancelled and -32603 otherwise. Later requests get -32603 without a call. A failure during InitializeAsync gives InitializeFailure.Refused with that error. RunAsync ends with Stopped at exit or failure.

Which notifications a WASM guest accepts is read from its morphir.initialize result by the runtime, not by HostSession. The member that advertises it is not fixed in the contract yet (NTFY-1).

A guest and a host in memory

This example is compiled by tests/Morphir.Mep.Tests/ReadmeTests.fs. Keep the two equal.

let runSession (claims: CapabilityClaimSet) (capabilities: ExtensionCapabilities) =
    task {
        let guest =
            Guest(
                { Claims = claims
                  Capabilities = capabilities
                  Methods = readOnlyDict [] }
            )

        let toGuest = Pipe()
        let toHost = Pipe()
        let guestRun = guest.RunAsync(toGuest.Reader.AsStream(), toHost.Writer.AsStream(), CancellationToken.None)

        let host =
            HostSession(
                toHost.Reader.AsStream(),
                toGuest.Writer.AsStream(),
                { Kind = PeerKind.Cli; Name = "morphir"; Version = "0.4.0" },
                null
            )

        let hostRun = host.RunAsync CancellationToken.None
        let! session = host.InitializeAsync CancellationToken.None
        let! ping = host.PingAsync CancellationToken.None
        let! _ = host.ShutdownAsync CancellationToken.None
        do! host.ExitAsync()
        let! guestEnd = guestRun
        toHost.Writer.Complete()
        let! _ = hostRun
        return session, ping, guestEnd
    }

Bounded generation

An extension can generate from a package on disk without receiving the whole package at initialization. It asks for the inventory or documents it needs in each continuation. The host keeps the snapshot lease and answers from the same revision. The same exchange works on a framed process connection and a WASM byte-call channel.

sequenceDiagram
    participant Host
    participant Guest
    Host->>Guest: initialize with modelAccess
    Guest-->>Host: select draft.2 and complete tuples
    Host->>Guest: StartGenerationAsync with one tuple and snapshot
    Guest-->>Host: Continue round 1 with inventory requests
    Host->>Guest: AdvanceGenerationAsync with deliveries in request order
    Guest-->>Host: Continue with the next round, Complete, or Failed

Construct the host with HostSession.CreateWithModelAccess, supplying ModelAccessSupport and an optional legacy transport offer. The guest lists draft.2 in Claims.ProtocolVersions and declares Capabilities.ModelAccess, its backend targets and its start, advance and cancel handlers. Check the selected draft and tuple in InitializeAsync before choosing the request's input. A draft.1 selection keeps the existing whole-model path.

For example, when a continuation has no requests, the host advances with an empty delivery list. This example is compiled by ReadmeTests.fs.

let advanceEmpty (host: HostSession) (step: ModelAccessStep) cancellation =
    match step with
    | ModelAccessStep.Continue(id, round, requests, _, _) when requests.Count = 0 ->
        Some(host.AdvanceGenerationAsync({ SessionId = id; Round = round; Deliveries = [||] }, cancellation))
    | _ -> None

For a nonempty continuation, supply one delivery per request in order. CancelGenerationAsync requests release of an open operation and checks the acknowledged ID. An invalid round does not consume the outstanding round. Completion, failure and an acknowledged cancel retire the operation ID for the connection. Both peers check exchange identity and order. Before passing a document delivery to the transport or handler, they verify canonical base64, decoded length, and SHA-256. They enforce the batch document count and the aggregate encoded and decoded byte ceilings before decoding. An invalid delivery leaves the pending round available for correction. Snapshot access, IR decoding, execution deadlines, artifact staging, and publication belong to the host and extension operating the session. See the bounded-generation contract for the complete exchange and resource limits.

Add a method

  1. Check that the pinned contract has the method and its params and result types. Do not add a method, member or error code that the pin does not have; raise an upstream issue.
  2. Write a failing wire test, then add the types to Wire.fs with the attributes that the contract's wire rules need. Add the type to the contract test (ContractTests.fs): a complete sample, and the members that the contract text lets a reader default.
  3. Add the method to Method if it is new, and its capability to Lifecycle.capability if the contract makes it depend on one (the guest replies -32013 without it).
  4. Register a handler in the guest's Methods with Handlers.request (params bind as one object through their codec; absent or mismatched params give -32602), and add a typed call to HostSession if hosts send it.
  5. Add the method to the AOT probe (tests/Morphir.Mep.AotProbe) when it changes what C# calls.

The pin

tests/Fixtures/Mep pins the upstream contract model (mep.ir.json), the transcripts and the model-transport corpus by commit and digest. Do not edit the fixtures. To update the pin:

  1. Copy the new files from finos/morphir at one commit, and record the commit and the SHA-256 digests in PROVENANCE.md.
  2. Run the tests. ContractTests fails for each renamed or added member, and the transcript and corpus tests fail for each changed behavior.
  3. Change the types and rules in the same pull request. A new MEP version moves every MEP part in morphir-dotnet together; drafts match only exactly.

Where a transcript and the contract text disagree, the tests follow the contract text. The legacy transcripts initialize with 0.1; the replays use 0.2.0-draft.1 instead. The separately pinned bounded-generation transcript runs on exact draft.2.

C# callers

The project is trimmable and AOT-compatible, with F# nullness metadata. Parsed values have TryParse and Create; FrameRead and SessionFailure have Match. tests/Morphir.Mep.AotProbe is a C# consumer that runs the full session on streams and on a C# ISingleMessageChannel; InteropTests and ChannelTests compile C# examples and check the nullable-flow diagnostics.

Tests

dotnet run --project tests/Morphir.Mep.Tests -- --summary
./build.sh --target TestAot --configuration Release

The first command runs the wire, contract, JSON-RPC, connection, session, channel and model-transport tests in memory. The channel tests use a fake single-message guest built on Dispatcher.DispatchAsync. The second is the Native AOT lane of the black-box tests: it publishes the probe (and the other probes and library hosts) with Native AOT, refuses IL diagnostics other than the FSharp.Core summary baseline, and compares the native output with the managed output. Both run in PR CI.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Morphir.Mep:

Package Downloads
Morphir.Extensions

Morphir extension registry domain: parsed extension identities, capability claims and the extension catalog

Morphir.Compilation.Mep

The MEP 0.2.0-draft.1 host side of guest processes: the guest process and session, and the frontend adapter, an IFrontend over a guest that serves morphir.frontend.compileModel. Trim-safe and AOT-safe.

Morphir.Extensions.Installation

Local extension package installation, inventory, selection and activation for Morphir tooling.

Morphir.Extensions.Wasm

The WASM extension runtime of morphir-dotnet: Wasmtime with the embedded Extism kernel module.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.5.0-alpha.7 63 12/2/2026
0.5.0-alpha.6 99 11/30/2026
0.5.0-alpha.5 103 11/22/2026
0.5.0-alpha.4 97 11/16/2026
0.5.0-alpha.3 105 11/14/2026
0.5.0-alpha.2 101 11/13/2026
0.5.0-alpha.1 99 11/13/2026
0.4.0-alpha.5 103 11/13/2026
0.4.0-alpha.4 90 11/10/2026
0.4.0-alpha.3 88 11/9/2026

### Added

- `morphir compile` composes `ir.layout` (`single-file`, `document-tree`) with `ir.format` (`json`, `yaml`, `ion`):
- `morphir generate` reads JSON (`manifest.json`), YAML (`manifest.yaml`/`manifest.yml`), and Ion (`manifest.ion`) document trees (both plain and name-compacted contextual envelopes across IR `3`, `3.1.0`, and `4`/`4.0.0`) as well as single-file JSON, YAML, and Ion IR models, adds `--input-format yaml` (`autojsonyamlion`), and reads all three formats from `compile.json` without `--input`. Built-in backends (`fsharp`, `csharp`) generate identically across formats and layouts; external MEP draft.2 guests run bounded multi-document sessions over recorded or explicit JSON/YAML trees (including YAML and Classic `3.1.0` support and draft.1 lossless conversion reporting `morphir-yaml`/`morphir-json`), while `morphir validate` keeps its released JSON/Ion-only policy. `Morphir.Extensions.Installation` supports extension-state contract `0.1.0-preview.4` (for `capabilities.modelAccess` locks/catalogs) while retaining `0.1.0-preview.3`, and `Morphir.Ion` detects non-finite / precision-losing Classic `3.1.0` decimals (`unrepresentable_literal`) before typed decode. `DocumentTreeStore` adds multi-profile bounded loading (`TryReadModel`, `TryReadYamlDocument`, `TreeReadOptions`, and F#-only `readAnyProfile`) while keeping `DocumentTreeStore.Read` JSON-only, plus PascalCase `ReadOptions.Defaults` and `WriteOptions.DefaultPathBudget` for C# callers. See [morphir generate](docs/content/docs/cli/generate.md).
- Diagram layouts and renderers. `DiagramExport.Layout` gives every diagram a public, renderer-neutral layout of each page: shapes, lines with bound ends, waypoints and exact paths, text, images, composite elements, containers and groups, in `Distance` units (quarter EMU, exact for 0.01 px, points and EMU), with resolved colours and the diagram's links. A renderer from any assembly subclasses `DiagramRenderer` and declares the `LayoutFeature`s it draws; `DiagramExport.Assess` reports whether pages are native, degraded or unsupported for it, and `DiagramExport.RenderAsync` lowers them through fallbacks in a fixed order and applies a strict, allow-degraded or picture-fallback policy. `Diagnostic.Error` and `Diagnostic.Warning` let renderers report, and `DiagramRenderers` registers them by file extension. The new package `Morphir.Diagrams.Canvas` exports editable draw.io files, Excalidraw scenes and Obsidian Excalidraw notes whose shapes, bound connectors and element references survive editing. A transition from the reserved state `root` is now refused with `state/reserved-id`, and text that XML cannot hold is drawn with U+FFFD instead of failing. See [Layouts and renderers](src/Morphir.Diagrams/README.md#layouts-and-renderers) and [Morphir.Diagrams.Canvas](src/Morphir.Diagrams.Canvas/README.md) ([#705](https://github.com/finos/morphir-dotnet/issues/705))
- Diagram slide export. The new package `Morphir.Diagrams.Slides` places layouts on slides with `SlidePlacement` (widescreen or 4:3, a content area, an exact fit on the format's grid) and writes them as PowerPoint presentations (`PowerPointRenderer`, with exact routes or connectors glued to shapes), OpenDocument presentations for LibreOffice Impress (`OpenDocumentRenderer`, with glued connectors that keep their routes), Google Slides `batchUpdate` request bodies that the caller sends with their own client (`GoogleSlidesRenderer`), and reveal.js decks of the original SVG (`RevealJsRenderer`). The office formats embed SVG images with a PNG fallback. See [Morphir.Diagrams.Slides](src/Morphir.Diagrams.Slides/README.md) ([#706](https://github.com/finos/morphir-dotnet/issues/706))
- `Morphir.Ion` writes the Ion IR format. `IonIrWriter.write` gives the canonical Ion 1.0 text of draft `0.1.0-draft.1` for a v3 library (`3.0.0`), a v3 specs distribution (`3.1.0`) and every v4 distribution (`4.0.0`), and `IonIrWriter.writeTree` gives the canonical Ion document tree, with `manifest.ion`, `module.ion` and one `<stem>.type.ion` or `<stem>.value.ion` for each member, stems cut to the path budget, and no footer. What it writes reads back through `IonIr.read` and `IonIrTree.read` as the same distribution, and writing it again gives the same bytes; what Ion cannot hold that way is refused, such as a v3 value attribute that is not the classic JSON of a type (`unrepresentable_attribute`) or a version other than `3`, `3.0.0`, `3.1.0`, `4` and `4.0.0` (`IonIrVersions`). The header states the exact release. The reference CLI's single files and trees are matched byte for byte where the IR holds what they spell. `IonIrWriter.readJson` and `ofJson` start from IR JSON, and `IonIrWriting.TryWriteJson`, `TryWriteJsonTree` (both flat entries and versioned `VFileTree`) and `IonIrReading.TryRead` serve C# callers, with an `IonFailure` whose locations are text or null; the root's single `formatVersion` is checked by the format-version grammar (type, syntax and 32-bit range) and then for Ion support before the distribution is read, so `4.0`, `"3.4294967296.0"`, an uncarried release such as `3.0.1`, or a missing or repeated one is refused; a v3 member the classic model cannot keep is refused (`unknown_member`); a v3 inferred type with a name or path that Ion cannot read back, such as an empty name, is `unrepresentable_attribute`; a repeated member of any JSON object is refused (`duplicate_member`), at an RFC 9535 location that writes a key other than an ASCII member-name shorthand (a letter or `_`, then letters, digits and `_`) as an escaped `["key"]`, so `a-b` is `$["a-b"]`; a v4 float lexeme that does not spell its value is refused (`invalid_literal`); a document number whose decimal scale passes the reader's 1,000 stays `number::` text; a v3 member without documentation is `unrepresentable_documentation`, because Ion reads a missing `doc` as the empty one; `ofJsonAs` / `ofJsonTreeAs` state another carried release, such as `3.1.0`; and a tree whose cut stems give two documents one path is refused with `stem_collision`. See [Writing the Ion IR format](src/Morphir.Ion/README.md#writing-the-ion-ir-format).
- `Morphir.IR.Trees.CanonicalYaml` writes a JSON value as the canonical YAML of the YAML profile: block mappings with two-space indentation, flow sequences unless a mapping is nested in them, `{}` and `[]` for empty containers, plain strings unless plain YAML would change their meaning (control characters, the line and paragraph separators, U+FFFE and U+FFFF are escaped, and only a whole octal or hexadecimal token such as `0x10` is quoted, so `0xylophone` stays plain; a key longer than the 1,024 characters of an implicit key is an explicit `? key`), JSON number lexemes unchanged, and one final line feed. The profile's reader gives the same value back, a mapping key `<<`, which the profile refuses even quoted, and a repeated member are refused, and the kit's canonical YAML spellings and `complete-example.yaml` are matched byte for byte. `CanonicalYaml.ofJsonTree` and `CanonicalYamlWriter.TryWriteTree` convert the files of a JSON document tree into a YAML tree (`manifest.yaml`, `module.yaml`, `*.type.yaml`, `*.value.yaml`), and `CanonicalYamlWriter.TryWriteJson` serves C# callers.
- MCK vNext .NET runner in `Morphir.Mck` and `Morphir.Conformance`: adds `check`, `prepare`, `run`, `verify`, and `render` commands for IR inverted-control binding harnesses (`--exec`), MEP (`--target` / `--wasm`), and Morphir runtime verification, with sandboxed Jint JS driver execution, built-in comparators (`exact`, `json`, `ir-semantic`, `ion`, `diagnostic`), capability rollups, `--check-underclaims`, and standalone offline HTML report rendering. See [morphir-mck](docs/content/docs/cli/morphir-mck.md) and [MCK vNext .NET Runner](docs/contributing/mck-vnext-runner.md) ([#716](https://github.com/finos/morphir-dotnet/pull/716)).
- `Morphir.Mck` is packaged and published as a NuGet .NET tool (`morphir-mck`), installable via `dotnet tool install --global Morphir.Mck --prerelease` (or locally in a tool manifest) and delegated automatically by `morphir mck <args>` when on `PATH`. See [morphir-mck](docs/content/docs/cli/morphir-mck.md) and [mck](docs/content/docs/cli/mck.md).

### Changed

- The JSON locations that `V4Json` and the strict classic reader report, and the duplicate-member locations of the Ion writer, follow RFC 9535: a member whose name is an ASCII member-name shorthand (a letter or `_`, then letters, digits and `_`) follows a dot, and every other member is an escaped name selector, so `tx-id` is `["tx-id"]` and a key with a quote is `["a/"b"]`. `Morphir.Json.JsonPaths` writes them for every reader, and `morphir model verify` reads escaped selectors back into JSON Pointers.

### Fixed

- Pin LF (`/n`) line endings in `Morphir.Diagrams.Canvas` (`ExcalidrawRenderer` and `ObsidianExcalidrawRenderer`) and `Morphir.Models` (`ClassicJsonWriter`), ensuring byte-identical JSON output across Windows, macOS, and Linux ([#712](https://github.com/finos/morphir-dotnet/pull/712)).