File size: 2,898 Bytes
293f790
 
 
 
 
 
 
 
 
 
b837f59
 
293f790
 
 
b8a2da5
 
 
b837f59
 
b383738
 
 
b837f59
 
 
 
 
b8a2da5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
---
title: Utility Function Mcp
emoji: 💻
colorFrom: pink
colorTo: red
sdk: gradio
sdk_version: 6.0.1
app_file: app.py
pinned: false
license: mit
tags:
  - building-mcp-track-consumer
---

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference

# EV Utility Function MCP Server

An MCP (Model Context Protocol) server that provides utility function calculations for electric vehicles based on user preferences. Contributors: benjosaur, reuzed, MJ141592

**Train your own function here**
https://autofinder.onrender.com

Demo:
https://drive.google.com/file/d/1Z-PoQgvLaEBnhMk8nwrKOnRj8sOKz-QH/view?usp=sharing

Ig Social Media Post:
https://www.instagram.com/p/DRsxbbWCl0m/?img_index=6&igsh=MWoxc3ZrOTM2ZWxhbA==

## Features

This MCP server exposes two tools:

### 1. `calculate_utility`

Calculate the utility score for a single car based on a user's trained preferences.

**Parameters:**

- `user_id`: Username whose utility function to use
- `price`: Car price in euros
- `range`: Range in kilometers
- `efficiency`: Efficiency in Wh/km
- `acceleration`: 0-100km/h time in seconds
- `fast_charge`: Fast charging power in kW
- `seat_count`: Number of seats

**Returns:** JSON with utility score and coefficients used

### 2. `find_best_car`

Find the best car from an array based on a user's utility function.

**Parameters:**

- `user_id`: Username whose utility function to use
- `cars`: Array of car objects with the above features

**Returns:** JSON with the best car and all cars ranked by utility

## Setup

### Local Development

1. Install dependencies:

```bash
pip install -e .
```

2. Create a `.env` file with your Upstash Redis credentials:

```bash
UPSTASH_REDIS_REST_URL=https://your-redis-url.upstash.io
UPSTASH_REDIS_REST_TOKEN=your-token-here
```

3. Run the MCP server:

```bash
python server.py
```

### Using with Claude Desktop

Add to your `claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "ev-utility": {
      "command": "python",
      "args": ["/path/to/utility-mcp-server/server.py"],
      "env": {
        "UPSTASH_REDIS_REST_URL": "https://your-redis-url.upstash.io",
        "UPSTASH_REDIS_REST_TOKEN": "your-token-here"
      }
    }
  }
}
```

## Hugging Face Space

This server is also available as a Hugging Face Space for easy web-based access and demonstration.

## How It Works

1. User preferences (coefficients) are stored in Upstash Redis with key format `params:{user_id}`
2. The server fetches coefficients from Redis when calculating utilities
3. Features are scaled consistently with the training data
4. Utility is calculated as a dot product: `utility = Σ(coefficient_i × scaled_feature_i)`

## Default Coefficients

If a user_id is not found in Redis, default coefficients are used:

- price: -0.5
- range: 0.8
- efficiency: -0.3
- acceleration: -0.5
- fast_charge: 0.6
- seat_count: 0.4