Renzo commited on
Commit
74c8d32
Β·
1 Parent(s): b59a94d

Add geocoding interface and about tab to Geocalc MCP server

Browse files
Files changed (6) hide show
  1. .gitignore +3 -0
  2. .python-version +1 -0
  3. app.py +38 -21
  4. pyproject.toml +11 -0
  5. tools.py +30 -0
  6. uv.lock +0 -0
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ .env
2
+ .idea
3
+ __pycache__
.python-version ADDED
@@ -0,0 +1 @@
 
 
1
+ 3.11
app.py CHANGED
@@ -1,26 +1,43 @@
1
  import gradio as gr
 
2
 
3
- def letter_counter(word, letter):
4
- """
5
- Count the number of occurrences of a letter in a word or text.
6
- Args:
7
- word (str): The input text to search through
8
- letter (str): The letter to search for
9
- Returns:
10
- str: A message indicating how many times the letter appears
11
- """
12
- word = word.lower()
13
- letter = letter.lower()
14
- count = word.count(letter)
15
- return count
16
-
17
- demo = gr.Interface(
18
- fn=letter_counter,
19
- inputs=[gr.Textbox("strawberry"), gr.Textbox("r")],
20
- outputs=[gr.Number()],
21
- title="Letter Counter",
22
- description="Enter text and a letter to count how many times the letter appears in the text."
23
  )
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  if __name__ == "__main__":
26
- demo.launch(mcp_server=True)
 
1
  import gradio as gr
2
+ from tools import get_coords_from_address
3
 
4
+ # --- Tool 1: Geocoding Interface ---
5
+ geocoding_interface = gr.Interface(
6
+ fn=get_coords_from_address,
7
+ inputs=[
8
+ gr.Textbox(label="Address", placeholder="e.g., 1600 Amphitheatre Parkway, Mountain View, CA")
9
+ ],
10
+ outputs=[
11
+ gr.Textbox(label="Coordinates (Lat, Lon)")
12
+ ],
13
+ title="Address to Coordinates",
14
+ description="A tool to get the latitude and longitude for a given street address."
 
 
 
 
 
 
 
 
 
15
  )
16
 
17
+ # --- About Tab ---
18
+ # It's good practice to have a home/about tab. We create it using gr.Blocks and gr.Markdown.
19
+ with gr.Blocks() as about_tab:
20
+ gr.Markdown("""
21
+ # 🌍 Geocalc MCP Server
22
+
23
+ Welcome to the Geocalc MCP server. This application provides a collection of tools for geographic calculations.
24
+
25
+ This server is designed to be used by AI models (like LLMs) to perform geo-related tasks.
26
+
27
+ ## Available Tools
28
+
29
+ - **Address Geocoding**: Converts a physical address into latitude and longitude coordinates.
30
+
31
+ Use the tabs above to navigate to the desired tool.
32
+ """)
33
+
34
+ # --- Assemble the Tabbed Interface ---
35
+ demo = gr.TabbedInterface(
36
+ [about_tab, geocoding_interface],
37
+ ["About", "Address Geocoding"],
38
+ title="🌍 Geocalc MCP Server"
39
+ )
40
+
41
+ # --- Launch the Server ---
42
  if __name__ == "__main__":
43
+ demo.launch(mcp_server=True)
pyproject.toml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "geocalc-mcp"
3
+ version = "0.1.0"
4
+ description = "Add your description here"
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ dependencies = [
8
+ "geopy>=2.4.1",
9
+ "gradio>=5.33.0",
10
+ "mcp>=1.9.3",
11
+ ]
tools.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from geopy.geocoders import Nominatim
2
+
3
+ def get_coords_from_address(address: str) -> str:
4
+ """
5
+ Converts a street address into latitude and longitude coordinates.
6
+
7
+ Args:
8
+ address (str): The address to search for (e.g., "Eiffel Tower, Paris").
9
+
10
+ Returns:
11
+ str: A formatted string with the coordinates "Lat: XX.XXXX, Lon: YY.YYYY"
12
+ or an error message if the address is not found.
13
+ """
14
+ print("get_coords_from_address() called with address:", address)
15
+ # 1. Initialize a geocoder. Nominatim is a great free option based on
16
+ # OpenStreetMap. It doesn't require an API key for basic use.
17
+ # geolocator = Nominatim(user_agent="geocalc_mcp_app")
18
+
19
+ # 2. Use the geocoder to find the location from the 'address' string.
20
+ # location = geolocator.geocode(address)
21
+
22
+ # 3. Check if a location was found.
23
+ # - If 'location' is not None, extract 'location.latitude' and 'location.longitude'.
24
+ # - Format the result into a string like "Lat: 48.8584, Lon: 2.2945".
25
+ # - If 'location' is None, return a clear message like "Address not found."
26
+
27
+ # For now, you can use a temporary return value to test the interface.
28
+ # For example:
29
+ # return f"Processing address: {address}"
30
+ return "Lat: 48.8584, Lon: 2.2945"
uv.lock ADDED
The diff for this file is too large to render. See raw diff