This is theArcGIS Advent Calendar 2025 article for day 24. Please be sure to check out the other articles as well.
Introduction
This year was another year filled with continuous discussions about AI and development,1.
In ArcGIS, GeoAI is of course progressing, along with the development of AI features such as the AI assistant available in each product and the upcoming AI agents,AI assistant and upcoming AI agent, building ageospatial AI platform.
Among these topics related to AI and development, Model Context Protocol (MCP) stands out as a particularly noteworthy technology.
In this article, using FastMCP, which allows easy construction of MCP servers, we will create an MCP server as shown below that enables the use of ArcGIS routing functionality in an AI chat app utilizing large language models (hereafter LLM) .
Example configuration of MCP server connecting AI chat app and routing functionality
What is Model Context Protocol (MCP)?
MCP is an open protocol that allows LLMs to safely and uniformly interact with external tools (such as Web APIs). This technology was developed and proposed by Anthropic, a well-known AI company behind Claude, and is widely supported by AI app developers. Many AI chat apps support MCP, making it one of the hottest LLM-related technologies this year.
In the field of geospatial information as well, theNational Land Transportation Data Platform, a portal site for geospatial information in Japan, has published anMCP server.
Main software and libraries used in this article
Below is a list of software that can connect to MCP and libraries useful for building MCP servers used in this article.
A framework that allows easy and fast construction of MCP servers/clients in Python; in this article, it will be used to create an MCP server.
The desktop app version of the AI chat app Claude provided by Anthropic; in this article, it will be used as an MCP host to connect to the MCP server and verify correct operation.
A free source code editor provided by Microsoft; in this article, its extension GitHub Copilot Chat will be used as an MCP host similarly to Claude Desktop.
"f": "json",
"token": token,
"stops": ";".join(f"{x},{y}" for (x, y) in stops),
"returnDirections": str(return_directions).lower(),
"startTime": depart
}
url = ARCGIS_ROUTING_URL + "?" + urllib.parse.urlencode(params)
with urllib.request.urlopen(url, timeout=30) as resp:
return json.loads(resp.read())
if __name__=="__main__":
stops=[(139.745486, 35.658569),(139.749603, 35.660191)]
result = _call_arcgis_route(stops, API_KEY, return_directions=True,depart="now")
if "error" in result:
raise RuntimeError(result["error"])
print(result)
上記のスクリプトで、2点間のルート検索を行うことができます。
スタート地点を東京タワー、ゴール地点を芝公園の緯度経度を入力しているので実行してみるとルートの詳細を JSON 形式で返してくれています。
Python スクリプトを実行した結果
なお、今回はチャットの文章でルート検索ができるようにしたいので、
上記のスクリプトに住所検索とルート検索で移動手段を指定する際に利用する移動手段のエンド ポイントにリクエストする関数を追加しています。
追加した例が下記のスクリプトです。
import json
import urllib.parse
import urllib.request
GEOCODE_FIND_URL = "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates"
ARCGIS_ROUTING_URL = "https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World/solve"
ARCGIS_TRAVELMODE_URL = "https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World/retrieveTravelModes"
API_KEY ="<事前に用意した API キー>"
def _http_get(url: str) -> dict:
with urllib.request.urlopen(url, timeout=30) as resp:
return json.loads(resp.read())
def geocode_address(address: str, token: str, country_code: str = "JP") -> dict:
"""
住所や都市名、POI から 緯度経度へ変換する。
"""
params = {
"f": "json",
"token": token,
"SingleLine": address,
"countryCode": country_code,
"outFields": "*",
"langCode": "ja",
"maxLocations": 1
}
url = GEOCODE_FIND_URL + "?" + urllib.parse.urlencode(params)
result = _http_get(url)
if "error" in result:
raise RuntimeError(result["error"])
for c in result.get("candidates", []):
loc = c.get("location") or {}
return {
"lon": loc.get("x"),
"lat": loc.get("y"),
}
def _travel_mode_selector(travelMode: str, token: str):
"""
travelMode 引数から ArcGIS Routing の travelMode 名を返す。
"""
params = {
"f": "json",
"token": token
}
url = ARCGIS_TRAVELMODE_URL + "?" + urllib.parse.urlencode(params)
travelmode_list=_http_get(url)["supportedTravelModes"]
# 一致した文字列があれば travelmode として返す。
for travelmode in travelmode_list:
if travelmode["name"]== travelMode:
travelmode_param=travelmode
break
return travelmode_param
def _call_arcgis_route(stops, token, return_directions=True, travel_mode="運転時間", depart="now"):
params = {
"f": "json",
"token": token,
"stops": ";".join(f"{x},{y}" for (x, y) in stops),
"returnDirections": str(return_directions).lower(),
"travelMode": travel_mode, # 追加
"startTime": depart, # now / yyyy-mm-ddThh:mm:ss
}
url = ARCGIS_ROUTING_URL + "?" + urllib.parse.urlencode(params)
return _http_get(url)
if __name__=="__main__":
stops=["東京タワー","芝公園"]
result = _call_arcgis_route(stops, API_KEY, return_directions=True,depart="now")
if "error" in result:
raise RuntimeError(result["error"])
print(result)
FastMCP で MCP サーバー化
FastMCP は MCP サーバー/クライアントを Python で簡単・高速に構築できるフレームワークです。
ここからは上記で作成した Python スクリプトを FastMCP を使って MCP サーバー化していきましょう。
FastMCP のインストール
FastMCP は pip からライブラリをインストールできます。
pip install fastmcp
上記のコマンドを実行したあとで FastMCP がインストールされているか下記のスクリプトを実行して試してみましょう。
インストールした時点での最新版がインストールされているはずです。
import fastmcp
print(fastmcp.__version__)
# >> 2.xyz.x
ArcGIS Routing MCP サーバーを作成する
ここまで作成してきたルート検索用のエンド ポイントにリクエストを送信する Python スクリプトに FastMCP ライブラリをインポートし、MCP サーバーを立ち上げるためのスクリプトを記述していきます。
追加したスクリプトが下記となります。追加したコマンドや関数には、コメント アウトで追加した旨を記載してあります。
import json
import urllib.parse
import urllib.request
from fastmcp import FastMCP # 追加
mcp = FastMCP("ArcGIS Routing MCP Server") # 追加
GEOCODE_FIND_URL = "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates"
ARCGIS_ROUTING_URL = "https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World/solve"
ARCGIS_TRAVELMODE_URL = "https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World/retrieveTravelModes"
API_KEY ="<Pre-prepared API key>"
def _http_get(url: str) -> dict:
with urllib.request.urlopen(url, timeout=30) as resp:
return json.loads(resp.read())
def geocode_address(address: str, token: str, country_code: str = "JP") -> dict:
"""
Convert from address, city name, or POI to latitude and longitude.
"""
params = {
"f": "json",
"token": token,
"SingleLine": address,
"countryCode": country_code,
"outFields": "*",
"langCode": "ja",
"maxLocations": 1
}
url = GEOCODE_FIND_URL + "?" + urllib.parse.urlencode(params)
result = _http_get(url)
if "error" in result:
raise RuntimeError(result["error"])
for c in result.get("candidates", []):
loc = c.get("location") or {}
return {
"lon": loc.get("x"),
"lat": loc.get("y"),
}
def _travel_mode_selector(travelMode: str, token: str):
"""
Returns the ArcGIS Routing travelMode name from the travelMode argument.
"""
params = {
"f": "json",
"token": token
}
url = ARCGIS_TRAVELMODE_URL + "?" + urllib.parse.urlencode(params)
travelmode_list=_http_get(url)["supportedTravelModes"]
# Return travelmode if a matching string is found.
for travelmode in travelmode_list:
if travelmode["name"]== travelMode:
travelmode_param=travelmode
break
return travelmode_param
def _call_arcgis_route(stops, token, return_directions=True, travel_mode="Driving Time", depart="now"):
params = {
"f": "json",
"token": token,
"stops": ";".join(f"{x},{y}" for (x, y) in stops),
"returnDirections": str(return_directions).lower(),
"travelMode": travel_mode, # Added
"startTime": depart, # now / yyyy-mm-ddThh:mm:ss
}
url = ARCGIS_ROUTING_URL + "?" + urllib.parse.urlencode(params)
return _http_get(url)
# Added from here
@mcp.tool()
def solve_route(
stop_list: list,
depart: str = "now",
travelMode: str = "Driving Time",
) -> dict:
"""
Calls ArcGIS Routing's Route_World and returns the shortest/fastest route and directions.
Args:
stop_list: List of waypoint names (list of address strings)
depart: Departure time ("now" or ISO8601). Defaults to "now" if not specified.
travelMode: Mode of transportation ("Driving Time", "Driving Distance", "Walking Time", "Walking Distance", "Truck Transport Time", "Truck Transport Distance", "Driving Time (Unpaved Roads)", "Driving Distance (Unpaved Roads)"). Defaults to "Driving Time" if not specified.
Returns:
Dictionary containing route shape, time, distance, and directions (in Japanese if possible).
"""
stops=[]
for stop in stop_list:
geocode_result=geocode_address(stop, API_KEY)
stops.append((geocode_result["lon"], geocode_result["lat"]))
result = _call_arcgis_route(stops, API_KEY, return_directions=True, travel_mode=_travel_mode_selector(travelMode, API_KEY), depart=depart)
if "error" in result:
raise RuntimeError(result["error"])
return result # MCP tool return value can be JSON/object as is.
# Added up to here
if __name__ == "__main__":
mcp.run() # Added here.
# Comment out below.
# stops=["Tokyo Tower","Shiba Park"]
# result = _call_arcgis_route(stops, API_KEY, return_directions=True,depart="now")
# if "error" in result:
# raise RuntimeError(result["error"])
# print(result)
ここでのポイントは @mcp.tool 下の関数が LLM の利用するツールとしてスクリプトやツールの説明文を記述している点です。LLM が MCP サーバーを参照する際には、ここに記載の説明文を確認してリクエストする際に必要な引数の JSON を作成します。そのため、利用するのに必要となる引数のデータ型の指定と説明をコメント アウト内に記載し、LLM が使い方を間違えないようにします。
このスクリプトを実行して問題なければ下図のようにローカルで MCP サーバーが立ち上がるようになります。
MCP サーバーの起動
ここまで記述してきたスクリプトでも Claude Desktop に設定可能ですが、
本当に実行できるか試してみるために FastMCP ライブラリで MCP クライアントも作って試してみましょう。
MCP サーバーをクライアントで呼び出してみる
クライアント側では、MCP サーバーで設定されたツールを呼び出すように
下記のようなスクリプトを記述しておきます。
import asyncio
from fastmcp import Client
from fastmcp.client.transports import PythonStdioTransport
async def main():
# サーバーを起動
transport = PythonStdioTransport(script_path="./arcgis_route.py")
# MCP クライアントを作成し、MCP サーバーに接続
async with Client(transport) as client:
# solve_route ツールの呼び出し
result = await client.call_tool("solve_route",
{
"stop_list": ["東京駅","東京タワー"],
"travelMode": "運転時間"
}
)
print("ツール呼び出し結果:", result)
if __name__ == "__main__":
asyncio.run(main())
ここでは、クライアントから MCP サーバーを起動しているため、スクリプトを実行するとルート検索の結果が表示されるようになっています。
実際に実行してみた結果は下図の通りです。
MCPクライアントを実行
ArcGIS Routing MCP サーバーが正しく動作していていることがわかったので、
次に LLM で利用できるか確認するために Claude Desktop で実行してみましょう。
Claude Desktop で利用してみよう
Claude Desktop は Anthropic 社が提供する AI チャット アプリ Claude のデスクトップ アプリで、ローカル ファイルや外部ツールとの連携が実現できます。
Claude Desktop でローカルの MCP サーバーを実行するにはいくつか準備が必要です。
ここでは、その準備を行った後に Claude Desktop で ArcGIS Routing MCP を使ってみましょう。
Claude Desktop 側の設定
'claude_desktop_config.json' opened in code editor shows empty `{}`.
'{}' is replaced as below.
'{'
' \"mcpServers\": {'
' \"arcgis-routing-mcp\": {'
' \"command\": \"<absolute path to python environment>\\python.exe\",'
' \"args\": [ '
' \"<absolute path to script>\\arcgis_route.py\"'
' ]'
' }' claude_desktop_config.json` が生成されます。
`claude_desktop_config.json` をコード エディターで開くと空の `{}` が用意されています。
この中括弧を下記のように書き換えます。
{
"mcpServers": {
"arcgis-routing-mcp": {
"command": "<python 環境への絶対パス>\\python.exe",
"args": [
"<スクリプトの絶対パス>\\arcgis_route.py"
]
}
}
}
設定後、 1度 Claude Desktop を閉じる必要がありますが、注意していただきたい点は右上の×ボタンでウィンドウを閉じるのではなく、左上のハンバーガー メニューをクリックして表示される「終了」をクリックし、アプリを完全に終了させる必要があります。Claude Desktop のタスクが残っている状態ですので、タスク マネージャー等から Claude Desktop のタスクを削除しておきます。
Claude Desktop を閉じる手順
ここまで問題なければ再度 Claude Desktop を立ち上げるとチャットの入力欄の `+` ボタンをクリックして出てくるコネクタと設定の「開発者」の項目に ArcGIS Routing MCP が追加されているはずです。
コネクタに追加された様子
「開発者」項目に追加された様子
Claude Desktop で ArcGIS Routing MCP を使ってみる
立ち上げた Claude Desktop で ArcGIS Routing MCP を使ってルート検索をしてみましょう。
動画内でも確認していますが solve_route と書いてあるプルダウン メニューを押すと実際にリクエストした JSON とレスポンスされた JSON が閲覧できます。
最後に出力してもらった結果が正しそうかこのルート検索の結果を GeoJSON 化してもらい、ArcGIS Online の Map Viewerで描画してみましょう。
Claude に GeoJSON 化を依頼
ルートを GeoJSON で書き出した結果
出力された GeoJSON も間違いなさそうです。
ここまでで FastMCP を使うことで ArcGIS のルート検索機能 を LLM で利用できていることを確認できました。
様々な用途が考えられますが、LLM だけでは到達できないタスクを MCP で外部ツールにアクセスすることで達成できるようになりました。
最後に Visual Studio Code でも利用できるか試してみましょう。
Visual Studio Code でも使えるのか
MCP のメリットの 1 つとして挙げられるのは、あらゆる LLM に対応できるという点です。こちらを確認するために Visual Studio Code の GitHub Copilot Chat でも ArcGIS Routing MCP が使えるか試してみました。
Visual Studio Code の設定
Visual Studio Code での設定は GitHub アカウントにあらかじめサイン インをしたうえでGitHub Copilot と GitHub Copilot Chat の拡張機能をインストールしておきます。
上記の設定が完了している状態でしたら MCP サーバーを使えるように `mcp.jsonSet `.
`mcp.json` Open the MCP server directory in Visual Studio Code and create it inside the `.vscode` directory within the same directory.
`mcp.json` configuration is similar to Claude Desktop but differs in details, so please be careful.
{
"servers": {
"arcgis-routing-mcp": {
"type": "stdio",
"command": "<absolute path to python environment>\\python",
"args": ["arcgis_route.py"],
}
}
}
If the above settings are correct, `mcp.json` will display strings like `Start` as shown in the figure above under arcgis-routing-mcp. Try clicking `Start`.
mcp.json Settings
If there are no issues with the created MCP server script or the description in `mcp.json`, the `Start` section will be labeled as `Running` .
Let's actually try it with GitHub Copilot Chat .
Using GitHub Copilot Chat ArcGIS Routing MCP
Run GitHub Copilot Chat
It seems to produce results equivalent to those obtained when running on Claude Desktop.
As done with Claude Desktop, have it output GeoJSON and check it here as well on ArcGIS Online