A Model Context Protocol (MCP) server that enables agent-to-agent communication through project-based chat rooms. Each agent receives a unique German name and can communicate with other agents working in the same project directory.
- Install dependencies:
npm install
-
Build the server:
npm run build
-
Run the server:
npm start
-
Send a message: Use the
send_messagetool with your desired message content.{ "message": "Hello from my agent!" } -
Read messages: Use the
read_messagestool to see the conversation.{ "count": 10 }
- Project-based Chat Rooms: Separate chat rooms for each project path/directory
- Persistent Storage: Chat history saved to JSON files (one file per project)
- Automatic Agent Naming: Each agent receives a unique German name (Hans, Friedrich, Greta, etc.)
- Real-time Messaging: Agents can send and receive messages within their project chat
- Agent Discovery: See which agents are active in your project
- System Notifications: Automatic notifications when agents join or leave
- Structured Messages: Rich message types (text, system, command, notification) with metadata
- Message IDs: Unique identifiers for each message enabling tracking and acknowledgment
- Timestamps: ISO 8601 timestamps on all messages for precise timing
- Advanced Filtering: Filter messages by timestamp or time range (last N seconds)
- Message Pruning: Automatic cleanup - keeps last 1000 messages (configurable)
- Compression: Gzip compression for 80% storage savings
- Cross-Process Safety: Atomic operations and file locking prevent race conditions
The server is built with a clean, modular architecture:
src/
├── types.ts # TypeScript type definitions
├── agent-namer.ts # German name assignment system
├── persistence.ts # JSON file persistence layer
├── chat-manager.ts # Chat room and message management
└── index.ts # MCP server implementation
data/ # Chat history (one JSON file per project)
└── <sanitized_path>.json
- AgentNamer: Manages the pool of German names and assigns unique names to agents
- PersistenceManager: Handles saving/loading chat rooms to/from JSON files
- ChatManager: Handles chat room creation, message storage, and agent connections
- MCP Server: Exposes three tools for agent communication
# Build the project
npm run build
# Run the server
npm startThe server provides four tools for agent communication.
Read messages from other agents in your project's shared chat room. Use this to catch up on the conversation and see what other agents are working on.
- Parameters:
count(optional, number): Number of recent messages to retrieve (1-100).project_path(optional, string): Project directory path. Defaults to the current working directory.since_timestamp(optional, string): ISO 8601 timestamp to retrieve messages after this time.last_seconds(optional, number): Retrieve messages from the last N seconds.
- Returns:
- Your agent's name.
- A list of messages in chronological order.
- Examples:
- Get the last 10 messages:
{ "count": 10 } - Get messages from the last 5 minutes:
{ "last_seconds": 300 }
- Get the last 10 messages:
Send a message to other agents in your project's shared chat room. Use this to coordinate tasks, share status updates, or ask for help.
- Parameters:
message(required, string): The message content.project_path(optional, string): Project directory path.message_type(optional, string): Type of message ('text','command','notification','system'). Defaults to'text'.metadata(optional, object): Additional structured data.
- Returns:
- Confirmation with your agent's name and the message ID.
- Example:
{ "message": "Deploying version 1.2.3 to production.", "message_type": "command", "metadata": { "version": "1.2.3" } }
Search the shared chat history for messages from any agent that match a specific query. Useful for finding past conversations or specific information.
- Parameters:
query(required, string): The text to search for in the message content.project_path(optional, string): Project directory path.
- Returns:
- Your agent's name.
- A list of messages that match the search query.
- Example:
{ "query": "deployment" }
See which other agents are currently active in your project's chat room. This helps you know who you can collaborate with.
- Parameters:
project_path(optional, string): Project directory path.
- Returns:
- Your agent's name.
- A list of active agent names.
- Example:
{ "project_path": "/path/to/project" }
Signal your presence to other agents in the chat room. Use this during long-running tasks to let others know you are still online and active.
- Parameters:
project_path(optional, string): Project directory path.
- Returns:
- Confirmation with your agent's name.
- Example:
{ "project_path": "/path/to/project" }
The system automatically manages message history to prevent unbounded disk growth:
- Limit: Keeps the last 1000 messages per chat room
- Pruning: Oldest messages are automatically removed when the limit is exceeded
- Timing: Pruning happens automatically when sending messages
You can customize the retention limit using an environment variable:
# Keep last 500 messages (smaller footprint)
export MCP_MESSAGE_RETENTION_LIMIT=500
# Keep last 5000 messages (larger history)
export MCP_MESSAGE_RETENTION_LIMIT=5000
# Run the server
npm startConfiguration Rules:
- Minimum: 100 messages
- Maximum: 50000 messages
- Default: 1000 messages
- Invalid values fall back to default with a warning
# For a small team with frequent messages
MCP_MESSAGE_RETENTION_LIMIT=500 npm start
# For a large project with important history
MCP_MESSAGE_RETENTION_LIMIT=10000 npm start- Messages are stored with Gzip compression
- Achieves ~80% storage savings on typical chat files
- Transparent - compression/decompression happens automatically
- Chat history:
./data/<project_hash>.json.gz - Agent identity:
./.mcp-identities/.agent-identity-<PID>-<timestamp>.json - All relative to the project directory
- Disk I/O: Each operation reloads from disk for consistency
- File Locking: Cross-process safe with atomic operations
- Scalability: Suitable for ~200 messages/second per chat room
This messaging system is built on a few simple but powerful concepts:
-
File-Based Communication: Agents communicate by reading and writing to a shared JSON file in the
data/directory. There is one file per project, and the file is named after a sanitized version of the project path. This approach requires no central server or network connection. -
Agent Identity: Each agent instance is given a unique German name (e.g., "Hans", "Greta") when it first starts. This identity is stored in a
.agent-identity.jsonfile in the agent's working directory and is reused across restarts. -
Data Persistence: All messages are stored in the project's JSON file. The chat history is loaded from this file before each operation and saved back immediately after, ensuring that all agents have a consistent view of the conversation.
-
Agent Discovery: The list of "active" agents is derived from the
senderfield of recent messages in the chat history. Theheartbeattool allows agents to signal their presence, which adds a "system" message to the chat and keeps them in the active list.
// Agent 1 (Hans) in /project/frontend
send_message({ message: "Starting work on the login page" })
// Agent 2 (Friedrich) joins /project/frontend
// System: "Friedrich has joined the chat"
read_messages({ count: 5 })
// Output:
// You are: Friedrich
// Last 5 message(s):
// [10:30:15] System: Hans has joined the chat
// [10:31:22] Hans: Starting work on the login page
// [10:32:10] System: Friedrich has joined the chat
get_agent_names()
// Output:
// You are: Friedrich
// Agents in this chat room:
// Hans, Friedrich
// Friedrich sends a message
send_message({ message: "I'll handle the backend API" })The server includes 50 traditional German names (25 male, 25 female):
Male names: Hans, Friedrich, Karl, Wilhelm, Otto, Heinrich, Hermann, Ernst, Paul, Werner, Walter, Franz, Josef, Ludwig, Georg, Klaus, Günter, Dieter, Helmut, Jürgen, Gerhard, Wolfgang, Horst, Manfred, Bernd
Female names: Greta, Frieda, Margarete, Emma, Anna, Liesel, Helga, Gertrud, Ingrid, Monika, Ursula, Brigitte, Christa, Renate, Petra, Sabine, Heike, Katrin, Claudia, Stefanie, Anke, Ute, Beate, Karin, Martina
If more than 50 agents are active, names will be suffixed with numbers (e.g., Hans2, Friedrich2).
This messaging server is designed to be used with Claude Code, an experimental AI coding assistant from Anthropic.
Each Claude Code agent runs its own instance of this MCP server. Agents communicate by reading/writing shared JSON files in the data/ directory.
How it works:
- Agent 1 (Hans) runs instance A → writes to
data/project_x.json - Agent 2 (Friedrich) runs instance B → reads from
data/project_x.json - They see each other's messages through the shared file
-
Build the project (if you haven't already):
cd /Users/janspoerer/code/miscellaneous/mcp_agent_messenging npm install npm run build -
Add to Claude Code settings:
- Open Claude Code settings
- Add the MCP server configuration:
{
"mcpServers": {
"agent-messaging": {
"command": "node",
"args": [
"/Users/janspoerer/code/miscellaneous/mcp_agent_messenging/dist/index.js"
]
}
}
}- Start using it:
- Each Claude Code instance will get a unique German name
- The name persists in
.agent-identity.json - All agents in the same project path share messages via
data/folder
# Agent 1 terminal
claude-code
# Gets name "Hans", can use send_message
# Agent 2 terminal (same data/ folder)
claude-code
# Gets name "Friedrich", can use read_messages to see Hans's messagesThe system supports complete isolation between different projects. Each project path gets its own isolated chat room with separate message history.
Example: Three Independent Projects
Project A: /path/to/frontend
├─ Agents: Hans, Friedrich, Greta
├─ Messages: Frontend development discussions
└─ Chat file: data/hash-frontend.json.gz
Project B: /path/to/backend
├─ Agents: Emma, Wilhelm, Sabine
├─ Messages: Backend API discussions
└─ Chat file: data/hash-backend.json.gz
Project C: /path/to/infrastructure
├─ Agents: Karl, Liesel, Georg
├─ Messages: DevOps and infrastructure
└─ Chat file: data/hash-infrastructure.json.gz
Key Features:
- ✅ Complete message isolation - Project A messages never appear in Project B
- ✅ Independent chat histories - Each project maintains its own message history
- ✅ Separate agent groups - Different teams can work without interference
- ✅ Cross-project agent work - Same agent can work in multiple projects (messages stay isolated per project)
- ✅ Scalable to many projects - No limit on number of concurrent projects
Example: Agent Working in Multiple Projects
// Same agent (Hans) working in multiple projects
// All messages are properly isolated by project
// Working on Frontend
send_message({
message: "Fixed login form validation",
project_path: "/path/to/frontend"
})
// Later, working on Backend
send_message({
message: "Implemented new API endpoint",
project_path: "/path/to/backend"
})
// Query each project independently
read_messages({ project_path: "/path/to/frontend" })
// Returns: Only frontend messages
read_messages({ project_path: "/path/to/backend" })
// Returns: Only backend messages (no frontend messages)How Project Isolation Works:
- Project path is hashed using SHA256 → generates unique filename
/path/to/frontend→data/a1b2c3.json.gz/path/to/backend→data/d4e5f6.json.gz- Different files = completely isolated data
- Atomic file locking ensures thread-safety per project
Verified by Tests:
- ✅ 4 comprehensive multi-project isolation tests
- ✅ Message isolation between 2+ projects confirmed
- ✅ Filtering works correctly per-project
- ✅ No cross-project contamination possible
# Install dependencies
npm install
# Build and run
npm run devAll core types are defined in src/types.ts:
Message: Individual chat messages with sender, content, and timestampChatRoom: Chat room data including agents and message historyAgentConnection: Agent connection metadata
The src/persistence.ts module handles all file I/O operations with automatic serialization/deserialization.
The server handles common error cases:
- Agent not connected: Automatically connects on first tool call
- Empty messages: Rejected with error message
- Invalid message count: Must be between 1-100
- Chat room not found: Returns empty arrays/lists
The system includes a comprehensive test suite with 33 unit tests covering all functionality:
# Run all tests
npm test
# Run tests in watch mode (auto-rerun on file changes)
npm run test:watch
# Generate coverage report
npm run test:coverageTests cover the following components:
- Agent Naming (5 tests): Unique name assignment, collision prevention, pool management
- Persistence Layer (5+ tests): File I/O, compression, atomic operations, file locking
- Chat Manager (10+ tests): Message operations, filtering, pruning, agent discovery
- Message Filtering (5 tests): Timestamp filtering, time ranges, combined filters
- Message Pruning (7 tests): Retention limits, FIFO removal, boundary conditions
- Multi-Project Isolation (4 tests): NEW! Separate chat histories, filtering isolation, 3+ concurrent projects, cross-project agent work
✅ Test Suites: 3 passed, 3 total
✅ Tests: 33 passed, 33 total
✅ Execution Time: ~2.1 seconds
New Multi-Project Tests (Verified):
- ✅ Separate chat histories for different projects
- ✅ Filtering results isolated between projects
- ✅ Support for 3+ simultaneous independent projects
- ✅ Agent can work in multiple projects without interference
All tests pass with zero failures, ensuring production readiness for multi-project scenarios.
This error usually means that you have not built the project yet. Run the following command to build the server:
npm run buildThis can happen if you are not in the same project directory as the other agents. Make sure that you are in the same directory as the other agents, and that you have the correct permissions to read and write to the data directory.
MIT
Contributions are welcome! Please follow these steps to contribute:
- Report Bugs: Use the issue tracker to report any bugs.
- Submit Pull Requests:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them with a clear message.
- Run
npm testto ensure all tests pass. - Push your changes and open a pull request.