内容
# WhereAmI MCP Server



一个轻量级的 mcp server,它会根据您当前的 IP 告诉您您在哪里,由 [ipapi.co](https://ipapi.co/) 提供支持。
## Features
- **Dynamic Resources**:通过 `location://{type}` 获取特定数据(例如,IP、国家、城市)。
- **Detailed Tool**:使用 `get_location()` 生成全面的位置报告。
- **Natural Language Prompt**:询问“我在哪里?”以获得详细结果。
- **Robust Error Handling**:优雅地管理 API 和网络问题。
- **Minimal Dependencies**:仅需要 `mcp` 和 `httpx`。
## Installation
### Prerequisites
- Python 3.10+
- `pip`
### Setup
1. 克隆存储库:
```bash
git clone https://github.com/kukapay/whereami-mcp.git
cd whereami-mcp
```
2. 安装依赖项:
```bash
pip install mcp httpx
```
3. (可选)作为 MCP 服务安装:
```bash
mcp install whereami_mcp.py --name "WhereAmI"
```
## Usage
### Running the Server
- 直接执行:
```bash
python whereami_mcp.py
```
- 开发模式:
```bash
mcp dev whereami_mcp.py
```
### Components
#### Resource: `location://{type}`
根据 `{type}` 返回特定的位置详细信息。
- **Supported Types**:`ip`、`country`、`country_code`、`region`、`city`、`latitude`、`longitude`、`timezone`、`isp`、`asn`
- **Examples**:
- `@location://ip` → `"8.8.8.8"`
- `@location://city` → `"Mountain View"`
- `@location://country` → `"United States"`
#### Tool: `get_location()`
生成地理位置数据的详细 Markdown 表格。
- **Fields**:
- IP
- Country
- Country Code
- Region
- City
- Latitude
- Longitude
- Timezone
- ISP
- ASN
- **Sample Output**:
```
| Field | Value |
|----------------|-------------------|
| IP | 8.8.8.8 |
| Country | United States |
| Country Code | US |
| Region | California |
| City | Mountain View |
| Latitude | 37.4223 |
| Longitude | -122.0848 |
| Timezone | America/Los_Angeles |
| ISP | GOOGLE |
| ASN | AS15169 |
```
#### Prompt: `where_am_i_prompt`
预定义的查询:“请根据我当前的 IP 地址告诉我我在哪里。” 触发 `get_location()`。
### Examples in Claude Desktop
1. 安装服务器:
```bash
mcp install whereami_mcp.py --name "WhereAmI"
```
2. 查询数据:
- "My IP is `@location://ip`"
- "I’m in `@location://city`, `@location://country`"
3. 获取完整报告:
- "Where am I?"
- `get_location()`
## License
MIT License. See [LICENSE](LICENSE) for details.