Skip to content

karx/kaaroMCP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Kaaro MCP Server

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.

πŸš€ Features

  • 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

πŸ“ Project Structure

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

πŸ› οΈ Installation

  1. Clone the repository:
git clone <repository-url>
cd kaaroMCP
  1. Install dependencies:
npm install
  1. Build the project:
npm run build

πŸƒβ€β™‚οΈ Running the Server

Development Mode

npm run dev

Production Mode

npm start

The server will start on port 3000 by default. You can configure this using environment variables:

PORT=8080 npm start

πŸ“‘ API Endpoints

MCP Protocol

  • POST /mcp - Client-to-server communication
  • GET /mcp - Server-to-client notifications (SSE)
  • DELETE /mcp - Session termination

Health & Monitoring

  • GET /health - Health check endpoint
  • GET / - Server information

Example Health Response

{
  "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"]
  }
}

πŸ”§ Configuration

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

Production Configuration

NODE_ENV=production
PORT=8080
ALLOWED_HOSTS=yourdomain.com,api.yourdomain.com

πŸ§ͺ Testing

Run all tests

npm test

Run tests in watch mode

npm run test:watch

Generate coverage report

npm run test:coverage

Test Structure

  • Unit Tests: Individual component testing
  • Integration Tests: End-to-end API testing
  • Mocking: Console output and external dependencies

πŸ“Š Logging & Observability

The server includes comprehensive logging for observability:

Log Levels

  • INFO: General information
  • WARN: Warning conditions
  • ERROR: Error conditions
  • DEBUG: Debug information (development only)

Log Context

All logs include contextual information:

{
  "timestamp": "2024-01-14T01:38:00.000Z",
  "level": "info",
  "message": "Session initialized",
  "sessionId": "abc-123",
  "method": "POST",
  "path": "/mcp"
}

Monitoring Events

  • Session lifecycle (created, initialized, closed)
  • Request/response timing
  • Tool invocations
  • Resource access
  • Error conditions

πŸ”Œ MCP Tools & Resources

Available Tools

  • add: Addition calculator
  • multiply: Multiplication calculator

Available Resources

  • greeting://{name}: Dynamic greeting generator
  • status://server: Server status information

Example Tool Usage

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "add",
    "arguments": {
      "a": 5,
      "b": 3
    }
  }
}

πŸš€ Development

Adding New Tools

  1. Modify src/services/mcpServer.ts
  2. Add tool registration in setupTools()
  3. Include logging and error handling
  4. Add unit tests

Adding New Resources

  1. Modify src/services/mcpServer.ts
  2. Add resource registration in setupResources()
  3. Include proper URI templates
  4. Add integration tests

Code Style

  • Use TypeScript strict mode
  • Follow ESLint configuration
  • Include comprehensive error handling
  • Add logging for all major operations

πŸ“ Scripts

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

πŸ› Troubleshooting

Common Issues

  1. Port already in use:

    PORT=8080 npm start
  2. TypeScript compilation errors:

    npm run lint
  3. Test failures:

    DEBUG=true npm test

Debug Mode

Enable detailed logging:

DEBUG=true npm run dev

🀝 Contributing

  1. Create a feature branch
  2. Write tests for new functionality
  3. Ensure all tests pass
  4. Update documentation
  5. Submit a pull request

Development Workflow

# Start development server
npm run dev

# Run tests
npm test

# Check types
npm run lint

# Build for production
npm run build

πŸ“„ License

This project is licensed under the ISC License.

πŸ™‹β€β™‚οΈ Support

For questions or issues:

  1. Check the troubleshooting section
  2. Review the logs with DEBUG=true
  3. Check existing issues
  4. Create a new issue with detailed information

Made with ❀️ for the Kaaro Brain project

About

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors