npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mg.js/headless

v0.1.6

Published

Standalone Magic Garden client: owns its own WebSocket, authenticates, handshakes, stays alive, reconnects, and exposes the full @mg.js/common action and state surface.

Readme

@mg.js/headless

The standalone Magic Garden client from magicgarden.js. It owns its own WebSocket: it authenticates, handshakes, stays alive, reconnects, and exposes the full @mg.js/common action and state surface.

Use this when you want a client that owns its connection. To ride the live game's own connection from inside the page instead, use @mg.js/bootstrapped.

Install

npm install @mg.js/headless

ws is declared as both an optional dependency and an optional peer dependency. It exists because Node's global WebSocket cannot do one thing the game needs: send request headers. The game's own documented Cookie: mc_jwt and Origin paths need them. new WebSocket(url, [], { headers }) is accepted and silently ignored, so the package exposes an injectable webSocketFactory and an opt-in ws adapter, emits a headers-dropped event (names only, never values), and logs which runtime it got.

Entry points

| Subpath | Contains | |---|---| | @mg.js/headless | the clients, the auth providers and the session probe | | @mg.js/headless/transport | the socket transport and its attempt-URL builder | | @mg.js/headless/auth | CookieAuthProvider and the credential handling around it |

Example

Two entry points, both delegating to the same client: RoomSocket is the class the API reference specifies for a standalone client, and HeadlessClient is the richer one the repository docs use.

import { RoomSocket, CookieAuthProvider } from '@mg.js/headless';

// The documented API-reference shape: start(options) -> the URL that was opened.
const socket = new RoomSocket({ auth: new CookieAuthProvider(process.env.MC_JWT!) });
socket.onWelcome((msg) => console.log('playerId:', msg.selfPlayerId));
await socket.start({ room: 'abcde12345' });
await socket.waitUntilReady();
await socket.actions.harvestCrop({ slot: 3 });
import { HeadlessClient, CookieAuthProvider } from '@mg.js/headless';

const client = new HeadlessClient({
  auth: new CookieAuthProvider(process.env.MC_JWT!),
  // version is discovered from /platform/v1/version, so the 4710/4700 loop cannot start
});

client.on('ready', () => {
  void client.actions.checkWeatherStatus();
});

await client.start();
await client.waitUntilReady();

console.log(client.selfPlayerId, client.store.get('/data/players/0/coins'));

Known limitations

  • A headless connection needs an mc_jwt cookie, and there is no headless way to obtain one. See docs/sessions.md for how the cookie is obtained and why guests get 4840.
  • Node's global WebSocket cannot send request headers, as described above.
  • No inbound event exists for chat, emotes, or player join/leave: the protocol documents five inbound message types and a wrapper cannot surface events it cannot observe.
  • Nothing here is official, and a client update can change any of it.

License

MIT