Skip to main content
Glama
MCP Dynamic HTML App

MCP Dynamic HTML App

by vikkysarswat
README.md
# ๐Ÿš€ MCP Dynamic HTML App

A Python-based Model Context Protocol (MCP) server that demonstrates **dynamic HTML rendering with live data** for ChatGPT applications.

## ๐ŸŽฏ What This Does

This app showcases how to build a **dynamic ChatGPT app** where:
- HTML is rendered based on **live data** (not static assets)
- Data is fetched from a simulated database
- Content changes dynamically based on user queries
- Perfect for dashboards, reports, and data visualizations

## ๐Ÿ—๏ธ Architecture

Based on the **Server-Side Dynamic HTML Rendering** pattern:

```
ChatGPT โ†’ MCP Tool Call โ†’ Python Server โ†’ Fetch DB Data โ†’ Render HTML โ†’ Return to ChatGPT
```

## ๐Ÿ“ฆ Features

โœ… **Three Dynamic Tools:**
1. **`get_dynamic_dashboard`** - Live metrics dashboard with theme support
2. **`get_user_profile`** - User profile cards with real-time data
3. **`get_metrics_table`** - Interactive data tables (sales, performance, engagement)

โœ… **Simulated Database** - No setup required, works out of the box

โœ… **Beautiful HTML** - Modern, responsive designs with CSS

โœ… **Easy Deployment** - Deploy to Railway, Render, or any Python hosting

## ๐Ÿš€ Quick Start

### 1. Clone the Repository

```bash
git clone https://github.com/vikkysarswat/mcp-dynamic-html-app.git
cd mcp-dynamic-html-app
```

### 2. Install Dependencies

```bash
pip install -r requirements.txt
```

### 3. Run the Server

```bash
python server.py
```

## ๐Ÿ”ง How to Use

### With Claude Desktop (Recommended)

Add to your `claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "dynamic-html": {
      "command": "python",
      "args": ["/path/to/mcp-dynamic-html-app/server.py"]
    }
  }
}
```

### Example Prompts

```
"Show me the dashboard"
"Get user profile for user_001"
"Display sales metrics table"
"Show me performance metrics with dark theme"
```

## ๐Ÿ“ Project Structure

```
mcp-dynamic-html-app/
โ”œโ”€โ”€ server.py           # Main MCP server with tool definitions
โ”œโ”€โ”€ database.py         # Simulated database with sample data
โ”œโ”€โ”€ html_renderer.py    # HTML rendering templates
โ”œโ”€โ”€ requirements.txt    # Python dependencies
โ””โ”€โ”€ README.md          # This file
```

## ๐Ÿ› ๏ธ Customization

### Add Your Own Data Source

Replace the simulated database in `database.py`:

```python
import sqlite3

async def get_user_data(user_id: str):
    conn = sqlite3.connect('your_database.db')
    cursor = conn.cursor()
    cursor.execute("SELECT * FROM users WHERE id = ?", (user_id,))
    return cursor.fetchone()
```

### Create Custom HTML Templates

Add new rendering functions in `html_renderer.py`:

```python
def render_custom_view(data):
    return f"""
    <!DOCTYPE html>
    <html>
        <!-- Your custom HTML -->
    </html>
    """
```

### Add New Tools

Extend the tools list in `server.py`:

```python
@server.list_tools()
async def handle_list_tools():
    return [
        # ... existing tools
        types.Tool(
            name="your_custom_tool",
            description="Your tool description",
            inputSchema={...}
        )
    ]
```

## ๐Ÿšข Deployment Options

### Deploy to Railway

1. Fork this repository
2. Go to [Railway.app](https://railway.app)
3. Click "New Project" โ†’ "Deploy from GitHub"
4. Select this repository
5. Railway will auto-detect Python and deploy

### Deploy to Render

1. Go to [Render.com](https://render.com)
2. Click "New" โ†’ "Background Worker"
3. Connect your GitHub repository
4. Set build command: `pip install -r requirements.txt`
5. Set start command: `python server.py`

### Deploy to Heroku

```bash
heroku create your-app-name
git push heroku main
```

## ๐Ÿ“Š Example Use Cases

- **Business Dashboards** - Real-time KPIs and metrics
- **User Management** - Dynamic user profiles and lists
- **Data Reports** - Interactive tables and charts
- **Analytics Views** - Performance and engagement tracking
- **Admin Panels** - System monitoring and alerts

## ๐Ÿงช Testing

Test the tools directly:

```python
import asyncio
from database import get_user_data
from html_renderer import render_user_card

async def test():
    user = await get_user_data("user_001")
    html = render_user_card(user)
    print(html)

asyncio.run(test())
```

## ๐Ÿ“š Learn More

- [MCP Documentation](https://modelcontextprotocol.io/)
- [Claude AI](https://claude.ai)
- [MCP Python SDK](https://github.com/modelcontextprotocol/python-sdk)

## ๐Ÿค Contributing

Contributions welcome! Feel free to:
- Add new HTML templates
- Create additional tools
- Improve the database layer
- Add tests

## ๐Ÿ“„ License

MIT License - feel free to use this in your projects!

## ๐ŸŽ‰ Credits

Created by Nilesh Vikky based on MCP dynamic HTML rendering patterns.

---

**Happy Building! ๐Ÿš€**

If you have questions or need help, open an issue or reach out!