muse-code-sdk
The Rust SDK for Muse Code: an async client for driving a Muse Code agent over the Muse Session Protocol (MSP), on your own Tokio runtime.
- Spawn a
muse servehost, or attach to a transport you already run. - Open and resume sessions; stream a turn's items as they arrive and await the turn's server-authored outcome.
- Answer tool-approval requests with a handler you register.
- A client-side fold keeps a live, typed view of the session, with gap recovery after reconnects and same-command retry: a host that can still read the earlier submission answers with its first decision instead of running it twice (a restarted host that cannot read it may run it again).
The generated MSP wire types are in muse_code_sdk::msp. Rust 1.97+.
Versioning and stability
-
The crate version is the Muse Code release it ships with:
muse-code-sdkX.Y.Zpairs with Muse CodeX.Y.Z, and every release moves both together. -
The stable MSP surface follows the Muse Code product's compatibility promise. Surfaces marked experimental may change or be removed in any release.
-
Cargo treats every
1.xrelease as compatible, but a Muse Code minor release can change the protocol. Pin the exact version that matches your Muse Code release:[] = "=X.Y.Z" -
Open protocol enums are
#[non_exhaustive]: amatchon them needs a catch-all_arm, and a release that adds a value does not break your build. -
So are the SDK's own public enums (its errors, outcomes and states): match them with a catch-all
_arm too, and a release that adds an error or an outcome does not break your build. -
Protocol structs that you only receive from the host (results, notifications, items, error objects) are
#[non_exhaustive]too, so a release that adds a field does not break your build; to build one, for example in a test that scripts a host, decode it from its wire JSON. The params you send (TurnInputPart,SessionConfig, and the params of every method) stay buildable with struct literals.
Before you start
- Install Muse Code.
curl https://dev.meta.ai/install.sh | bashinstalls a checksum-verifiedmuselauncher in~/.local/bin, adds it to yourPATH, and keeps it up to date; the user manual has the details. Open a new shell afterwards. The SDK runs the binary you name inSpawnOptions::muse_bin, or else the firstmuseonPATH: a program started from a shell opened before the install fails with "no muse host found", and an oldermuseearlier onPATHis used silently. - Log in once. Run
museand log in, so the host has provider credentials. A host without them fails every turn. - Pair the versions. Run
muse --versionand install this crate at that sameX.Y.Z(see Versioning and stability above). The installedmuseupdates itself, so it can move ahead of your pinned crate. If that release changed the protocol, the connection reportsfingerprint_warningand stays open, but calls whose shape changed can fail. Either way, move your pin to the versionmuse --versionprints.
Install
The second line is for the sample below: it runs on tokio
(#[tokio::main]), which this crate uses but does not re-export.
Use
use ;
use ;
use SendUserTurnOptions;
use SpawnOptions;
use TurnOutcome;
async
The crate's examples/ directory has a fuller quickstart and recipes for
approvals, retries, and cancellation.
Upgrading
From 1.4.20 or earlier
In 1.4.21, the workflow and web-search fields of Item (in
muse_code_sdk::msp) moved into two member fields. The wire format is
unchanged. Only Rust code that reads these fields needs the new paths:
- under
item.workflow:entry_id,script_id,trigger_source,resume_from_run_id,paused,children,message,token_budget,declared_phase,final_summary,stop_availableandchild_prompt_refs; - under
item.web_search:action,query,url,pattern,provider_status,resultsandraw_item.
For example, item.children becomes item.workflow.children, and
item.results becomes item.web_search.results.
Documentation
- API reference: https://docs.rs/muse-code-sdk
- Guides and the protocol reference: https://meta-models.github.io/muse-code-sdk/
- Source and issues: https://github.com/meta-models/muse-code-sdk
License
MIT. See LICENSE.