返回市场
街景视图-mcp

街景视图-mcp

作者:vlad-ds7 星标更新:2025-05-14

项目介绍

Street View MCP

一个用于Google Street View API的Model-Client-Protocol (MCP)服务器,使AI模型能够获取并显示街景图像,并创建虚拟游览。

使用Claude Desktop

要在Claude Desktop中使用Street View MCP:

  1. 确保已安装uvUV安装指南
  2. 克隆此仓库:
    git clone https://github.com/vlad-ds/street-view-mcp.git
    cd street-view-mcp
    
  3. 安装依赖项:
    uv pip install -e ".[dev]"
    
  4. 获取Google Maps API密钥(见下文)
  5. 在Claude Desktop的claude_desktop_config.json文件中添加以下内容:
"street_view": {
  "command": "uv",
  "args": [
    "run",
    "--directory",
    "/path/to/street-view-mcp",  // 替换为实际路径
    "mcp",
    "run",
    "src/street_view_mcp/server.py"
  ],
  "env": {
    "API_KEY": "your_google_maps_api_key_here"  // 添加您的API密钥
  }
}

配置完成后,您只需在Claude Desktop中键入"/street_view"即可使用Street View MCP。

概述

Street View MCP提供了一个简单的接口供AI模型使用:

  1. 根据地址、坐标或全景ID获取Street View图像
  2. 将图像保存到本地文件
  3. 在默认查看器中打开保存的图像
  4. 创建HTML页面,将多个Street View图像编译成虚拟游览

要求

  • Python 3.9+
  • 启用了Street View API的Google Maps API密钥
  • fastmcp
  • uv包管理器(推荐)

安装

# 克隆仓库
git clone https://github.com/vlad-ds/street-view-mcp.git
cd street-view-mcp

# 使用uv创建并激活虚拟环境(推荐)
uv venv
source .venv/bin/activate  # 在Windows上:.venv\Scripts\activate

# 安装依赖项
uv pip install -e ".[dev]"

API密钥设置

Street View MCP需要一个启用了Street View API的Google Maps API密钥:

  1. 访问Google Cloud Console
  2. 创建新项目或选择现有项目
  3. 在API库中启用“Street View Static API”
  4. 从凭证页面创建API密钥
  5. 将API密钥设置为环境变量:
# 在shell中临时设置:
export API_KEY=your_api_key_here

# 或在项目根目录创建一个.env文件:
echo "API_KEY=your_api_key_here" > .env

使用方法

启动MCP服务器

python -m street_view_mcp.main --host 127.0.0.1 --port 8000

服务器将在指定的主机和端口对AI模型可用。

作为CLI工具使用

# 根据地址获取Street View图像
python -m street_view_mcp.street_view --address "Empire State Building, NY" --output output/empire_state.jpg

# 根据经纬度获取Street View图像
python -m street_view_mcp.street_view --latlong "40.748817,-73.985428" --output output/coords.jpg --heading 180

# 根据全景ID获取Street View图像
python -m street_view_mcp.street_view --pano PANO_ID --output output/panorama.jpg

MCP工具

Street View MCP提供了以下工具供AI模型使用:

get_street_view

根据位置、坐标或全景ID获取Street View图像并将其保存到文件。

{
  "filename": "empire_state.jpg",
  "location": "Empire State Building, NY",
  "size": "600x400",
  "heading": 90,
  "pitch": 10
}

参数:

  • filename(必需):保存图像的名称(必须不存在)
  • location(可选):获取图像的地址
  • lat_lng(可选):逗号分隔的坐标(例如:"40.748817,-73.985428")
  • pano_id(可选):特定的全景ID
  • size(可选):图像尺寸,格式为"宽度x高度"(默认:"600x400")
  • heading(可选):相机方向角度(0-360,默认:0)
  • pitch(可选):相机俯仰角度(-90至90,默认:0)
  • fov(可选):视场角度(10-120,默认:90)
  • radius(可选):搜索半径,单位米(默认:50)
  • source(可选):图像来源("default"或"outdoor",默认:"default")

注意:必须提供locationlat_lngpano_id中的一个。

get_metadata

获取关于Street View全景图的元数据。

{
  "location": "Empire State Building, NY"
}

参数:

  • get_street_view相同的地点参数
  • 返回带有状态、版权、日期、全景ID和坐标的JSON元数据

open_image_locally

在默认应用程序中打开保存的Street View图像。

{
  "filename": "empire_state.jpg"
}

参数:

  • filename(必需):要打开的图像文件名(必须存在于输出目录中)

create_html_page

创建一个HTML页面,显示多个Street View图像作为虚拟游览。

{
  "filename": "nyc_tour.html",
  "title": "New York City Tour",
  "html_elements": [
    "<h1>New York City Landmarks Tour</h1>",
    "<p>Explore famous landmarks through Street View images.</p>",
    "<h2>Empire State Building</h2>",
    "<img src='../output/empire.jpg' alt='Empire State Building'>",
    "<p class='location'>350 Fifth Avenue, New York, NY</p>",
    "<p class='description'>This 102-story Art Deco skyscraper was completed in 1931.</p>"
  ]
}

参数:

  • html_elements(必需):HTML内容元素列表
  • filename(必需):HTML文件的名称
  • title(可选):页面标题(默认:"Street View Tour")

重要:引用图像时,始终使用路径../output/filename.jpg

创建虚拟游览

Street View MCP通过结合多个Street View图像和描述性文本在HTML页面中创建虚拟游览。

创建游览的示例工作流程:

  1. 获取不同地点的图像:
get_street_view(filename="empire.jpg", location="Empire State Building, NY")
get_street_view(filename="times_square.jpg", location="Times Square, NY")
get_street_view(filename="central_park.jpg", location="Central Park, NY")
  1. 创建HTML游览页面:
create_html_page(
  filename="nyc_tour.html",
  title="New York City Tour",
  html_elements=[
    "<h1>New York City Landmarks Tour</h1>",
    "<p>Explore these famous NYC landmarks through Street View images.</p>",
    
    "<h2>Empire State Building</h2>",
    "<img src='../output/empire.jpg' alt='Empire State Building'>",
    "<p class='location'>350 Fifth Avenue, New York, NY</p>",
    "<p class='description'>An iconic 102-story Art Deco skyscraper in Midtown Manhattan.</p>",
    
    "<h2>Times Square</h2>",
    "<img src='../output/times_square.jpg' alt='Times Square'>",
    "<p class='location'>Broadway & 7th Avenue, New York, NY</p>",
    "<p class='description'>Famous for its bright lights, Broadway theaters, and as the site of the annual New Year's Eve ball drop.</p>",
    
    "<h2>Central Park</h2>",
    "<img src='../output/central_park.jpg' alt='Central Park'>",
    "<p class='location'>Central Park, New York, NY</p>",
    "<p class='description'>An urban park spanning 843 acres in the heart of Manhattan.</p>"
  ]
)

项目结构

  • street_view_mcp/
    • __init__.py:包初始化
    • main.py:MCP服务器入口点
    • server.py:MCP服务器实现
    • street_view.py:核心Street View API客户端

重要注意事项

  • 本地存储:此工具将所有Street View图像和HTML文件保存在本地的output/目录中
  • 无自动清理:没有内置机制来删除保存的文件
  • 手动清理:应定期清理output/目录以管理磁盘空间
  • API使用:每个图像请求都会计入您的Google Maps API配额,并可能产生费用

开发

测试

pytest

许可证

MIT