geeViz.mcp.server¶
geeViz MCP Server – execution and introspection tools for Earth Engine via geeViz.
Unlike static doc snippets, this server executes code, inspects live GEE assets, and dynamically queries API signatures. 12 tools.
Functions
|
Get environment information: versions, REPL namespace, or project details. |
|
Export an ee.Image to a GEE asset, Google Drive, or Cloud Storage. |
|
Run an FIA estimate. |
|
Get detailed metadata for any GEE asset (Image, ImageCollection, FeatureCollection, etc.). |
|
LCMS land cover / land use / change areas for a named area. |
|
Load a skill: the tested workflow for one kind of request. |
|
CLI entry point — start the geeViz MCP server on stdio transport. |
|
Manage GEE assets: delete, copy, move, create folders, update permissions. |
|
Control the geeView interactive map. |
|
Execute Python/GEE code in a persistent REPL namespace (like Jupyter). |
|
|
|
Save the accumulated run_code history to a .py script or .ipynb notebook. |
|
Search geeViz — plus any module in the REPL namespace (ee, pandas, numpy, etc.). |
|
Search the GEE dataset catalog PLUS BigQuery public data by keyword. |
|
Search the FIA vocabulary: estimate attributes, groupings, evaluations. |
|
View a generated output file (PNG, GIF, JPEG) as an inline image. |
- async geeViz.mcp.server.run_saved_script(**kwargs)[source]¶
run_codefor a saved script assembled from several chat blocks.
- async geeViz.mcp.server.run_code(code: str, timeout: int = 120, reset: bool = False, stream_stdout: bool = False, session_id: str = None, ctx: Context = None) str[source]¶
Execute Python/GEE code in a persistent REPL namespace (like Jupyter).
The namespace persists across calls – variables set in one call are available in the next. Pre-populated with: ee, Map (gv.Map), gv (geeViz.geeView), gil (geeViz.getImagesLib), sal (geeViz.getSummaryAreasLib), tl (geeViz.outputLib.thumbs), rl (geeViz.outputLib.reports), save_file.
Sandbox mode: When the server is run with
--sandboxor over HTTP to a non-localhost address,open(),os,sys,eval, etc. are blocked. For local/stdio use (the default), sandbox is OFF and full Python access is available. Usesave_file(filename, content)to write files to thegenerated_outputs/directory regardless of sandbox mode.While executing, progress heartbeats are sent every ~10 seconds to keep the MCP client connection alive and inform the agent that the tool is still running.
- Parameters:
code – Python code to execute.
timeout – Max seconds to wait (default 120). On Windows a hung getInfo() cannot be force-killed; the thread continues in background.
reset – If True, clear the namespace and re-initialize before executing.
stream_stdout – If True, print output is available in real-time via the /stdout polling endpoint. Default False.
session_id – Session identifier for namespace isolation. Default None (shared default session).
ctx – MCP Context (auto-injected by FastMCP). Used for progress reporting.
- Returns:
JSON with
success(bool) andstdout, plus each ofstderr,result,errorandoutput_markdown(new output files) that has something in it. A success also givesscript_path, the file holding every block run so far. An error gives each exception’s message and the lines of your code it passed through.
- geeViz.mcp.server.inspect_asset(asset_id: str, start_date: str = '', end_date: str = '', region_var: str = '', session_id: str = None) str[source]¶
Get detailed metadata for any GEE asset (Image, ImageCollection, FeatureCollection, etc.).
Returns band names/types, CRS, scale, date range, size, columns, and properties. Uses ee.data.getInfo for fast catalog metadata, then fetches live details with a 10-second timeout per query to avoid hangs on large collections. Also handles BigQuery-backed FeatureCollections — when the standard catalog lookup returns “not found” and the id looks BQ-shaped (
project.dataset.table), retries viaee.FeatureCollection.loadBigQueryTableso tables likebigquery-public-data.overture_maps.placedescribe cleanly.- Parameters:
asset_id – Full Earth Engine asset ID (e.g.
"COPERNICUS/S2_SR_HARMONIZED") OR a BigQuery table path in the formproject.dataset.table(e.g."bigquery-public-data.overture_maps.place"). EE catalog is tried first; BQ is the fallback.start_date – Optional start date filter for ImageCollections (YYYY-MM-DD).
end_date – Optional end date filter for ImageCollections (YYYY-MM-DD).
region_var – Optional name of an ee.Geometry or ee.FeatureCollection variable in the REPL namespace for spatial filtering (ImageCollections only).
- Returns:
JSON with asset metadata. For BQ-backed hits,
source=bigqueryis set so the caller knows to useee.FeatureCollection.loadBigQueryTable(notee.FeatureCollection) when constructing the FC.
- geeViz.mcp.server.search_codebase(query: str = '', name: str = '', module: str = '', session_id: str = None) str[source]¶
Search geeViz — plus any module in the REPL namespace (ee, pandas, numpy, etc.).
A unified introspection tool. Look up functions, classes, dicts, constants, viz params, band mappings, palettes, method signatures, example scripts — anything reachable by name.
Modules it searches
Every geeViz module (
getImagesLib,getSummaryAreasLib,geeView,geePalettes,edwLib,googleMapsLibwhen available,outputLib.charts/.thumbs/.reports, etc.) — indexed via AST at startup, so no imports fire until you actually request a runtime value.Example scripts under
geeViz/examples/—module="examples"lists them,name="<script_name>"returns source.Any module already loaded in the REPL namespace — that includes Earth Engine (
ee), pandas (pd/pandas), numpy (np/numpy), and anything else priorrun_codeblocks imported. Passmodule="ee"/module="pd"/ etc. to browse.
- Parameters:
query – Search term (case-insensitive). Matches against names and first-line docstrings across every indexed module.
name – Exact name to look up. Accepts bare names (
"vizParamsFalse","simpleMask","DataFrame.to_markdown") or dotted paths ("getImagesLib.vizParamsFalse","mapper.addLayer","ee.Image.reduceRegion","pd.DataFrame"). Returns full details — signature and docstring for functions; keys / values for dicts; value for constants.module – Module to search or list. Accepts short geeViz names (
"getImagesLib","charts","thumbs"), full paths ("geeViz.outputLib.charts"), legacy aliases ("chartingLib"), or any REPL-loaded module ("ee","pandas"/"pd","numpy"/"np").
- Returns:
No args: list of all discovered modules
module only: all public members (functions, classes, variables)
query only: search results across all modules
name only: detailed description of the named object
name + module: direct lookup within a specific module
- Return type:
JSON with results. Shape depends on the query
- geeViz.mcp.server.map_control(action: str = 'view', open_browser: bool = True, filename: str = 'map.html', session_id: str = None)[source]¶
Control the geeView interactive map.
action="view"writes the per-session runGeeViz.js to disk and opensgeeView/index.html. In plain Python this is afile:///URL; in notebooks it uses an in-process threaded HTTP server (http://localhost:<port>/...) for iframe display. The access token is passed via URL query string.Supported
actionvalues:"view"(default) — validates all layers first (runstest_layersinternally). If any layer fails, returns the errors without opening the map. If all pass, opens the map and returns the URL."layers"— list current layers with visibility and viz params."layer_names"— quick list of just layer names (lightweight)."clear"— remove all layers and commands."test_layers"— fast validation, callsgetMapId()on all layers in parallel. Catches bad bands, invalid viz, computation errors. No browser required. Returns pass/fail per layer."preview"— quick visual check. Fetches a small grid of EE map tiles for each layer around the current center/zoom and returns them as inline images (one per layer). No browser required. Use to visually verify layers have data in the right area. Returns{layer_name: PNG image}plus center and zoom. Optional:"preview,zoom=10,grid=2"to override zoom or grid."export"— validates all layers first (like"view"), then writes a self-contained geeView HTML togenerated_outputs/{filename}. If any layer fails, returns errors without exporting. The HTML uses absolute asset paths under/geeView/staticand a__GEEVIZ_TOKEN__placeholder for the access token. Suitable for chat UIs that serve the HTML themselves and inject a fresh token on load. Use this for chat-embedded maps that should survive session reloads."export_layers_json"— bundle every currently-added layer into a JSON file undergenerated_outputs/{filename}. Use when the agent is building a CUSTOM HTML dashboard (Leaflet, MapLibre, etc.) and needs the EE layers to be re-mintable. The returnedrefresh_urlis an endpoint the agent embeds in its HTML; fetching it returns fresh tile URLs for every layer so dashboards survive after EE map IDs expire. Handles all the same input types asaddLayer(Image, ImageCollection, Geometry, Feature, FeatureCollection) plus tile-URL layers (an XYZ URL given toMap.addLayer).
- Parameters:
action – One of the values listed above.
open_browser – For
action="view", whether to open in browser (default True).filename – For
action="export", the output filename (saved undergenerated_outputs/). Defaults tomap.html.session_id – Session identifier for namespace isolation.
- Returns:
JSON with action-specific results.
- geeViz.mcp.server.save_session(filename: str = '', format: str = 'py', sliced: bool = True, session_id: str = None) str[source]¶
Save the accumulated run_code history to a .py script or .ipynb notebook.
- Parameters:
filename – Optional custom filename (saved in geeViz/mcp/generated_scripts/). If omitted, uses a timestamped default. The correct extension is added automatically based on format.
format – Output format – “py” (default) for a standalone Python script, “ipynb” for a Jupyter notebook.
sliced – When True (default), run backward program slicing anchored on the last successful block and emit ONLY the surviving blocks — exploratory dead code and superseded assignments are dropped. When False, emit every successful block verbatim (legacy behavior; useful when the slicer’s judgment is wrong for a specific session). See
_slice_historyfor the rules.
- Returns:
JSON with the file path, block-retention counts, and status.
- geeViz.mcp.server.load_skill(name: str) str[source]¶
Load a skill: the tested workflow for one kind of request.
The instructions list every skill in one line (its name and when to use it). Before working on a request a skill covers, load it and follow it: it names the one or two calls that do the job, with their signatures, so they need no lookup.
- Parameters:
name – The skill’s name, as listed (for example “fire”).
- Returns:
The skill’s instructions (markdown), or an error naming the skills there are.
- geeViz.mcp.server.env_info(action: str = 'version', session_id: str = None) str[source]¶
Get environment information: versions, REPL namespace, or project details.
- Parameters:
action – What to return: - “version” (default): geeViz, EE, and Python versions. - “namespace”: User-defined variables in the REPL (no getInfo calls). - “project”: Current EE project ID and root assets.
- Returns:
JSON with action-specific results.
- geeViz.mcp.server.view_output(filename: str, session_id: str = None)[source]¶
View a generated output file (PNG, GIF, JPEG) as an inline image.
Use this to visually inspect charts, thumbnails, previews, or any image file in the generated_outputs directory. The image is returned directly so the LLM can see it.
For map previews, first call map_control(action=”preview”) to generate preview PNGs, then call view_output(“preview_Layer_Name.png”) to see them.
- Parameters:
filename – Name of the file in generated_outputs/ (e.g. “chart.png”, “preview_Elevation.png”). Just the filename, no directory.
session_id – Session identifier for namespace isolation.
- Returns:
The image content (displayed inline by the MCP client), or an error string.
- geeViz.mcp.server.export_image(destination: str, image_var: str, region_var: str = '', scale: int = 30, crs: str = 'EPSG:4326', overwrite: bool = False, asset_id: str = '', pyramiding_policy: str = 'mean', output_name: str = '', drive_folder: str = '', bucket: str = '', output_no_data: int = -32768, file_format: str = 'GeoTIFF', session_id: str = None) str[source]¶
Export an ee.Image to a GEE asset, Google Drive, or Cloud Storage.
- Parameters:
destination – Where to export – “asset”, “drive”, or “cloud”.
image_var – Name of the ee.Image variable in the REPL namespace.
region_var – Name of an ee.Geometry or ee.FeatureCollection variable for the export region. Required for drive/cloud exports; optional for asset exports (uses image footprint if omitted).
scale – Output resolution in meters (default 30).
crs – Coordinate reference system (default “EPSG:4326”).
overwrite – If True, overwrite existing asset/file (default False).
Asset-specific – asset_id: Full destination asset ID (required for destination=”asset”). pyramiding_policy: “mean” (default), “mode”, “min”, “max”, “median”, “sample”.
Drive-specific – output_name: Output filename without extension (required for drive/cloud). drive_folder: Google Drive folder name (required for destination=”drive”).
Storage-specific (Cloud) – output_name: Output filename without extension (required for drive/cloud). bucket: GCS bucket name (required for destination=”cloud”). output_no_data: NoData value (default -32768). file_format: “GeoTIFF” (default) or “TFRecord”.
- Returns:
JSON with export status or an error.
- geeViz.mcp.server.search_datasets(query: str, source: str = 'all', max_results: int = 50) str[source]¶
Search the GEE dataset catalog PLUS BigQuery public data by keyword.
Searches three catalogs, all cached with 30-day stale-while-revalidate:
official — Earth Engine STAC catalog (~500+ datasets).
community — awesome-gee-community-datasets (~200+ datasets).
bigquery — every dataset AND table under
bigquery-public-data(~357 datasets, ~3000 tables). Table-level indexing means a query like “overture places” resolves directly tobigquery-public-data.overture_maps.place— no need to enumerate tables yourself afterwards. Results havesource=bigquery, pluskindset to"dataset"or"table". For a BQ table row, construct the FeatureCollection withee.FeatureCollection.loadBigQueryTable(id)— NOTee.FeatureCollection(id)— because the id is a BQ path, not an EE asset path.inspect_asseton a BQ id auto-falls back through the same helper.
Uses word-level matching against title, tags, id, and provider fields with relevance scoring.
- Parameters:
query – Search terms (e.g. “landsat surface reflectance”, “DEM”, “sentinel fire”, “overture places”). Case-insensitive.
source – Which catalog to search: “official”, “community”, “bigquery”, or “all” (default — spans all three).
max_results – Maximum number of results to return (default 50).
- Returns:
JSON list of matching datasets with id, title, type, provider, tags, source, and additional metadata.
- geeViz.mcp.server.manage_asset(action: str, asset_id: str = '', dest_id: str = '', overwrite: bool = False, folder_type: str = 'Folder', all_users_can_read: bool = False, readers: str = '', writers: str = '', session_id: str = None) str[source]¶
Manage GEE assets: delete, copy, move, create folders, update permissions.
- Parameters:
action – Operation to perform: - “delete”: Delete a single asset. - “copy”: Copy asset_id to dest_id. - “move”: Copy asset_id to dest_id, then delete source. - “create”: Create a folder or ImageCollection at asset_id. - “update_acl”: Update permissions on asset_id.
asset_id – Full asset path. Required for all actions. For “create”, this is the folder path to create.
dest_id – Destination path (required for “copy” and “move”).
overwrite – If True, overwrite existing destination (default False).
folder_type – For action=”create” – “Folder” (default) or “ImageCollection”.
all_users_can_read – For action=”update_acl” – make publicly readable.
readers – For action=”update_acl” – comma-separated reader emails.
writers – For action=”update_acl” – comma-separated writer emails.
- Returns:
JSON confirmation or error.
- geeViz.mcp.server.search_fia(query: str = '', kind: str = 'attributes', state: str = '', growth_only: bool = False, max_results: int = 20) str[source]¶
Search the FIA vocabulary: estimate attributes, groupings, evaluations.
Call this before fia_estimate — always. FIA’s
/fullreporttakes an attribute, two groupings and an evaluation drawn from 752 / 96 / 1,129 options respectively. Guessing a parameter produces an opaque server error, not a helpful one.Resolved from catalogs bundled with geeViz, so this is instant and works with no network — including while FIADB-API is down, which it intermittently is.
- Parameters:
query – Free text. For
attributes, matched against the description and estimate group (“carbon”, “net growth volume”, “mortality”). Forgroupings, against the label and database column (“species”, “county”, “ownership”).kind –
"attributes"(what to estimate),"groupings"(how to break it out), or"evaluations"(which inventory).state – For
kind="evaluations"— state name prefix.growth_only – For
kind="evaluations"— keep only evaluations with growth accounting, required by every growth, removals and mortality attribute.max_results – Cap on rows returned.
- Returns:
JSON. Attributes carry
snum,description,unitsandeval_typ; groupings carry the exactlabelstring thatfia_estimateneeds; evaluations carrywcandgrowth_acct.
- geeViz.mcp.server.fia_estimate(wc: int, snum: int, rselected: str = '', cselected: str = '', str_filter: str = '', max_results: int = 60) str[source]¶
Run an FIA estimate. Returns values WITH their sampling error.
Get
wc,snumand the grouping strings fromsearch_fiafirst — the grouping arguments are exact display strings, so a near miss fails.You must not report any value from this tool without its standard error. FIA is a probability sample, not a census. Rows carry
se_pctandplots, andunreliableis set when the cell is too thin to report (SE > 30% or fewer than 30 plots, withn = 0andn = 1called out separately because a zero-plot cell reports a zero standard error — reading as maximum precision when it means no information).Do not report a row where
unreliableis true. Say the estimate is too uncertain to give, and name why fromunreliable_reason. “Alabama has 15,748 acres of white pine” is a confident falsehood built from correct data when the truth is 15,748 +/- 54.9% from four plots.A total over several rows comes from FIA, not from arithmetic. Rows of one evaluation can share sampling strata, so their errors need not be independent, and percentages cannot be added: combining row standard errors yourself can give a wrong SE for the combined area. To estimate a region made of several rows (units, counties, owners), restrict the query to them with
str_filterand report theTotalrow’s estimate andse_pct(leaverselectedempty to get only that row). The Total row carries the sameunreliableflag as any other.- Parameters:
wc – Evaluation group from
search_fia(kind="evaluations").snum – Attribute number from
search_fia(kind="attributes").rselected – Row grouping — exact
labelfromsearch_fia.cselected – Column grouping. Optional; cross-tabulating thins the plot count per cell fast, so expect more flagged rows.
str_filter – SQL-style filter restricting the estimate to a domain, e.g.
"plot.unitcd in (0, 1, 2)". Qualify columns with the full table name (plot.,cond.,tree.); the short aliases indb_column(P.,C.) fail upstream with an uninformative SQL error. Filter on the stored code, not the row label: labels can prefix the state code (aUnit coderow labeled4100 ...isplot.unitcd = 0).max_results – Cap on rows returned.
- Returns:
JSON with
rows, plusreliable_count/unreliable_countand theforest_definitionthe API actually applied.
- geeViz.mcp.server.lcms_summary(product: str = 'Land_Cover', state: str = '', county: str = '', region: str = '', forest: str = '', district: str = '', year: int = 0, max_results: int = 0) str[source]¶
LCMS land cover / land use / change areas for a named area.
Wall-to-wall 30 m maps, 1985-2025. Complements FIA: LCMS answers what changed and where, FIA answers what is there, plus or minus error.
Only the 3,643 precomputed areas are available here — 3,137 counties, 502 ranger districts, and CONUS / All-Lands rollups. Arbitrary geometry is not served by this API; that needs Earth Engine, via
run_codewithgeeViz.fsInsights.lcms_summary(geometry=...).- Parameters:
product –
"Land_Cover","Land_Use"or"Change".state – State name. Required alongside
county.county – County name.
region – Forest Service units.
districtrequiresforest. Short names work:"Tonto"and"Cave Creek"are sent as"Tonto National Forest"and"Cave Creek Ranger District"when the API wants those.forest – Forest Service units.
districtrequiresforest. Short names work:"Tonto"and"Cave Creek"are sent as"Tonto National Forest"and"Cave Creek Ranger District"when the API wants those.district – Forest Service units.
districtrequiresforest. Short names work:"Tonto"and"Cave Creek"are sent as"Tonto National Forest"and"Cave Creek Ranger District"when the API wants those.year – A single year, or 0 for the full 1985-2025 series.
max_results – 0 (the default) returns every row.
- Returns:
JSON rows of
year,class_name,acres,hectares, plus theforestanddistrictnames the API answered to.
Note
Do not equate these areas with FIA area estimates. One is a classified map, the other a probability sample; comparing them conflates map accuracy with sampling error. Report them separately and say which is which.
- geeViz.mcp.server.main() None[source]¶
CLI entry point — start the geeViz MCP server on stdio transport.
Reads config from the environment (EE_PROXY_URL, GEE_PROJECT, GEE_SERVICE_ACCOUNT_B64, MCP_SANDBOX, MCP_STREAM_DIR), spawns a background prewarm thread that eagerly initializes EE + imports the heavy geeViz modules, then blocks in
app.run()speaking JSON-RPC over stdin/stdout for the MCP client (Claude Desktop, ADK, etc.).Invoked as
python -m geeViz.mcpor by an MCP client configured withcommand: python -m geeViz.mcp.