Skip to main content
Glama
NitinUdasin

MCPServerDemo

by NitinUdasin
README.md
# JSON RPC Server with FastAPI and Python

This project implements a simple JSON-RPC server using FastAPI, Uvicorn, and jsonrpcserver in Python. It exposes `add` and `multiply` methods.

## Setup

1.  **Clone the repository:**
    ```bash
    git clone <your-repo-url>
    cd json-rpc-server
    ```

2.  **Create a virtual environment and install dependencies using `uv`:**
    ```bash
    uv venv
    .\.venv\Scripts\activate # On Windows
    # source .venv/bin/activate # On Linux/macOS
    uv pip install fastapi uvicorn jsonrpcserver
    ```

## Running the Server

To start the development server with auto-reloading:

```bash
.\.venv\Scripts\activate # On Windows
# source .venv/bin/activate # On Linux/macOS
uv run python -m uvicorn main:app --reload
```

The server will run at `http://127.0.0.1:8000/`.

## API Endpoints

### GET /

A simple test endpoint to confirm the server is running.

**Request:**

```bash
# Using curl (Linux/macOS/Git Bash)
curl http://127.0.0.1:8000/

# Using Invoke-RestMethod (PowerShell)
Invoke-RestMethod -Uri "http://127.0.0.1:8000/" -Method Get
```

**Response:**

```json
{
  "message": "FastAPI is running!"
}
```

### POST / (JSON-RPC 2.0)

This is the main JSON-RPC endpoint for `add` and `multiply` methods.

#### Add Method

**Request:**

```bash
# Using curl
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "add", "params": [2, 3], "id": 1}' http://127.0.0.1:8000/

# Using Invoke-RestMethod (PowerShell)
Invoke-RestMethod -Uri "http://127.0.0.1:8000/"   -Method Post -Headers @{ "Content-Type" = "application/json" }   -Body '{"jsonrpc":"2.0","method":"add","params":[2,3],"id":1}'
```

**Response (Example):**

```json
{"jsonrpc": "2.0", "result": 5, "id": 1}
```

#### Multiply Method

**Request:**

```bash
# Using curl
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "multiply", "params": [4, 5], "id": 1}' http://127.0.0.1:8000/

# Using Invoke-RestMethod (PowerShell)
Invoke-RestMethod -Uri "http://127.0.0.1:8000/"  -Method Post -Headers @{ "Content-Type" = "application/json" }  -Body '{"jsonrpc":"2.0","method":"multiply","params":[4,5],"id":1}'
```

**Response (Example):**

```json
{"jsonrpc": "2.0", "result": 20, "id": 1}
```

#### Multipl Methods in a sigal call 
```bash
curl -X POST -H "Content-Type: application/json" -d '[{"jsonrpc": "2.0", "method": "add", "params": [2, 3], "id": 1},{"jsonrpc": "2.0", "method": "multiply", "params": [2, 30], "id": 2}]' http://127.0.0.1:8000/


Invoke-RestMethod -Uri "http://127.0.0.1:8000/" -Method Post -Headers @{ "Content-Type" = "application/json" }  -Body '[{"jsonrpc":"2.0","method":"add","params":[2,3],"id":1},{"jsonrpc":"2.0","method":"multiply","params":[2,30],"id":2}]'
```

## Install fastmcp
```bash
uv add fastmcp
```

## Run MCP inspector 
```bash 
uv run fastmcp dev inspector TestMPCserver.py 
```

## Run MCP server 
```bash 
uv run fastmcp run TestMPCserver.py
```


## Connect to cluade-desktop 
```bash
uv run fastmcp install claude-desktop TestMPCserver.py
```

##  Run MCP server 
```bash
uv run fastmcp run DataprovidersMCPServer.py
```

## Connect to cluade-desktop 
```bash
uv run fastmcp install claude-desktop DataprovidersMCPServer.py
```

```bash
uv add langchain langchain-openai langchain-mcp-adapters python-dotenv streamlit logging pandas fastmcp python-dotenv jsonrpcserver uvicorn streamlit langchain-ollama fastapi
```

```bashe
 uvicorn serversendevent:app
```


```bashe
 uvicorn Streamable:app
```

## Streaming HTTP Demo

This project includes a streaming HTTP endpoint demonstration using FastAPI's `StreamingResponse`.

### Start the Stream Server

```bash
uv run uvicorn Streamable:app --reload
```

The server will run at `http://127.0.0.1:8000/stream` and sends 10 chunks with 1-second intervals.

### Run the Stream Client

```bash
python StreamableClient.py
```

The client demonstrates both async and synchronous methods to consume the streaming response.

### Test with curl

```bash
# Using curl (Linux/macOS/Git Bash)
curl http://127.0.0.1:8000/stream

# Using Invoke-RestMethod (PowerShell)
Invoke-RestMethod -Uri "http://127.0.0.1:8000/stream" -Method Get
```

## VS Code Debugging

A `launch.json` file is provided in the `.vscode` directory to enable debugging with VS Code. You can set breakpoints in `main.py` and run the "Python: FastAPI" configuration.

TDQS

B3.1/5.0

Scored across 1 tool

Disambiguation5/5

With only one tool, there is no possibility of ambiguity or overlap between tools. The tool 'add' has a clear and distinct purpose of adding two numbers, leaving no room for confusion or misselection by an agent.

Naming Consistency5/5

Since there is only one tool named 'add', naming consistency is inherently perfect. There are no other tools to compare against, so no inconsistencies in patterns, styles, or conventions can arise.

Tool Count2/5

A single tool is too few for most server purposes, as it severely limits functionality and scope. For a server named 'MCPServerDemo', which suggests a broader demonstration or utility set, one tool feels thin and inadequate, indicating a likely mismatch with the intended scope.

Completeness1/5

The tool surface is severely incomplete, as it only covers a basic arithmetic operation (adding two numbers) with no other related operations like subtraction, multiplication, or division. This leaves significant gaps for any practical use case, making it impossible to handle a full range of tasks in the implied domain of mathematical or utility functions.

Maintenance

ActivityInactive
ResponsivenessNo issues