Registry / communication / twilio-mcs-client

twilio-mcs-client

JSON →
library0.4.3jsnpmunverified

This package provides a client library for interacting with the Twilio Media Content Service (MCS). MCS is a specialized Twilio offering that handles the storage and processing of media content, primarily for use with other Twilio products like Twilio Conversations. It enables developers to upload files, obtain media SIDs, and manage media assets, which can then be attached to messages for features such as Chat Media Messages. The service supports functionalities like generating image and video thumbnails, as well as document and video previews. The `twilio-mcs-client` library acts as a direct interface to the MCS REST API, which operates independently of the main `twilio-node` SDK. As of version 0.4.3, the package was last published approximately four years ago (as of mid-2026), suggesting it is no longer actively developed or may be in a long-term maintenance state with no new feature releases. Users should be aware that active development has ceased.

npm install twilio-mcs-client
INSTALL
IMPORT
SIG · TWILIO-MCS-CLIENT
T
twilio-mcs-client
communicationjavascriptv0.4.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Client
import { Client } from 'twilio-mcs-client';
const Client = require('twilio-mcs-client');
While CommonJS `require` might work in older Node.js, the package ships TypeScript types, favoring ESM `import` for modern usage and type safety. However, given its age, CJS is also common.
TwilioMcsClientOptions
import type { TwilioMcsClientOptions } from 'twilio-mcs-client';
Import types separately for explicit type usage in TypeScript projects.
MediaInstance
import type { MediaInstance } from 'twilio-mcs-client';
For type-checking the response object when uploading or retrieving media.

This example demonstrates how to initialize the Twilio Media Content Service (MCS) client and upload a simple text file. It creates a dummy file, reads its content into a buffer, and then uses the client's `media.create` method to upload it to a specified Chat Service SID. The script then logs the resulting Media SID and URL. Authentication uses a Twilio API Key and Secret, alongside the Account SID and Chat Service SID, all provided via environment variables. This pattern is essential for integrating media management with Twilio Conversations.

import { Client } from 'twilio-mcs-client'; import { promises as fs } from 'fs'; import * as path from 'path'; // Ensure you have these environment variables set const accountSid = process.env.TWILIO_ACCOUNT_SID ?? ''; const apiKey = process.env.TWILIO_API_KEY ?? ''; const apiSecret = process.env.TWILIO_API_SECRET ?? ''; const chatServiceSid = process.env.TWILIO_CHAT_SERVICE_SID ?? ''; // Your Chat Service SID async function uploadMediaFile() { if (!accountSid || !apiKey || !apiSecret || !chatServiceSid) { console.error('Missing one or more required environment variables: TWILIO_ACCOUNT_SID, TWILIO_API_KEY, TWILIO_API_SECRET, TWILIO_CHAT_SERVICE_SID'); process.exit(1); } // 1. Create a dummy file for upload const fileName = 'example.txt'; const filePath = path.join(__dirname, fileName); const fileContent = 'This is a test file to be uploaded to Twilio Media Content Service.'; const contentType = 'text/plain'; try { await fs.writeFile(filePath, fileContent); console.log(`Created dummy file: ${filePath}`); // 2. Read the file into a buffer const fileBuffer = await fs.readFile(filePath); // 3. Instantiate the Twilio MCS Client // The MCS client's base URL uses API key and secret for authentication, distinct from general Twilio client const client = new Client(apiKey, apiSecret, { accountSid: accountSid }); // 4. Upload the media console.log(`Uploading ${fileName} (Type: ${contentType}) to Service SID: ${chatServiceSid}...`); const mediaInstance = await client.media.create( chatServiceSid, { body: fileBuffer, contentType: contentType, filename: fileName } ); console.log('Media uploaded successfully!'); console.log('Media SID:', mediaInstance.sid); console.log('Media URL:', mediaInstance.url); } catch (error) { console.error('Error uploading media:', error); if (error instanceof Error && error.message.includes('401')) { console.error('Authentication failed. Check your API Key/Secret and Account SID.'); } if (error instanceof Error && error.message.includes('404')) { console.error('Service SID not found or incorrect. Check TWILIO_CHAT_SERVICE_SID.'); } } finally { // Clean up the dummy file try { await fs.unlink(filePath); console.log(`Cleaned up dummy file: ${filePath}`); } catch (cleanupError) { console.error('Error cleaning up dummy file:', cleanupError); } } } uploadMediaFile();
Debug
Known issues
breakingThis package (`twilio-mcs-client`) is considered abandoned. Its last publish was over four years ago (as of mid-2026). While it may still function, there will be no further updates, bug fixes, or security patches. Consider migrating to direct REST API calls or newer Twilio SDKs if media handling is integrated with other active services.
fix
Evaluate if direct HTTP requests to Twilio's Media Content Service API (https://mcs.us1.twilio.com/v1) can replace the library calls, or explore media handling within actively maintained Twilio SDKs like `@twilio/conversations` (if applicable to your use case) for client-side uploads, or `twilio-node` for general API interactions (though `twilio-node` does not directly handle MCS uploads).
affects: >=0.4.3
gotchaThe `twilio-mcs-client` is a dedicated client for the Media Content Service, which uses a distinct API endpoint and authentication flow. It is *not* the same as the general `twilio-node` SDK for other Twilio services (e.g., sending SMS, managing calls). You cannot use the `twilio-node` client directly for MCS operations.
fix
Always use the `twilio-mcs-client` for Media Content Service interactions or make direct HTTP requests to the MCS API. Do not attempt to use the main `twilio` NPM package for these specific media upload/retrieval operations. Ensure you are using an API Key and Secret, not your Account SID and Auth Token directly, for MCS calls, as recommended for production.
affects: >=0.1.0
gotchaMedia uploaded via MCS requires a `Chat Service SID`. If the media is not attached to a Conversation message within five minutes, it will be automatically garbage-collected by Twilio.
fix
Ensure you have a valid `TWILIO_CHAT_SERVICE_SID` for your Twilio project. Implement logic to promptly associate uploaded media with a Conversation Message using the returned Media SID from the MCS client within the stipulated five-minute window to prevent unintended deletion.
affects: >=0.1.0
Errors
Common errors & fixes
Error uploading media: Twilio API Error: 401 - Unauthorized
Invalid Twilio API Key, API Secret, or Account SID provided during client initialization. MCS uses basic authentication with API Key/Secret.
fix
Verify that `TWILIO_API_KEY`, `TWILIO_API_SECRET`, and `TWILIO_ACCOUNT_SID` environment variables are correctly set and correspond to valid Twilio API credentials with appropriate permissions for the Media Content Service. Remember that API Keys are recommended over Auth Tokens for production.
Error uploading media: Twilio API Error: 404 - Resource Not Found
The provided `TWILIO_CHAT_SERVICE_SID` is incorrect or does not exist for your Twilio Account.
fix
Double-check the `TWILIO_CHAT_SERVICE_SID` environment variable against your Twilio Console to ensure it refers to an existing and correct Chat Service Instance.
Upgrade
Version history
0.4.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
18
Amazon
1
OpenAI (training)
1
Resources
twilio-mcs-client — npm install twilio-mcs-client · libregistry