# π± MCP Currency Converter App
A minimal TypeScript ChatGPT App using the Model Context Protocol (MCP) SDK with Express to provide real-time currency conversion for 160+ currencies.
## β¨ Features
- π± **Real-time Currency Conversion**: Convert between 160+ currencies
- π **Live Exchange Rates**: Up-to-date rates from exchangerate-api.com
- π¨ **Beautiful UI**: Dark mode with DaisyUI, Tailwind CSS, and Anime.js
- π± **Responsive Design**: Works on desktop, tablet, and mobile
- π **MCP Integration**: Uses @modelcontextprotocol/sdk
- π **Free to Use**: No API key required (free tier: 1500 requests/month)
- β‘ **Auto-convert**: Real-time conversion as you type
- π **Live Rates Table**: View exchange rates for major currencies
## π― Quick Start
### 1. Start the Server
```bash
chmod +x start-currency.sh
./start-currency.sh
```
### 2. Open in Browser
```
http://localhost:3001
```
That's it! No API key required for basic usage.
## π§ Optional: Use API Key for Unlimited Access
To remove the 1500 requests/month limit:
1. Get a free API key at: https://www.exchangerate-api.com/
2. Set the environment variable:
```bash
export EXCHANGE_RATE_API_KEY=your_key_here
```
3. Restart the server
## π MCP Tools Available
### 1. `convertCurrency`
Converts an amount from one currency to another.
**Parameters:**
- `from` (string): Source currency code (e.g., "USD")
- `to` (string): Target currency code (e.g., "EUR")
- `amount` (number): Amount to convert
**Example:**
```javascript
await window.openai.callTool('convertCurrency', {
from: 'USD',
to: 'EUR',
amount: 100
});
// Returns: { from: 'USD', to: 'EUR', amount: 100, result: 92.50, rate: 0.925, timestamp: '...' }
```
### 2. `getSupportedCurrencies`
Gets a list of all supported currency codes.
**Example:**
```javascript
await window.openai.callTool('getSupportedCurrencies', {});
// Returns: { currencies: { USD: 'US Dollar', EUR: 'Euro', ... }, count: 161 }
```
### 3. `getExchangeRates`
Gets all exchange rates for a base currency.
**Parameters:**
- `base` (string): Base currency code (e.g., "USD")
**Example:**
```javascript
await window.openai.callTool('getExchangeRates', { base: 'USD' });
// Returns: { base: 'USD', rates: { EUR: 0.925, GBP: 0.79, ... }, timestamp: '...' }
```
## π¨ Features Breakdown
### Auto-load Functionality
- Page automatically calls `window.openai.callTool('convertCurrency', ...)` on load
- Real-time conversion as you type or change currencies
- Instant results with smooth animations
### Converter Interface
- Select from/to currencies from dropdown
- Enter amount to convert
- See instant results
- Swap currencies with one click
- Popular conversion shortcuts
### Live Exchange Rates Table
- Shows rates for major currencies
- Updates every 60 seconds
- Based on selected "from" currency
### Responsive Design
- Mobile-friendly interface
- Touch-optimized controls
- Adapts to any screen size
## ποΈ Architecture
```
Browser
βββΊ window.openai.callTool('convertCurrency', { from, to, amount })
βββΊ POST http://localhost:3001/mcp/tools/call
βββΊ MCP Server (currency-server.ts)
βββΊ GET https://open.er-api.com/v6/latest/{currency}
βββΊ Exchange Rate API
βββΊ Returns real-time rates
```
## π Files
- **src/currency-server.ts**: MCP server with currency conversion tools
- **public-currency/index.html**: ChatGPT app frontend
- **start-currency.sh**: Startup script
- **dist/currency-server.js**: Compiled JavaScript
## π API Endpoints
| Method | Path | Description |
|--------|------|-------------|
| GET | / | Serve currency converter UI |
| GET | /mcp/tools/list | List available MCP tools |
| POST | /mcp/tools/call | Execute MCP tool |
## π Example Request
```bash
curl -X POST http://localhost:3001/mcp/tools/call \
-H "Content-Type: application/json" \
-d '{
"name": "convertCurrency",
"arguments": {
"from": "USD",
"to": "EUR",
"amount": 100
}
}'
```
**Response:**
```json
{
"from": "USD",
"to": "EUR",
"amount": 100,
"result": 92.50,
"rate": 0.925,
"timestamp": "2024-01-01T12:00:00.000Z"
}
```
## π‘ Popular Currency Pairs
The app includes quick-access buttons for:
- USD β EUR
- EUR β USD
- GBP β USD
- USD β JPY
- USD β CNY
- EUR β GBP
- AUD β USD
- USD β INR
## π― Supported Currencies
160+ currencies including:
- **USD** - US Dollar
- **EUR** - Euro
- **GBP** - British Pound
- **JPY** - Japanese Yen
- **AUD** - Australian Dollar
- **CAD** - Canadian Dollar
- **CHF** - Swiss Franc
- **CNY** - Chinese Yuan
- **INR** - Indian Rupee
- And 150+ more!
## π§ Development
### Build TypeScript
```bash
npm run build
```
### Run in Development Mode
```bash
npm run dev-currency
```
### Expose with ngrok
```bash
ngrok http 3001
```
## π Troubleshooting
### Port 3001 in use
```bash
PORT=3002 node dist/currency-server.js
```
### API rate limit exceeded
- Get a free API key at https://www.exchangerate-api.com/
- Set `EXCHANGE_RATE_API_KEY` environment variable
### Currency not found
- Check that you're using 3-letter ISO currency codes (e.g., USD, EUR)
- Use `getSupportedCurrencies` to see all available currencies
## π Technologies Used
### Backend
- TypeScript
- Express.js
- @modelcontextprotocol/sdk
- Axios
- exchangerate-api.com
### Frontend
- HTML5
- Tailwind CSS
- DaisyUI
- Anime.js
- Vanilla JavaScript
## π Future Enhancements
- [ ] Historical exchange rate charts
- [ ] Favorite currency pairs
- [ ] Offline mode with cached rates
- [ ] Currency converter calculator
- [ ] Multi-currency conversion (convert to multiple currencies at once)
- [ ] Rate alerts
## π License
MIT
---
**Built with β€οΈ using TypeScript, Express, and the Model Context Protocol**