Labsco
phamtienduceng logo

SSE Calculator

from phamtienduceng

A stateful calculator server using Server-Sent Events (SSE) for real-time communication.

๐Ÿ”ฅโœ“ VerifiedFreeAdvanced setup

SSE Calculator MCP Server

A stateful calculator server that uses Server-Sent Events (SSE) for real-time communication. This server implements the Model Context Protocol (MCP) for integration with AI assistants.

Features

  • Real-time calculator operations using SSE
  • Stateful sessions for ongoing calculations
  • History tracking for all calculations
  • Web-based calculator interface
  • MCP integration for AI assistants

Architecture

The server is built using NestJS and implements the following components:

  • Session Service: Manages calculator sessions and state
  • Calculator Service: Performs calculation operations
  • SSE Controller: Handles client connections and event streaming

API Endpoints

SSE Stream

GET /calculator/stream

Establishes an SSE connection and creates a new calculator session.

Calculate

POST /calculator/calculate/:sessionId

Performs a calculation operation on the specified session.

Request body:

{
  "operation": "add", // add, subtract, multiply, divide, clear
  "a": 5,
  "b": 3
}

History

GET /calculator/history/:sessionId

Retrieves the calculation history for the specified session.

Sessions

GET /calculator/sessions

Retrieves all active calculator sessions.

MCP Integration

To use this server as an MCP server, add the following configuration to your MCP settings file:

{
  "mcpServers": {
    "remote-calculator": {
      "url": "http://localhost:3000/calculator/stream",
      "disabled": false,
      "alwaysAllow": [],
      "timeout": 60
    }
  }
}

Hosting Your Own MCP Server

After deploying your server, update your MCP client configuration to point to your hosted URL:

{
  "mcpServers": {
    "remote-calculator": {
      "url": "https://your-deployed-url.com/calculator/stream",
      "disabled": false,
      "alwaysAllow": [],
      "timeout": 60
    }
  }
}