location-history-mcp-server

location-history-mcp-server

A Model Context Protocol server for personal location tracking that stores GPS points, detects frequent places via clustering, and provides AI-accessible tools for querying location history, visit statistics, and place management.

Category
访问服务器

README

Location History MCP Server

A comprehensive Model Context Protocol (MCP) server for personal location tracking with intelligent place recognition, automatic clustering, and Google Places integration.

Features

  • Real-time GPS Tracking: Store location points from iOS app with high accuracy
  • Intelligent Place Detection: Automatic clustering to identify where you spend time
  • Place Recognition: Google Places API integration for automatic place naming
  • Manual Labeling: Name your frequent places (Home, Work, Gym, etc.)
  • Visit Tracking: Automatic detection of arrival/departure times
  • Travel Statistics: Distance traveled, average speed, time spent moving
  • 13 MCP Tools: Comprehensive AI-accessible location queries
  • PostGIS Support: Advanced geospatial queries and radius searches

Architecture

iOS App → location-history-mcp-server → PostgreSQL (PostGIS)
                                            ↓
                                    ChatGPT / Claude
                                   (13 MCP tools)

Available MCP Tools

Location Queries

  1. get_current_location - Your most recent GPS position
  2. get_location_history - GPS points for date range
  3. get_location_at_time - Where were you at [specific time]?
  4. search_locations_near - Find visits near coordinates/address
  5. get_travel_stats - Distance, speed, time traveled

Place Management

  1. get_frequent_places - Most visited places (sorted by visit count)
  2. list_all_places - All identified places (labeled & unlabeled)
  3. label_place - Name a place (e.g., "Home", "Equinox Gym")
  4. get_unlabeled_frequent_places - Suggest places to label

Place Queries

  1. get_place_visits - All visits to a specific place
  2. get_time_at_place - Total time spent at a place
  3. enrich_place_with_google - Get business name from Google Places API
  4. process_recent_locations - Trigger place detection/clustering

Prerequisites

  1. PostgreSQL Database with PostGIS

    • Cloud SQL instance or local PostgreSQL
    • PostGIS extension enabled
    • Same database as health-data-storage recommended
  2. Google Places API Key (Optional but recommended)

    • Enable Places API in Google Cloud Console
    • For automatic place name resolution
    • Cost: ~$0.005 per API call
  3. iOS Location Tracker App

    • See: location-tracker-ios (companion app)

Setup

1. Install Dependencies

npm install

2. Configure Environment Variables

Create .env file:

# Database (use your health-data-storage Cloud SQL connection)
DATABASE_URL=postgresql://user:pass@/health_data?host=/cloudsql/PROJECT:REGION:INSTANCE

# Google Places API (optional)
GOOGLE_PLACES_API_KEY=your_api_key_here

# User ID (your email)
DEFAULT_USER_ID=lucashanson132@gmail.com

3. Initialize Database

The server automatically creates tables on first run:

  • location_points - GPS coordinates with timestamps
  • places - Identified significant places
  • place_visits - Visit records with arrival/departure times
npm run dev

4. Deploy to Cloud Run

GOOGLE_CLOUD_PROJECT=your-project-id ./deploy.sh

iOS App Configuration

Update location-tracker-ios/LocationTracker/APIClient.swift:

private let baseURL = "https://location-history-mcp-server-xxxxx.run.app"

Update location-tracker-ios/LocationTracker/Config.swift:

static let userId = "lucashanson132@gmail.com"

Usage with ChatGPT

  1. Go to ChatGPT Settings → GPT Connectors
  2. Add server URL: https://your-server.run.app/sse
  3. Start asking questions:
"Where was I last Tuesday at 3pm?"
"How much did I travel this week?"
"How many times did I visit the gym this month?"
"Show me my most frequent places"
"Label place #5 as 'Home'"

Usage with Claude Desktop

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "location-history": {
      "url": "https://your-server.run.app/sse"
    }
  }
}

How Place Detection Works

  1. Upload: iOS app uploads GPS points in batches of 10
  2. Storage: Points stored in location_points table
  3. Clustering: Background process identifies "stops" (stayed >5 min within 50m)
  4. Place Creation: New place created or matched to existing place
  5. Visit Recording: Arrival/departure times tracked in place_visits
  6. Google Enrichment (optional): Reverse geocode to get business names
  7. Manual Labeling: You name important places

Database Schema

location_points

- id, user_id, latitude, longitude
- accuracy, altitude, speed, course
- timestamp, device_model, device_os
- place_id (FK to places)
- geom (PostGIS geography point)

places

- id, user_id, name, category
- center_lat, center_lng, radius
- address, google_place_id, google_place_name
- visit_count, created_at, updated_at
- geom (PostGIS geography point)

place_visits

- id, user_id, place_id (FK)
- arrival_time, departure_time, duration_minutes

API Endpoints

  • POST /upload - iOS app uploads location batches
  • GET /health - Health check
  • GET /sse - MCP SSE transport
  • POST /message - MCP message handler
  • GET /tools - List available MCP tools

Example Queries

"Where was I yesterday at 2pm?"

Tool: get_location_at_time
Args: { timestamp: "2025-10-26T14:00:00Z" }
Returns: Lat/lng coordinates

"How long did I spend at work this week?"

Tool: get_time_at_place
Args: {
  place_name: "Work",
  start_date: "2025-10-20T00:00:00Z",
  end_date: "2025-10-27T00:00:00Z"
}
Returns: Total hours, visit count, average visit duration

"What are my most visited places?"

Tool: get_frequent_places
Returns: Sorted list with visit counts, coordinates, names

Privacy & Security

  • Your Data: All location data stays in your Cloud SQL database
  • No Third-party Storage: MCP server doesn't store data, only queries it
  • Optional Google API: Use only when you explicitly enrich a place
  • User Control: You decide which places to label and share with AI

Development

# Local development
npm run dev

# Build TypeScript
npm run build

# Run production
npm start

Cost Considerations

  • Cloud Run: Free tier covers typical personal use
  • Cloud SQL: Shared with health-data-storage, no additional cost
  • Google Places API: ~$0.005/call, only used for enrichment
  • Total: Typically $0-3/month for personal use

Troubleshooting

No locations appearing

  • Check iOS app is uploading: look for "✅ Successfully uploaded" logs
  • Verify DATABASE_URL in Cloud Run environment variables
  • Run health check: curl https://your-server.run.app/health

Places not being detected

  • Ensure you're staying in one location for 5+ minutes
  • Manually trigger: use process_recent_locations tool
  • Check clustering settings in PlacesAnalyzer constructor

Google Places not working

  • Verify GOOGLE_PLACES_API_KEY is set in Cloud Run
  • Enable Places API in Google Cloud Console
  • Check API quotas and billing

Support

For issues:

  1. Check Cloud Run logs: gcloud run services logs read location-history-mcp-server
  2. Verify database connectivity
  3. Check iOS app logs

License

MIT License


Built with Model Context Protocol and deployed on Google Cloud Run

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选
mcp-server-qdrant

mcp-server-qdrant

这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。

官方
精选
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选