title: Utility Function Mcp
emoji: 💻
colorFrom: pink
colorTo: red
sdk: gradio
sdk_version: 6.0.1
app_file: app.py
pinned: false
license: mit
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.
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 useprice: Car price in eurosrange: Range in kilometersefficiency: Efficiency in Wh/kmacceleration: 0-100km/h time in secondsfast_charge: Fast charging power in kWseat_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 usecars: Array of car objects with the above features
Returns: JSON with the best car and all cars ranked by utility
Setup
Local Development
- Install dependencies:
pip install -e .
- Create a
.envfile with your Upstash Redis credentials:
UPSTASH_REDIS_REST_URL=https://your-redis-url.upstash.io
UPSTASH_REDIS_REST_TOKEN=your-token-here
- Run the MCP server:
python server.py
Using with Claude Desktop
Add to your claude_desktop_config.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
- User preferences (coefficients) are stored in Upstash Redis with key format
params:{user_id} - The server fetches coefficients from Redis when calculating utilities
- Features are scaled consistently with the training data
- 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