MCP Tools Reference: mapstools.googleapis.com

工具:compute_routes

計算指定起點和目的地之間的路線。支援的交通方式:開車 (預設)、步行。

輸入規定 (重要):必須提供來源和目的地。請使用下列其中一種方法,在各自的欄位中提供這些資訊:

  • address: (字串,例如「Eiffel Tower, Paris」)。注意:輸入的地址越精細或具體,結果就越準確。

  • 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"}

  • 如有 attribution 欄位資訊,系統必須使用該資訊將基礎輸出內容歸因於來源。

下列程式碼範例說明如何使用 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": {
      // Provide these details according to the MCP tool specification.
    }
  },
  "jsonrpc": "2.0",
  "id": 1
}'

輸入內容的結構定義

ComputeRoutesRequest。

ComputeRoutesRequest

JSON 表示法
{
  "origin": {
    object (Waypoint)
  },
  "destination": {
    object (Waypoint)
  },
  "travelMode": enum (RouteTravelMode)
}
欄位
origin

object (Waypoint)

必填。起點航點。

destination

object (Waypoint)

必填。目的地路線控點。

travelMode

enum (RouteTravelMode)

(選用步驟) 指定交通方式。

途經點

JSON 表示法
{

  // Union field location_type can be only one of the following:
  "latLng": {
    object (LatLng)
  },
  "placeId": string,
  "address": string
  // End of list of possible types for union field location_type.
}
欄位
聯集欄位 location_type。表示位置的不同方式。location_type 只能是下列其中一項:
latLng

object (LatLng)

使用地理座標指定的點。

placeId

string

與途經點相關聯的地點 ID。

address

string

使用者容易理解的地址或 Plus Code。詳情請參閱 https://plus.codes。

LatLng

JSON 表示法
{
  "latitude": number,
  "longitude": number
}
欄位
latitude

number

緯度度數,必須介於 [-90.0, +90.0] 的範圍之間。

longitude

number

經度度數,必須介於 [-180.0, +180.0] 的範圍之間。

RouteTravelMode

用來指定交通方式的一組值。

列舉
ROUTE_TRAVEL_MODE_UNSPECIFIED 未指定交通方式。預設值為 DRIVE。
DRIVE 搭乘客車。
WALK 步行:注意:WALK 路線目前為 Beta 版,有時可能無法提供明確的人行道或行人路徑。您必須向使用者顯示這項警告,提醒他們應用程式中顯示的所有步行活動。

輸出內容的結構定義

ComputeRoutesResponse。

ComputeRoutesResponse

JSON 表示法
{
  "routes": [
    {
      object (Route)
    }
  ]
}
欄位
routes[]

object (Route)

包含所要求起點和目的地之間的路線。目前只會傳回一條路線。

路線

JSON 表示法
{
  "distanceMeters": integer,
  "duration": string,
  "attribution": {
    object (Attribution)
  }
}
欄位
distanceMeters

integer

路線的移動距離 (以公尺為單位)。

duration

string (Duration format)

導覽路線所需的時間長度。

以秒為單位的時間長度,最多 9 個小數位數,結尾為「s」。示例:"3.5s"。

attribution

object (Attribution)

顯示路線時必須提供出處資訊。

時間長度

JSON 表示法
{
  "seconds": string,
  "nanos": integer
}
欄位
seconds

string (int64 format)

時間範圍的簽署秒數。必須介於 -315,576,000,000 至 +315,576,000,000 之間 (含這兩個值)。注意:這些界限是根據以下公式計算得出:60 秒/分 * 60 分/時 * 24 時/天 * 365.25 天/年 * 10000 年

nanos

integer

時間跨度 (以奈秒為單位) 的正負秒數。如果時間長度不到一秒,系統會以 0 seconds 欄位和正數或負數 nanos 欄位表示。如果時間長度為一秒以上,nanos 欄位的非零值必須與 seconds 欄位相同。必須介於 -999,999,999 至 +999,999,999 之間 (含)。

歸因

JSON 表示法
{
  "title": string,
  "url": string
}
欄位
title

string

要顯示的著作權聲明標題。

url

string

用於歸因的連結網址。

工具註解

工具註解會傳送至 MCP 用戶端,說明特定工具的基本風險。大多數用戶端會將這些提示視為不受信任,但可用於決定何時可能向使用者傳送確認提示。

除了標題字串,以下布林值提示的定義如下:

  • readOnlyHint:如果為 true,工具不會修改環境。預設值為 false。
  • destructiveHint:如果為 true,工具可以執行破壞性動作。如果為 false,工具只能執行加法動作。預設值為 true。
  • idempotentHint:如果為 true,以相同引數重複呼叫工具時,不會對環境產生額外影響。預設值為 false。
  • openWorldHint:設為 true 時,工具可與外部實體的「開放世界」互動。如果為 false,工具只能與內部實體互動。舉例來說,網路搜尋工具屬於開放世界,記憶體工具則不屬於開放世界。

破壞性提示:❌ | 等冪提示:❌ | 唯讀提示:✅ | 開放世界提示:❌