Skip to content

cesium-mcp-bridge

Browser SDK — embeds in your CesiumJS app, receives commands via WebSocket.

npm

Installation

bash
npm install cesium-mcp-bridge

Peer dependency: cesium@~1.139.0

Initialization

js
import { CesiumBridge } from 'cesium-mcp-bridge'

const viewer = new Cesium.Viewer('cesiumContainer')
const bridge = new CesiumBridge(viewer, {
  wsUrl: 'ws://localhost:9100',   // Runtime WebSocket URL
  sessionId: 'default',           // Session ID for routing
})

Commands (43)

View Control

CommandDescriptionKey Parameters
flyToAnimate camera to a positionlongitude, latitude, height, heading, pitch, roll, duration
setViewInstantly set camera positionlongitude, latitude, height, heading, pitch, roll
getViewGet current camera state
zoomToExtentZoom to geographic boundswest, south, east, north

Entity

CommandDescriptionKey Parameters
addMarkerAdd point markerlongitude, latitude, label, color, size
addLabelAdd text labelsdata, field, style
addPolylineAdd polyline (path/route)coordinates, color, width, clampToGround
addPolygonAdd polygon areacoordinates, color, outlineColor, opacity, extrudedHeight
addModelPlace 3D model (glTF/GLB)longitude, latitude, url, scale, heading, pitch, roll
updateEntityUpdate entity propertiesentityId, position, color, label, scale, show
removeEntityRemove a single entityentityId

Layer Management

CommandDescriptionKey Parameters
addGeoJsonLayerLoad GeoJSON dataurl or data, name, style
listLayersList all loaded layers
removeLayerRemove a layer by IDlayerId
setLayerVisibilityShow/hide a layerlayerId, visible
updateLayerStyleChange layer stylinglayerId, style
setBasemapSwitch imagery base layerprovider, url

Camera (advanced)

CommandDescriptionKey Parameters
lookAtTransformOrbit-style camera aimlongitude, latitude, height, heading, pitch, range
startOrbitStart camera orbitspeed, direction
stopOrbitStop orbit animation
setCameraOptionsConfigure camera controllerenableRotate, enableZoom, enableTilt

Extended Entity Types

CommandDescriptionKey Parameters
addBillboardAdd image iconlongitude, latitude, image, scale
addBoxAdd 3D boxposition, dimensions, material
addCorridorAdd corridorpositions, width, material
addCylinderAdd cylinder/coneposition, length, topRadius, bottomRadius
addEllipseAdd ellipseposition, semiMajorAxis, semiMinorAxis
addRectangleAdd rectanglewest, south, east, north, material
addWallAdd wallpositions, maximumHeights, minimumHeights

Animation

CommandDescriptionKey Parameters
createAnimationCreate waypoint animationentityId, waypoints, model
controlAnimationPlay/pause animationentityId, action
removeAnimationRemove animation entityentityId
listAnimationsList active animations
updateAnimationPathUpdate path visualsentityId, show, width, color
trackEntityCamera follows entityentityId
controlClockConfigure clockstartTime, stopTime, multiplier
setGlobeLightingGlobe lighting controlenableLighting, enableFog

3D Scene

CommandDescriptionKey Parameters
load3dTilesLoad 3D Tileseturl, name, maximumScreenSpaceError
loadTerrainSet terrain providerurl, provider
loadImageryServiceAdd imagery layerurl, provider, name

Interaction

CommandDescriptionKey Parameters
screenshotCapture current viewwidth, height, format
highlightHighlight featureslayerId, featureId, color

Other

CommandDescriptionKey Parameters
playTrajectoryAnimate along a pathpositions, duration, loop
addHeatmapCreate heatmap visualizationpoints, name, radius, gradient

Two Calling Styles

Style 1: Type-safe Methods

typescript
const result = await bridge.flyTo({
  longitude: 116.4,
  latitude: 39.9,
  height: 5000,
  duration: 2,
})

Style 2: JSON Command Dispatch

typescript
const result = await bridge.execute({
  action: 'flyTo',
  params: {
    longitude: 116.4,
    latitude: 39.9,
    height: 5000,
    duration: 2,
  },
})

Events

typescript
bridge.on('layerAdded', (layer) => console.log('Layer added:', layer))
bridge.on('layerRemoved', (layerId) => console.log('Removed:', layerId))
bridge.on('error', (err) => console.error('Bridge error:', err))

TypeScript Types

typescript
import type {
  BridgeCommand,
  BridgeResult,
  FlyToParams,
  SetViewParams,
  AddGeoJsonLayerParams,
  AddHeatmapParams,
  AddPolylineParams,
  AddPolygonParams,
  AddModelParams,
  UpdateEntityParams,
  RemoveEntityParams,
  Load3dTilesParams,
  PlayTrajectoryParams,
  LayerInfo,
  HighlightParams,
  ColorInput,
  // Camera
  LookAtTransformParams,
  StartOrbitParams,
  SetCameraOptionsParams,
  // Entity Types
  AddBillboardParams,
  AddBoxParams,
  AddCorridorParams,
  AddCylinderParams,
  AddEllipseParams,
  AddRectangleParams,
  AddWallParams,
  MaterialSpec,
  MaterialInput,
  OrientationInput,
  PositionDegrees,
  // Animation
  CreateAnimationParams,
  ControlAnimationParams,
  RemoveAnimationParams,
  UpdateAnimationPathParams,
  TrackEntityParams,
  ControlClockParams,
  SetGlobeLightingParams,
  AnimationWaypoint,
  AnimationInfo,
} from 'cesium-mcp-bridge'

Released under the MIT License.