激光雷达传感器API服务

一个通过标准化API提供Ouster激光雷达传感器访问的模型上下文协议服务器,支持AI模型和其他客户端通过定义良好的工具函数与激光雷达传感器交互。

  • by jmdaly
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 jmdaly/ouster-lidar-mcp-server

使用说明

Ouster激光雷达MCP服务器

一种模型上下文协议(MCP)服务器,通过标准化的API提供对Ouster Lidar传感器的访问。该服务器允许AI模型和其他客户端通过一组定义良好的工具功能与Ouster Lidar传感器进行交互。

特性

  • 连接和断开Ouster Lidar传感器
  • 获取详细的传感器信息
  • 捕获激光雷达扫描
  • 配置传感器参数
  • 支持多个传感器同时连接
  • 直接从GitHub运行 uvx 不进行本地克隆

需求

  • Python 3.11或更高版本
  • Ouster SDK 0.14.0或更高版本(使用时自动安装 uvx)
  • MCP库1.7.1或更高版本(使用时自动安装 uvx)
  • uv包管理器(包括 uvx)

安装

  1. 克隆此存储库
  2. 创建并激活虚拟环境:
# Create virtual environment
uv venv
# Activate it
source .venv/bin/activate  # On Unix/macOS
.venv\Scripts\activate     # On Windows
  1. 安装依赖项:
# Basic installation
uv pip install -e .

# With development dependencies (for running tests)
uv pip install -e ".[dev]"

用法

启动服务器

服务器可以通过多种方式运行:

选项1:直接运行 uvx (推荐,不需要本地克隆)

直接从GitHub运行 uvx:

# Start with default settings (stdio transport)
uvx --from git+https://github.com/jmdaly/ouster-lidar-mcp-server.git ouster-mcp-server

# Enable debug logging
uvx --from git+https://github.com/jmdaly/ouster-lidar-mcp-server.git ouster-mcp-server --debug

# Run with SSE transport (localhost:8080)
uvx --from git+https://github.com/jmdaly/ouster-lidar-mcp-server.git ouster-mcp-server --sse

# Specify host and port for SSE
uvx --from git+https://github.com/jmdaly/ouster-lidar-mcp-server.git ouster-mcp-server --sse --host 0.0.0.0 --port 9000

选项2:从本地克隆

如果已克隆存储库:

1.标准I/O(stdio)传输:
# Start with default settings
python main.py

# Enable debug logging
python main.py --debug
2.通过HTTP传输服务器发送事件(SSE):
# Start with default settings (localhost:8080)
python main.py --sse

# Specify host and port
python main.py --sse --host 0.0.0.0 --port 9000

# Enable debug logging
python main.py --sse --debug

选项3:作为安装包

如果您已安装该软件包:

# Start with default settings
ouster-mcp-server

# Enable debug logging
ouster-mcp-server --debug

# Run with SSE transport
ouster-mcp-server --sse

测试服务器

提供测试客户端以验证服务器功能:

对于stdio传输:

python test_client.py --server-script main.py --sensor your-sensor-hostname

对于SSE运输:

# Start the server in one terminal
python main.py --sse

# Run the test client in another terminal
python test_client.py --server-url http://localhost:8080 --sensor your-sensor-hostname

与Claude等MCP客户端一起使用

  1. 使用上述方法之一启动服务器(直接 uvx、stdio或SSE传输)
  2. 使用Claude Desktop或任何其他MCP兼容客户端连接到服务器
  3. 使用提供的工具与Ouster激光雷达传感器进行交互

使用Claude Desktop进行最快的设置:

# This runs the server directly from GitHub - no local clone needed
uvx --from git+https://github.com/jmdaly/ouster-lidar-mcp-server.git ouster-mcp-server --sse

然后将Claude Desktop连接到 http://localhost:8080

可用工具

服务器提供以下工具功能:

  1. connect_sensor -连接到Ouster激光雷达传感器
  2. disconnect_sensor -断开与Ouster激光雷达传感器的连接
  3. get_sensor_info -获取有关连接传感器的详细信息
  4. get_connected_sensors -列出所有连接的传感器
  5. capture_single_scan -从连接的传感器捕获单次扫描
  6. set_sensor_config -配置传感器参数

Claude中的示例用法

以下是如何使用Claude中的工具的示例:

> tool ouster_lidar.connect_sensor
{
  "hostname": "os-122200123456.local"
}

Response:
{
  "status": "connected",
  "sensor_info": {
    "hostname": "os-122200123456.local",
    "serial": "122200123456",
    "model": "OS-1-64",
    "firmware_version": "v2.4.0"
  }
}

> tool ouster_lidar.capture_single_scan
{
  "hostname": "os-122200123456.local"
}

Response:
{
  "status": "success",
  "scan_summary": {
    "frame_id": 42,
    "scan_shape": {
      "h": 64,
      "w": 1024
    },
    "range_stats": {
      "min": 0.0,
      "max": 85.23,
      "mean": 12.45
    },
    "signal_stats": {
      "min": 0.0,
      "max": 255.0,
      "mean": 45.78
    },
    "reflectivity_stats": {
      "min": 0.0,
      "max": 255.0,
      "mean": 35.62
    },
    "num_valid_returns": 45678
  }
}

发展

项目结构

  • main.py -核心服务器实现
  • test_client.py -用于测试服务器功能的客户端
  • tests/ -服务器和客户端的单元测试
  • README.md -文件

添加新工具

要添加新的工具功能,请执行以下操作:

  1. 使用以下命令实现async函数 @mcp.tool() 装饰器
  2. 确保为参数和返回类型提供类型提示
  3. 添加全面的文档字符串来描述功能

例子:

@mcp.tool()
async def my_new_tool(param1: str, param2: int) -> Dict[str, Any]:
    """
    Description of what the tool does.
    
    Args:
        param1: Description of param1
        param2: Description of param2
        
    Returns:
        Dictionary with results
    """
    # Implementation
    return {"result": "success"}

运行测试

该项目包括对服务器和客户端功能的全面单元测试:

# Run all tests
pytest

# Run specific test file
pytest tests/test_server.py

# Run with verbose output
pytest -v

# Run with code coverage report
pytest --cov=.

进一步增强

未来发展的一些潜在增强功能:

  • 添加对记录/回放激光雷达数据的支持
  • 实现点云可视化功能
  • 添加对多传感器校准和注册的支持
  • 实施先进的点云处理算法

许可证

MIT许可证