Version 0.1.2
This application integrates MyCarrierPackets (MCP) webhooks with Slack using Socket Mode. It listens for MCP webhook events and forwards formatted messages to a specified Slack channel.
This application was built by Anthony Fecarotta (https://github.com/fakebizprez) of freight.Cognition.
- Receives MCP webhooks.
- Verifies webhook signatures for security.
- Uses Slack Socket Mode for real-time messaging.
- Formats messages for various MCP event types.
- Includes a health check endpoint (
/health). - Configured for Docker deployment.
Before you begin, ensure you have the following installed:
-
Clone the repository:
git clone https://github.com/your-username/mcp-alerts.git # Replace with the actual repo URL if different cd mcp-alerts
-
Install dependencies:
pnpm install
-
Create and Configure the Slack App:
Before you can configure the environment variables, you need to create a Slack app and obtain the necessary tokens. Follow these steps:
a. Go to Your Slack Apps: Navigate to https://api.slack.com/apps and click "Create New App".
b. Create an App: Choose "From scratch". Enter an "App Name" (e.g., "MCP Alerts") and select the Slack workspace where you want to install the app. Click "Create App".
c. Enable Socket Mode: In the left sidebar, under "Settings", click on "Socket Mode". Toggle the switch to "Enable Socket Mode". You'll be prompted to generate an App-Level Token. Enter a name for the token (e.g., "mcp-socket-token") and click "Generate". Copy this token (it will start with
xapp-) and save it. This will be yourSLACK_APP_TOKEN.d. Add Bot Scopes: In the left sidebar, under "Features", click on "OAuth & Permissions". Scroll down to the "Scopes" section. Under "Bot Token Scopes", click "Add an OAuth Scope" and add the following scope: *
chat:write: Allows the app to send messages to channels it's a part of.e. Install App to Workspace: At the top of the "OAuth & Permissions" page, click "Install to Workspace". Follow the prompts to authorize the app. Once installed, you will see a "Bot User OAuth Token". Copy this token (it will start with
xoxb-) and save it. This will be yourSLACK_BOT_TOKEN.f. Add Bot to Channel(s): Open your Slack client. Go to the channel where you want the MCP alerts to be posted. Type
/invite @your-app-name(replaceyour-app-namewith the name you gave your Slack app) and send the message, or use the channel settings to add the app/bot user. -
Configure environment variables: Create a
.envfile in the root of the project by copying the example file:cp .env.example .env
Then, open the
.envfile and update it with your specific credentials and settings:SLACK_BOT_TOKEN: Your Slack Bot Token (starts withxoxb-). This token is used by the app to interact with the Slack API.SLACK_APP_TOKEN: Your Slack App-Level Token (starts withxapp-). This token is used for Socket Mode connections.SLACK_CHANNEL: The ID or name of the Slack channel where messages will be posted (e.g.,C1234567890ormcp-alerts).MCP_WEBHOOK_SECRET: Your MCP Webhook Signing Secret. This is used to verify the authenticity of incoming webhooks from MyCarrierPackets.MCP_WEBHOOK_URL_PATH: The path on your server where the application will listen for MCP webhooks (default is/webhooks/mcp).PORT: The port on which the Express server will run (default is3001).PUBLIC_APP_URL: (Optional) The public URL of your application, especially useful if you're using Cloudflare Tunnel for on-premise deployment. If set, the application will log this URL at startup.
-
To start the application in production mode:
pnpm start
-
To start the application in development mode (with hot reloading using nodemon):
pnpm dev
The application will be accessible at
http://localhost:PORT(e.g.,http://localhost:3001if using the default port).
This application includes a utility to test the webhook signature verification and message formatting.
- Ensure your application is running (
pnpm startorpnpm dev). - You can send a test payload to your local webhook endpoint. The
test/webhook.jsscript can be used for this. Modifytest-payload.jsonwith the desired event type and data. - Run the test script:
This script will send the payload defined in
pnpm test:webhook
test-payload.jsonto the/webhooks/mcpendpoint of your locally running application.
This application includes a Dockerfile and docker-compose.yml for containerized deployment. Refer to those files for more details on building and running the application with Docker.
If you plan to run this application on an on-premise server and need to expose it to the public internet (e.g., to receive webhooks from MyCarrierPackets), using Cloudflare Tunnel is a recommended approach for security and simplicity.
-
Set up Cloudflare Tunnel: Follow Cloudflare's documentation to install
cloudflaredon your on-premise server and create a tunnel. Configure the tunnel to point to your application's local address (e.g.,http://localhost:3001if your application is listening on port 3001). -
Public URL: Cloudflare Tunnel will provide you with a public URL (e.g.,
https://your-tunnel-subdomain.trycloudflare.comor a custom domain likehttps://mcp-alerts.linehaul.cloud). -
Configure MCP Webhook Provider: Update your MyCarrierPackets webhook configuration to send webhooks to your public Cloudflare Tunnel URL, appending the
MCP_WEBHOOK_URL_PATH. For example:https://mcp-alerts.linehaul.cloud/webhooks/mcp. -
Environment Variable for Public URL (Optional but Recommended): You can set the
PUBLIC_APP_URLin your.envfile to your Cloudflare Tunnel's base URL (e.g.,PUBLIC_APP_URL=https://mcp-alerts.linehaul.cloud). If set, the application will log this public URL at startup for clarity.
carrier.packet.completedcarrier.incident_report.createdcarrier.incident_report.updatedcarrier.incident_report.retractedcarrier.vin_verification.completedcarrier.user_verification.completed
