- Explore MCP Servers
- mcp-message-bus
Mcp Message Bus
What is Mcp Message Bus
mcp-message-bus is a project that demonstrates a server-driven Mastra agent responding to the MCP Server via a message bus architecture, where the environment controls the agent’s behavior based on external events.
Use cases
Use cases include automated responses in chat environments, monitoring and responding to user interactions in real-time, and enhancing user engagement through dynamic conversations.
How to use
To use mcp-message-bus, clone the repository, set up your environment variables in a .env file, install dependencies using pnpm, and start the development server with pnpm dev.
Key features
Key features include message persistence per channel, event notifications for new messages, and the ability for the agent to maintain conversation history and respond only to newly arrived messages.
Where to use
mcp-message-bus can be used in applications that require real-time communication, such as chatbots, customer support systems, and collaborative platforms.
Clients Supporting MCP
The following are the main client software that supports the Model Context Protocol. Click the link to visit the official website for more information.
Overview
What is Mcp Message Bus
mcp-message-bus is a project that demonstrates a server-driven Mastra agent responding to the MCP Server via a message bus architecture, where the environment controls the agent’s behavior based on external events.
Use cases
Use cases include automated responses in chat environments, monitoring and responding to user interactions in real-time, and enhancing user engagement through dynamic conversations.
How to use
To use mcp-message-bus, clone the repository, set up your environment variables in a .env file, install dependencies using pnpm, and start the development server with pnpm dev.
Key features
Key features include message persistence per channel, event notifications for new messages, and the ability for the agent to maintain conversation history and respond only to newly arrived messages.
Where to use
mcp-message-bus can be used in applications that require real-time communication, such as chatbots, customer support systems, and collaborative platforms.
Clients Supporting MCP
The following are the main client software that supports the Model Context Protocol. Click the link to visit the official website for more information.
Content
MCP Message Bus Example
This project demonstrates a server-driven Mastra agent that responds on the message bus to the MCP Server, showcasing the agentic paradigm where the environment drives the agent, rather than the agent driving itself.
Overview
The MCP Message Bus example simulates an environment where:
- An agent subscribes to a chat resource (like a Discord channel)
- The agent listens for new messages via notifications
- The agent responds only to newly arrived messages while tracking conversation history
- All interactions flow through a message bus architecture
This implementation pattern puts the environment (MCP Server) in control, where the agent’s behavior is driven by external events rather than by the agent’s internal logic.
Prerequisites
- Node.js 16+
- pnpm
- OpenAI API key
Getting Started
- Clone this repository
- Copy
.env.exampleto.envand set your environment variables:
OPENAI_API_KEY=your_openai_api_key_here OPENAI_API_URL=https://api.openai.com/v1 # Optional, defaults to OpenAI's API
- Install dependencies:
pnpm install
- Start the development server:
pnpm dev
How It Works
-
The
FakeMcpClientsimulates an MCP server with:- Message persistence per channel/room
- Event notifications
- Message sending capabilities
-
The
BaseChatAgentprovides the core agent functionality:- Subscribing to chat resources
- Processing notifications
- Maintaining conversation state
- Generating responses only for new messages
-
The demo automatically:
- Loads an initial backlog of messages
- Simulates a new message arriving after 5 seconds
- Generates a response using the Mastra agent
- Sends the response back to the chat resource
Architecture
index.ts- Main entry point and fake MCP client implementationBaseChatAgent.ts- Core agent implementation that handles subscriptions and responseschatResources.ts- Interface between the agent and MCP clientchatSchemas.ts- Type definitions and validation for chat messages
Customization
You can modify the agent’s behavior by:
- Changing the model in
index.ts - Updating the system instructions
- Implementing your own MCP client for a real deployment
License
ISC
Dev Tools Supporting MCP
The following are the main code editors that support the Model Context Protocol. Click the link to visit the official website for more information.










