Mux Node SDK MCP
Mux Node SDK is the official API wrapper for Node projects, supporting Mux Data and Video. It provides easy access to the Mux REST API for server-side TypeScript or JavaScript applications.
How to Install and Use Mux Node SDK MCP
If you want to use Mux Node SDK MCP to work with Mux's video and data APIs in your Node.js projects, this guide will help you get started quickly. Follow these simple steps to install the SDK and use it with real code examples.
Step 1: Install the SDK
First, you need to add the Mux Node SDK MCP to your project. It’s available as an npm package, so you can install it easily using npm.
Open your terminal and run this command:
npm install @mux/mux-node
This command downloads and installs the SDK so you can use it in your Node.js app.
Step 2: Set Up Your Mux Client
After installing, you need to create a Mux client in your code. This client lets you call Mux APIs.
Here’s how to set it up:
import Mux from '@mux/mux-node';
const client = new Mux({
tokenId: process.env['MUX_TOKEN_ID'], // Your Mux token ID
tokenSecret: process.env['MUX_TOKEN_SECRET'] // Your Mux token secret
});
Make sure you have your Mux API credentials saved in environment variables (MUX_TOKEN_ID and MUX_TOKEN_SECRET). This keeps your keys safe and your code clean.
Step 3: Create a Video Asset
Now that your client is ready, you can create a video asset. This means uploading a video URL to Mux for processing and playback.
Here’s a simple example:
const asset = await client.video.assets.create({
inputs: [{ url: 'https://storage.googleapis.com/muxdemofiles/mux-video-intro.mp4' }],
playback_policies: ['public']
});
console.log(asset.id);
This code tells Mux to create a new video asset from the given URL and make it publicly playable. The asset ID is printed so you can use it later.
Step 4: Use JWT Helpers to Sign Playback IDs
If you want to secure your video playback, Mux SDK offers JWT helpers. These create tokens to control access to your videos.
Example of signing a playback ID token:
const token = Mux.jwt.signPlaybackId('your-playback-id');
console.log(token);
You can also sign tokens for thumbnails, GIFs, or storyboards by specifying the type:
const thumbToken = Mux.jwt.signPlaybackId('your-playback-id', { type: 'thumbnail', params: { time: 14, width: 100 } });
console.log(thumbToken);
This helps you control who can view or use your video content.
Step 5: Handle Webhooks Securely
Mux sends webhooks to notify your app about video events. To verify these webhooks, use the SDK’s webhook utilities.
Example of verifying a webhook in an Express app:
import Mux from '@mux/mux-node';
const mux = new Mux({ webhookSecret: process.env.MUX_WEBHOOK_SECRET });
app.post('/webhooks', bodyParser.raw({ type: 'application/json' }), (req, res) => {
try {
mux.webhooks.verifySignature(req.body, req.headers, process.env.MUX_WEBHOOK_SECRET);
const event = JSON.parse(req.body);
// Handle event here
res.json({ received: true });
} catch (err) {
res.status(400).send(`Webhook Error: ${err.message}`);
}
});
This ensures your app only processes genuine Mux webhooks.
By following these steps, you can install the Mux Node SDK MCP, create video assets, secure playback, and handle webhooks easily. The SDK is designed to be simple and practical for Node.js developers. For more details, visit the official Mux documentation.