Morphir.Mep 0.5.0-alpha.2

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.2
                    
NuGet\Install-Package Morphir.Mep -Version 0.5.0-alpha.2
                    
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.2" />
                    
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.2" />
                    
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.2
                    
#r "nuget: Morphir.Mep, 0.5.0-alpha.2"
                    
#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.2
                    
#: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.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Morphir.Mep&version=0.5.0-alpha.2&prerelease
                    
Install as a Cake Tool

Morphir.Mep

One implementation of the Morphir Extension Protocol (MEP) 0.2.0-draft.1 for morphir-dotnet hosts and guests: JSON-RPC 2.0 messages, Content-Length framing, the session lifecycle and the model transport. Work 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.
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
    }

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.

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.5 79 11/22/2026
0.5.0-alpha.4 92 11/16/2026
0.5.0-alpha.3 98 11/14/2026
0.5.0-alpha.2 98 11/13/2026
0.5.0-alpha.1 94 11/13/2026
0.4.0-alpha.5 98 11/13/2026
0.4.0-alpha.4 83 11/10/2026
0.4.0-alpha.3 82 11/9/2026

### Fixed

- `morphirup setup --yes` and extension package installation work on macOS 15. Before, they failed with `extension.io_error: Cannot access '…/store/extensions/packages/sha256': native error 13.` macOS 15 refuses to rename a directory that is not writable, even when the directory stays in the same parent, and the installer sealed a package (mode 0555) before it published it with a rename. macOS 26 allows that rename, so the macos-latest jobs passed. The installer now seals the package's contents before publication and the package root after it, while it still holds the state lock. An installation of a package that is already in the store seals the root if a publication was interrupted before it did.
- Build: the release and its dry run also run the osx-arm64 setup journey on macOS 15 (`build-morphirup`, `os: macos-15`), beside macos-latest (macOS 26). That leg uploads nothing: the new `morphirup-build.yml` input `upload` (default `true`) is `false` for it, and the macos-latest leg still produces the osx-arm64 assets. Pull requests do not run it.

### Changed

- `morphirup setup` sets up from the [finos/morphir releases](https://github.com/finos/morphir/releases), the official place for Morphir releases, from the next release, `0.5.0-alpha.2`, on. It downloads from `https://github.com/finos/morphir/releases/download/v<version>/`, with the same `v<version>` tag and the same three redirect hosts (`github.com`, `release-assets.githubusercontent.com`, `objects.githubusercontent.com`, at most three redirects), and keeps its `release-checksum` assurance. There is no fallback to the finos/morphir-dotnet releases: a bundle whose asset URLs name finos/morphir-dotnet is refused. A release generation records `https://github.com/finos/morphir` as its repository; the candidate's `sourceRepository` still names finos/morphir-dotnet, where the code is built from.
- The composed local-toolchains family moves from `0.1.0-preview.4` to `0.1.0-preview.5` ([finos/morphir#1171](https://github.com/finos/morphir/pull/1171), merged as `00a48d4a`), which differs from preview.4 only in the release repository of the bundle's asset URLs and of the generation's `acquisition.repository`. The producer writes preview.5, and `morphirup` reads preview.5 only: candidates, bundles, receipts, selections and generations of preview.4 (written by 0.5.0-alpha.1) are not read and are not converted. `select`, `show` and `run` read only the preview.5 selection pointer: in a Home set up with preview.2, preview.3 or preview.4 they refuse with `local.setup_required`, which says to run `morphirup setup --yes` again (and then `select`, for a local candidate). Setup in that Home installs preview.5 beside the earlier generations without reading them, and replaces the selection pointer. A refused `setup`, `select` or `show` writes a preview.5 result. The historical preview.1 local route is unchanged.
- Build: finos/morphir can call `morphirup-build.yml` at a pinned commit of this repository, as it calls `cli-offering.yml`. The new inputs `repository` and `ref` (a full commit SHA) choose what the job checks out and builds, and the Windows source check compares the checkout with `ref`. With the new input `upload-host-offering: true`, a job that packs a toolchain (win-x64, win-arm64, or osx-arm64 with `toolchain: true`) also uploads its self-contained host as the artifact `morphir-dotnet-self-contained-<rid>`: the archive with its `.build-launch.json`, `.build-contents.json` and `.sha256`, the files `cli-offering.yml` uploads for that offering. The inputs default to empty and `false`, so `morphirup.yml` and `deployment.yml` work as before. The checkout no longer keeps the workflow token in the Git configuration.