A robust Model Context Protocol (MCP) server implementation for the Kaaro Brain agent interface. This project has been refactored for maintainability, observability, and team collaboration.
- MCP Protocol Support: Full implementation of the Model Context Protocol for AI agent communication
- Session Management: Robust session handling with automatic cleanup
- Comprehensive Logging: Detailed logging for debugging and monitoring
- Health Monitoring: Built-in health check endpoints
- TypeScript: Full type safety and modern development experience
- Testing: Comprehensive unit and integration tests
- Modular Architecture: Clean separation of concerns for maintainability
kaaroMCP/
βββ src/
β βββ types/ # TypeScript type definitions
β βββ utils/ # Utility functions (logger, etc.)
β βββ services/ # Business logic services
β βββ routes/ # HTTP route handlers
β βββ middleware/ # Express middleware
β βββ app.ts # Main application class
β βββ index.ts # Application entry point
βββ tests/ # Unit and integration tests
βββ dist/ # Compiled JavaScript output
βββ package.json # Dependencies and scripts
βββ tsconfig.json # TypeScript configuration
βββ jest.config.js # Test configuration
βββ README.md # This file
- Clone the repository:
git clone <repository-url>
cd kaaroMCP- Install dependencies:
npm install- Build the project:
npm run buildnpm run devnpm startThe server will start on port 3000 by default. You can configure this using environment variables:
PORT=8080 npm start- POST /mcp - Client-to-server communication
- GET /mcp - Server-to-client notifications (SSE)
- DELETE /mcp - Session termination
- GET /health - Health check endpoint
- GET / - Server information
{
"status": "healthy",
"timestamp": "2024-01-14T01:38:00.000Z",
"server": {
"name": "kaaro-mcp-server",
"version": "1.0.0",
"uptime": 125.5
},
"sessions": {
"activeSessions": 2,
"sessionIds": ["session-123", "session-456"]
}
}The server can be configured through environment variables:
| Variable | Default | Description |
|---|---|---|
PORT |
3000 |
Server port |
NODE_ENV |
development |
Environment mode |
DEBUG |
false |
Enable debug logging |
ALLOWED_HOSTS |
127.0.0.1,localhost |
Comma-separated allowed hosts |
NODE_ENV=production
PORT=8080
ALLOWED_HOSTS=yourdomain.com,api.yourdomain.comnpm testnpm run test:watchnpm run test:coverage- Unit Tests: Individual component testing
- Integration Tests: End-to-end API testing
- Mocking: Console output and external dependencies
The server includes comprehensive logging for observability:
- INFO: General information
- WARN: Warning conditions
- ERROR: Error conditions
- DEBUG: Debug information (development only)
All logs include contextual information:
{
"timestamp": "2024-01-14T01:38:00.000Z",
"level": "info",
"message": "Session initialized",
"sessionId": "abc-123",
"method": "POST",
"path": "/mcp"
}- Session lifecycle (created, initialized, closed)
- Request/response timing
- Tool invocations
- Resource access
- Error conditions
- add: Addition calculator
- multiply: Multiplication calculator
- greeting://{name}: Dynamic greeting generator
- status://server: Server status information
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "add",
"arguments": {
"a": 5,
"b": 3
}
}
}- Modify
src/services/mcpServer.ts - Add tool registration in
setupTools() - Include logging and error handling
- Add unit tests
- Modify
src/services/mcpServer.ts - Add resource registration in
setupResources() - Include proper URI templates
- Add integration tests
- Use TypeScript strict mode
- Follow ESLint configuration
- Include comprehensive error handling
- Add logging for all major operations
| Script | Description |
|---|---|
npm start |
Start production server |
npm run dev |
Start development server |
npm run build |
Build TypeScript to JavaScript |
npm test |
Run all tests |
npm run test:watch |
Run tests in watch mode |
npm run test:coverage |
Generate test coverage |
npm run lint |
Type check without compilation |
npm run clean |
Clean build and coverage |
-
Port already in use:
PORT=8080 npm start
-
TypeScript compilation errors:
npm run lint
-
Test failures:
DEBUG=true npm test
Enable detailed logging:
DEBUG=true npm run dev- Create a feature branch
- Write tests for new functionality
- Ensure all tests pass
- Update documentation
- Submit a pull request
# Start development server
npm run dev
# Run tests
npm test
# Check types
npm run lint
# Build for production
npm run buildThis project is licensed under the ISC License.
For questions or issues:
- Check the troubleshooting section
- Review the logs with
DEBUG=true - Check existing issues
- Create a new issue with detailed information
Made with β€οΈ for the Kaaro Brain project