Skip to content

arush3218/LocationMCP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

LocationMCP# SongMCP

A minimal Model Context Provider (MCP) script that returns the user's current public IP-based location when run.A minimal MCP-style server (Python + FastAPI) that exposes a single tool get_song_recommendation.

What it doesEndpoints

  • GET /tools — list available tools and metadata

When you run location_mcp.py, it fetches your location using the ipinfo.io service and prints a JSON payload containing:- POST /run_tool — execute a tool. Body must match RunToolRequest (tool_name + input)

  • ip — your public IP addressQuick run (Windows PowerShell):

  • city — detected city

  • region — state/province```powershell

  • country — country code# create and activate venv (optional but recommended)

  • loc — latitude and longitude (when available)python -m venv .venv; ..venv\Scripts\Activate.ps1

  • raw — full response from ipinfo.iopip install -r requirements.txt

uvicorn SongMCP.main:app --reload --host 127.0.0.1 --port 8000

Installation```

  1. Clone this repository:Or run test client script included: python test_client.py

    git clone git@github.com:arush3218/LocationMCP.gitLightweight location MCP
    
    cd LocationMCP------------------------
    

There's also a tiny non-FastAPI MCP-style script that returns your current

  1. (Optional but recommended) Create a virtual environment:public-IP-based location when run. It uses ipinfo.io (public JSON endpoint).

    python -m venv .venvRun it with:
    
    .\.venv\Scripts\Activate.ps1
    
    ``````powershell
    

python location_mcp.py

  1. Install dependencies:```

    pip install -r requirements.txtThe script prints a compact JSON payload containing `ip`, `city`, `region`,
    
    ````country`, `loc` (latitude/longitude when available) and the full `raw`
    

response from the service.

Usage

Note: This script depends on the requests library. If it's missing, install

Run the script:it with pip install requests.


python location_mcp.py```json

```{

  "tool_name": "get_song_recommendation",

**Example output:**  "input": { "mood_or_genre": "lofi" }

}

```json```

{

  "ip": "106.51.251.74",Response: JSON with `tool_name` and `result` (list of song objects with `title` and `artist`).

  "city": "Bengaluru",
  "region": "Karnataka",
  "country": "IN",
  "loc": {
    "latitude": 12.9719,
    "longitude": 77.5937
  },
  "raw": {
    "ip": "106.51.251.74",
    "hostname": "106.51.251.74.actcorp.in",
    "city": "Bengaluru",
    "region": "Karnataka",
    "country": "IN",
    "loc": {
      "latitude": 12.9719,
      "longitude": 77.5937
    },
    "org": "AS24309 Atria Convergence Technologies Pvt. Ltd.",
    "postal": "562114",
    "timezone": "Asia/Kolkata"
  }
}

Entry Point

The entry point is location_mcp.py. When executed directly, it:

  1. Fetches location data from ipinfo.io
  2. Parses the loc field into latitude/longitude
  3. Prints a JSON payload to stdout

You can also import the get_current_location() function from other Python scripts:

from location_mcp import get_current_location

location = get_current_location()
print(location)

Error Handling

If the script cannot reach the ipinfo.io service or if the requests library is not installed, it will print an error message to stderr and exit with code 2.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages