-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcap.py
More file actions
99 lines (80 loc) · 2.94 KB
/
cap.py
File metadata and controls
99 lines (80 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
"""Italian postal code and municipality tools."""
# MCP tool names and parameter names intentionally mirror the public API.
# pylint: disable=invalid-name
import logging
from typing import Any
from fastmcp import Context # pylint: disable=import-error
from ..mcp_core import make_api_call, mcp
from ..memory_store import OPENAPI_HOST_PREFIX
logger = logging.getLogger(__name__)
logger.debug("module loaded")
@mcp.tool
async def get_IT_regions_list(ctx: Context) -> Any:
"""
Returns the list of Italian regions
"""
url = f"https://{OPENAPI_HOST_PREFIX}cap.openapi.it/regioni"
return make_api_call(ctx, "GET", url)
@mcp.tool
async def get_IT_provinces_list(ctx: Context) -> Any:
"""
Returns the list of Italian provinces
"""
url = f"https://{OPENAPI_HOST_PREFIX}cap.openapi.it/province"
return make_api_call(ctx, "GET", url)
@mcp.tool
async def get_IT_metropolitan_cities_list(ctx: Context) -> Any:
"""
Returns the list of Italian metropolitan cities
"""
url = f"https://{OPENAPI_HOST_PREFIX}cap.openapi.it/citta_metropolitane"
return make_api_call(ctx, "GET", url)
@mcp.tool
async def get_suppressed_italian_municipalities(ctx: Context) -> Any:
"""
Returns the list of suppressed or merged Italian municipalities
"""
url = f"https://{OPENAPI_HOST_PREFIX}cap.openapi.it/comuni_soppressi"
return make_api_call(ctx, "GET", url)
@mcp.tool
async def find_IT_istat_by_comune_name(comune: str, ctx: Context) -> Any:
"""
Searches for the ISTAT code associated with a given Italian municipality.
"""
url = f"https://{OPENAPI_HOST_PREFIX}cap.openapi.it/cerca_comuni"
params = {"comune": comune}
return make_api_call(ctx, "GET", url, params=params)
@mcp.tool
async def find_IT_municipality_by_istat(istatCode: str, ctx: Context) -> Any:
"""
Retrieves detailed data about an Italian municipality using the ISTAT code:
- istat:istatCode
- comune:municipalityName
- regione:regionName
- provincia:provinceName
- prefisso:telephoneLocalPrefix
- cod_fisco:cadastralCodeor BelfioreCode of town,
- superficie:surfaceArea
- num_residenti:numberOfResidents
- nome_abitanti:inhabitantsName
- patrono.nomepatronSaintName,
- patrono.datapatronSaintDate,
- municipio:municipalityAddress
- istat_old:oldIstatCode
- sigla_provincia:provinceAbbreviation
- email:emailAddress
- pec:certifiedEmailAddress
- tel:telephoneNumber
- fax:faxNumber
- frazioni:fractions
- cap:postalCodes
"""
url = f"https://{OPENAPI_HOST_PREFIX}cap.openapi.it/comuni_advance/{istatCode}"
return make_api_call(ctx, "GET", url)
@mcp.tool
async def find_IT_municipalities_by_zip(zip_code: str, ctx: Context) -> Any:
"""
Retrieves the list of Italian municipalities and their ISTAT code based on the ZIP code.
"""
url = f"https://{OPENAPI_HOST_PREFIX}cap.openapi.it/cap/{zip_code}"
return make_api_call(ctx, "GET", url)