Skip to main content
Glama
README.md
# Simple MCP Server with Add Functionality

This is a minimal MCP (Model Context Protocol) server that provides two tools:
1. **echo** - Echoes back any text you send
2. **add** - Adds two numbers together

## How it Works

This MCP server acts as a bridge between an AI Model (like Claude) and your local environment (Android tools and system commands).

### Communication Flow

The following diagram illustrates how a user prompt triggers a tool execution:

```mermaid
sequenceDiagram
    participant User
    participant AI as AI Model (Claude)
    participant MCP as MCP Server (Node.js)
    participant Tools as Android Tools (ADB/Emulator)

    User->>AI: "Are there any Android phones connected?"
    AI->>MCP: Call tool: list_android_devices
    MCP->>Tools: Execute: adb devices
    Tools-->>MCP: Return device list
    MCP-->>AI: Return tool result (JSON)
    AI-->>User: "Yes, you have 2 emulators connected..."
```

### Detailed Process
1.  **User Prompt**: You send a natural language request to the AI.
2.  **Tool Selection**: The AI identifies that the request requires a specific tool (e.g., `list_android_devices`) based on the tool descriptions provided by the MCP server.
3.  **MCP Request**: The AI sends a JSON-RPC request to the MCP server via the standard transport (stdio).
4.  **Execution**: The MCP server executes the corresponding system command (like `adb` or `emulator`) using Node.js `child_process`.
5.  **Response**: The server captures the command output and sends it back to the AI as a structured response.
6.  **AI Interpretation**: The AI interprets the raw data and provides a human-friendly answer to you.

### PlantUML Source
If you wish to render this diagram elsewhere, here is the PlantUML source:

```plantuml
@startuml
actor User
participant "AI Model (Claude)" as AI
participant "MCP Server (Node.js)" as MCP
participant "Android Tools (ADB/Emulator)" as Tools

User -> AI : "Are there any Android phones connected?"
AI -> MCP : Call tool: list_android_devices
MCP -> Tools : Execute: adb devices
Tools -> MCP : Return device list
MCP -> AI : Return tool result (JSON)
AI -> User : "Yes, you have 2 emulators connected..."
@enduml
```

## Prerequisites

- Node.js installed
- Dependencies installed (`npm install`)

## Installation

```bash
npm install
```

## Running as a Local MCP Server

### Option 1: Direct Node Execution
```bash
node server.js
```

### Option 2: Configure in Claude Desktop (or other MCP clients)

Add this to your MCP client configuration (e.g., `claude_desktop_config.json`):

```json
{
  "mcpServers": {
    "simple-calculator": {
      "command": "node",
      "args": ["d:\\work\\mcp\\mcp-min\\server.js"]
    }
  }
}
```

**Note:** Update the path in `args` to match your actual installation directory.

## Available Tools

### 1. echo
Echoes back whatever text you send.

**Input:**
- `text` (string, required): The text to echo back

**Output:**
- `echoed` (string): The echoed text

**Example:**
```json
{
  "text": "Hello, World!"
}
```

### 2. add
Adds two numbers together.

**Input:**
- `a` (number, required): First number
- `b` (number, required): Second number

**Output:**
- `result` (number): Sum of a and b

**Example:**
```json
{
  "a": 5,
  "b": 3
}
```
Returns: `{ "result": 8 }`

### 3. list_android_devices
Lists connected Android devices using the `adb` command.

**Input:**
- None

**Output:**
- `text` (string): The output of the `adb devices` command.

**Example:**
Returns: `List of devices attached\nemulator-5554\tdevice`

### 4. list_android_emulators
Lists available Android emulators (AVDs) using the `emulator -list-avds` command.

**Input:**
- None

**Output:**
- `text` (string): The list of available AVD names.

**Example:**
Returns: `Pixel_9a\nPixel_Tablet`

## Testing the Server

You can test the server by:
1. Running it directly with `node server.js`
2. Connecting it to an MCP client like Claude Desktop
3. Using the tools through the client interface

The server communicates via stdio (standard input/output), which is the standard transport for MCP servers.

## Example Prompts

Once the MCP server is connected to your client (like Claude Desktop), you can use prompts like these to trigger the tools:

### For the `add` tool:
- "Can you add 25 and 37 for me?"
- "What is the sum of 123.45 and 67.89?"
- "I have 15 apples and my friend gives me 28 more. How many do I have in total? (Use the add tool)"
- "Calculate 1024 + 2048."

### For the `echo` tool:
- "Echo the phrase 'MCP is awesome!'"
- "Can you repeat back exactly what I say: 'Testing the echo functionality'?"
- "Use the echo tool to send back 'Hello from the other side'."

### For the `list_android_devices` tool:
- "List my connected Android devices."
- "Show me all Android devices currently attached via adb."
- "Are there any Android phones connected?"

### For the `list_android_emulators` tool:
- "What Android emulators do I have available?"
- "List all my AVDs."
- "Show me the list of Android emulators I can start."

## Server Details

- **Name:** simple-mcp-server
- **Version:** 0.0.1
- **Transport:** stdio (StdioServerTransport)
- **Module Type:** ES Modules (import/export)