Skip to content

Linking MCP geocontext and MCP carto : in search of the best solution #154

Description

@esgn

I was focused on geocontext and gpf-schema-store and did not look into mcp-carto enough till now. I should have.

Current status in production

The current happy path is

GeoContext v0.9.8
  ↓
returns:
  method: POST
  url: https://data.geopf.fr/wfs
  query: {...}
  body: cql_filter=...
  get_url: https://data.geopf.fr/wfs?...&cql_filter=...
  ↓
LLM
  takes get_url
  ↓
MCP Carto v0.1.2
  receives get_url in layers[].data_url
  ↓
Carto UI
  detects cql_filter
  sends a POST request to data.geopf.fr/wfs
  displays the GeoJSON

The less happy path is

GeoContext v0.9.8
  ↓
returns:
  method: POST
  url: https://data.geopf.fr/wfs
  query: {...}
  body: cql_filter=...
  get_url: null
  ↓
LLM
  cannot use the normal get_url → layers[].data_url handoff
  ↓
LLM may try to recover by rebuilding a long data_url from:
  url + query + body.cql_filter
  ↓
MCP Carto v0.1.2
  receives the rebuilt URL in layers[].data_url
  ↓
Carto UI
  detects cql_filter in data_url
  extracts cql_filter
  removes cql_filter from the URL
  sends a POST request to data.geopf.fr/wfs
  ↓
If the rebuilt URL is valid:
  receives the GeoJSON
  displays it on the map
  ↓
If the LLM fails to rebuild the URL correctly:
  no GeoJSON is loaded
  nothing is displayed

Another bad mistake I've just spotted : https://github.com/ignfab/mcp-carto/blob/166bcff0189c7ff1f605b0c90c188e127fde7d0e/server.ts#L64 => should be result_type=request with gpf_wfs_get_features tool !

I wonder how it can work so well in demo 🤪

Possible solutions to stabilize the contract

  1. Update MCP Carto to accept a structured http_request source with method, url, query, headers, and body, instead of only accepting layers[].data_url => could be ok but we will still have this problem gpf_wfs_get_features - ensure that it doesn't returns huge geometries (4Mo) in cql_filter #151

  2. Expose a stable /layers/{id}.geojson URL from GeoContext so MCP Carto can consume a simple GeoJSON layer without knowing the underlying WFS complexity => Geocontext acting as WFS proxy

  3. Store the request “recipe” in GeoContext rather than the result, then replay that recipe when Carto calls the layer URL. => Geocontext serving the POST request recipe via URL to bypass the LLM

  4. Temporarily materialize the GeoJSON in GeoContext, then provide Carto with a simple URL pointing to the precomputed result => Geocontext acting as WFS caching proxy

  5. Use an MCP resource from GeoContext to carry the GeoJSON or compiled request, then evolve Carto so it can consume that resource instead of a raw URL. => MCP resource are not supported by a lot of AI assistant

  6. Pass query with references directly to MCP Carto and let Carto do the work of building the query once again. => a bit cumbersome

Discussion

Let's say we choose the /layers/{id}.geojson which proxifies the WFS interrogation => it smells like valkey + http routes of mcp-framework

Metadata

Metadata

Labels

enhancementNew feature or requestquestionFurther information is requested

Type

No fields configured for Task.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions