MCP 工具參考資料:
本文說明用於叫用 Google 遠端 Model Context Protocol (MCP) 工具的對外 REST API 端點。這個 API 可做為外部 HTTP 用戶端 (例如 curl 或網路服務) 與內部 MCP 伺服器之間的 Proxy,確保連線安全。
取得 MCP 工具規格
如要取得 MCP 伺服器中所有工具的 MCP 工具規格,請使用 `tools/list` 方法。以下範例說明如何使用 curl 列出 MCP 伺服器中目前可用的所有工具及其規格。
| Curl 要求 |
|---|
curl --location 'https://mapstools.googleapis.com/mcp' --header 'content-type: application/json' --header 'accept: application/json, text/event-stream' --data '{ "method": "tools/list", "jsonrpc": "2.0", "id": 1 }' |
工具:search_places
當使用者要求尋找地點、商家、地址、位置、景點或任何其他 Google 地圖相關搜尋時,請呼叫這項工具。
輸入規定 (重要):
text_query(字串 - 必填):主要搜尋查詢。這項資訊必須清楚定義使用者要尋找的內容。- 示例:
'restaurants in New York'、'coffee shops near Golden Gate Park'、'SF MoMA'、'1600 Amphitheatre Pkwy, Mountain View, CA, USA'、'pets friendly parks in Manhattan, New York'、'date night restaurants in Chicago'、'accessible public libraries in Los Angeles'。
- 如要取得特定地點的詳細資料:請加入要求的屬性 (例如
'Google Store Mountain View opening hours'、'SF MoMa phone number'、'Shoreline Park Mountain View address')。
- 示例:
location_bias(物件 - 選用):使用這個參數,優先顯示特定地理區域附近的結果。- 格式:
{"location_bias": {"circle": {"center": {"latitude": [value], "longitude": [value]}, "radius_meters": [value (optional)]}}}
- 使用方式:
- 如要將半徑設為 5 公里:
{"location_bias": {"circle": {"center": {"latitude": 34.052235, "longitude": -118.243683}, "radius_meters": 5000}}} - 如要強烈偏向中心點:
{"location_bias": {"circle": {"center": {"latitude": 34.052235, "longitude": -118.243683}}}}(省略radius_meters)。
- 如要將半徑設為 5 公里:
- 格式:
language_code(字串 - 選用):顯示搜尋結果摘要的語言。- 格式:雙字母語言代碼 (ISO 639-1),後面可選擇加上底線和雙字母國家/地區代碼 (ISO 3166-1 alpha-2),例如
en、ja、en_US、zh_CN、es_MX。如未提供語言代碼,結果會以英文顯示。
- 格式:雙字母語言代碼 (ISO 639-1),後面可選擇加上底線和雙字母國家/地區代碼 (ISO 3166-1 alpha-2),例如
region_code(字串 - 選用):使用者的 Unicode CLDR 區域代碼。這個參數用於顯示地點詳細資料,例如特定地區的地點名稱 (如有)。根據適用法律,這項參數可能會影響結果。- 格式:由兩個英文字母組成的國家/地區代碼 (ISO 3166-1 alpha-2),例如
US,CA。
- 格式:由兩個英文字母組成的國家/地區代碼 (ISO 3166-1 alpha-2),例如
工具呼叫的指示:
位置資訊 (重要):搜尋內容必須包含足夠的位置資訊。如果地點不明確 (例如只有「披薩店」),您必須在
text_query中指定地點 (例如 「紐約市的披薩店」),或使用location_bias參數。如需消歧,請加入城市、州/省和區域/國家/地區名稱。請盡量提供最具體且語境豐富的
text_query。只有在明確提供座標,或從使用者已知情境推斷位置資訊適當且有助於提升結果品質時,才使用
location_bias。
下列範例示範如何使用 curl 叫用 search_places MCP 工具。
| Curl 要求 |
|---|
curl --location 'https://mapstools.googleapis.com/mcp' --header 'content-type: application/json' --header 'accept: application/json, text/event-stream' --data '{ "method": "tools/call", "params": { "name": search_places, arguments: { // please fill these details according to tools MCP specification } }, "jsonrpc": "2.0", "id": 1 }' |
工具:lookup_weather
提供任何地點的目前天氣狀況、每小時和每日預報。如要提出天氣相關問題,請使用這項工具。
可用的特定資料:溫度 (目前、體感、最高/最低、熱指數)、風 (風速、陣風、風向)、天象 (日出/日落、月相)、降水 (類型、機率、量/QPF)、大氣狀況 (紫外線指數、濕度、雲量、雷雨機率) 和地理編碼位置地址。
輸入規定 (重要):
目前狀況:只需要位置資訊 (例如城市或地址)。請勿指定日期或小時。
每小時天氣預報:需要位置資訊和小時 (0-23)。如果使用者詢問特定時間的天氣,或使用「接下來幾小時」或「今天稍晚」等字詞,請使用這個意圖。
每日預報:必須提供位置和完整日期。
日期處理 (重要):使用者提供的日期和時間必須以所要求地點的當地時區為準。日期必須分成不同的整數參數:年、月和日。這些參數的必要格式為:{"year":
下列範例示範如何使用 curl 叫用 lookup_weather MCP 工具。
| Curl 要求 |
|---|
curl --location 'https://mapstools.googleapis.com/mcp' --header 'content-type: application/json' --header 'accept: application/json, text/event-stream' --data '{ "method": "tools/call", "params": { "name": lookup_weather, arguments: { // please fill these details according to tools MCP specification } }, "jsonrpc": "2.0", "id": 1 }' |
工具:compute_routes
計算指定起點和目的地之間的路線。支援的交通方式:DRIVE (預設)、WALK。
輸入規定 (重要):必須同時提供出發地和目的地。您必須使用下列其中一種方法,在各自的欄位中提供這些資訊:
地址: (字串,例如 「巴黎艾菲爾鐵塔」)。注意:輸入的地址越精細或具體,結果就越準確。
lat_lng: (物件,{"latitude": number, "longitude": number})
place_id: (字串,例如 'ChIJOwE_Id1w5EAR4Q27FkL6T_0') 注意:這個 ID 可從 search_places 工具取得。允許使用任何輸入類型組合 (例如:起點為地址,目的地為 lat_lng)。如果缺少來源或目的地,請務必先請使用者釐清,再嘗試呼叫工具。
工具呼叫範例:{"origin":{"address":"Eiffel Tower"},"destination":{"place_id":"ChIJt_5xIthw5EARoJ71mGq7t74"},"travel_mode":"DRIVE"}
下列範例示範如何使用 curl 叫用 compute_routes MCP 工具。
| Curl 要求 |
|---|
curl --location 'https://mapstools.googleapis.com/mcp' --header 'content-type: application/json' --header 'accept: application/json, text/event-stream' --data '{ "method": "tools/call", "params": { "name": compute_routes, arguments: { // please fill these details according to tools MCP specification } }, "jsonrpc": "2.0", "id": 1 }' |