Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
name: Node.js CI

on:
schedule:
- cron: '0 6 * * *'
push:
branches: [ "main" ]
branches: [ "main", "release/**" ]
pull_request:
branches: [ "main" ]
branches: [ "main", "release/**" ]
workflow_dispatch:

jobs:
build:
Expand Down
19 changes: 19 additions & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Python-generated files
__pycache__/
*.py[oc]
build/
dist/
wheels/
*.egg-info

# Virtual environments
.venv

# Environment
.env

# Test results
results.xml

# Node
node_modules/
1 change: 1 addition & 0 deletions test/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.13
21 changes: 21 additions & 0 deletions test/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2026 IGNFab <https://github.com/ignfab>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
116 changes: 116 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# geocontext-test

This repository contains an integration test suite designed to validate the correct behavior of the MCP server `ignfab/geocontext` across different language models.

## Purpose

The main goal is to ensure that end-to-end interactions with `ignfab/geocontext` remain stable and consistent when switching model providers or model versions.

## What is tested

- Agent creation using a configured model name
- Real model invocation through integration scenarios
- Functional response checks for expected outputs

## Usage

### Testing with anthropic models

```bash
export MODEL_NAME="anthropic:claude-sonnet-4-6"
export ANTHROPIC_API_KEY=YourKey

uv run pytest
```

### Testing with google models

```bash
export MODEL_NAME="google_genai:gemini-2.5-flash"
export GOOGLE_API_KEY=YourKey

uv run pytest
```

```bash
export MODEL_NAME="google_genai:gemini-3.1-flash-lite-preview"
export GOOGLE_API_KEY=YourKey

uv run pytest
```

## Tests

| Test | Fichier | Outil(s) attendu(s) | Description |
|------|---------|---------------------|-------------|
| `test_france_capital` | [test_france_capital.py](test_france_capital.py) | aucun (LLM seul) | Test basique sans MCP — vérifie que le LLM répond "Paris" |
| `test_adminexpress` | [test_adminexpress.py](test_adminexpress.py) | `adminexpress` | Commune/département à partir de coordonnées (2.35, 48.85) |
| `test_cadastre` | [test_cadastre.py](test_cadastre.py) | `cadastre` | Parcelle cadastrale au 73 av. de Paris, Saint-Mandé |
| `test_describe_type` | [test_describe_type.py](test_describe_type.py) | `gpf_wfs_describe_type` | Attributs de la table BDTOPO_V3:batiment |
| `test_get_features` | [test_get_features.py](test_get_features.py) | `gpf_wfs_get_features` | Bâtiments BDTOPO proches de Chamonix |
| `test_search_batiment` | [test_search_batiment.py](test_search_batiment.py) | `gpf_wfs_search_types` | Recherche de tables contenant des bâtiments |
| `test_search_ecoles` | [test_search_ecoles.py](test_search_ecoles.py) | `gpf_wfs_search_types` | Recherche de tables contenant des écoles |
| `test_chaining_geocode` | [test_chaining_geocode.py](test_chaining_geocode.py) | `geocode` → `altitude` | Chaînage géocodage + altitude (mairie de Chamonix ≈ 1036m) |
| `test_chaining_cadastre_urbanisme` | [test_chaining_cadastre_urbanisme.py](test_chaining_cadastre_urbanisme.py) | `geocode` → `cadastre` → `urbanisme` | Chaînage géocodage, cadastre et urbanisme |
| `test_urbanisme` | [test_urbanisme.py](test_urbanisme.py) | `urbanisme` | Règles d'urbanisme pour la parcelle 94067000AI0042 |
| `test_chaining_geocode_adminexpress` | [test_chaining_geocode_adminexpress.py](test_chaining_geocode_adminexpress.py) | `geocode` → `adminexpress` | Chaînage géocodage + commune/département (1 rue de Rivoli) |
| `test_chaining_geocode_assiette_sup` | [test_chaining_geocode_assiette_sup.py](test_chaining_geocode_assiette_sup.py) | `geocode` → `assiette_sup` | Chaînage géocodage + servitudes d'utilité publique (Lyon) |
| `test_chaining_discovery` | [test_chaining_discovery.py](test_chaining_discovery.py) | `gpf_wfs_search_types` → `gpf_wfs_describe_type` → `gpf_wfs_get_features` | Découverte complète : recherche, description et interrogation (cours d'eau à Toulouse) |

## Derniers résultats de tests

**Date** : 23 June 2026
**Modèle** : `anthropic:claude-haiku-4-5`
**Serveur MCP** : `geocontext@0.9.8`
**Nombre de tests** : 14

### Run — 14/14 passed (3 min 55 s)

| Test | Résultat | Détail |
|------|----------|--------|
| test_adminexpress | PASSED | |
| test_cadastre | PASSED | |
| test_chaining_geocode_cadastre_urbanisme | PASSED | |
| test_chaining_discovery | PASSED | |
| test_chaining_geocode_altitude | PASSED | |
| test_chaining_geocode_adminexpress | PASSED | |
| test_chaining_geocode_assiette_sup | PASSED | |
| test_describe_type | PASSED | |
| test_agent_creation_call_and_paris_in_response | PASSED | |
| test_get_feature_by_id | PASSED | |
| test_get_features | PASSED | |
| test_chaining_geocode_altitude | PASSED | |
| test_search_ecoles | PASSED | |
| test_urbanisme | PASSED | |

### Observations

- **14 tests sur 14 sont passés**
- Les 10 outils MCP sont tous couverts.
## Couverture des outils MCP

| Outil | Test direct | Test en chaînage | Couvert |
|-------|------------|-----------------|---------|
| `geocode` | — | 5 tests de chaînage | ✅ |
| `altitude` | — | `test_chaining_geocode` | ✅ |
| `adminexpress` | `test_adminexpress` | `test_chaining_geocode_adminexpress` | ✅ |
| `cadastre` | `test_cadastre` | `test_chaining_cadastre_urbanisme` | ✅ |
| `urbanisme` | `test_urbanisme` | `test_chaining_cadastre_urbanisme` | ✅ |
| `assiette_sup` | — | `test_chaining_geocode_assiette_sup` | ✅ |
| `gpf_wfs_search_types` | `test_search_batiment`, `test_search_ecoles` | `test_chaining_discovery` | ✅ |
| `gpf_wfs_describe_type` | `test_describe_type` | `test_chaining_discovery` | ✅ |
| `gpf_wfs_get_features` | `test_get_features` | `test_chaining_discovery` | ✅ |
| `gpf_wfs_get_feature_by_id` | — | — | ❌ Non couvert |

## Cas critiques non couverts

| Cas | Criticité | Description |
|-----|-----------|-------------|
| `gpf_wfs_get_feature_by_id` direct | **Haute** | Seul outil sans test dédié — utilisé indirectement par le LLM dans `test_urbanisme` mais jamais validé explicitement |
| Erreur réseau / tool error recovery | Moyenne | Pas de test sur la capacité de l'agent à retenter après une erreur d'outil |
| Coordonnées hors France / input invalide | Moyenne | Aucun test négatif — comportement inconnu avec des entrées invalides |

## License

[MIT](LICENSE)

43 changes: 43 additions & 0 deletions test/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os

# The model name can be set via the MODEL_NAME environment variable.
# If not set, it defaults to "anthropic:claude-haiku-4-5".
MODEL_NAME = os.getenv("MODEL_NAME", "anthropic:claude-haiku-4-5")

# required for some small models. For larger models, it doesn't change much.
SYSTEM_PROMPT = "You are a helpful assistant for geospatial data. You can use the tools to answer questions about geospatial data."

from langchain_mcp_adapters.client import MultiServerMCPClient

def get_mcp_client():
# Préparer les variables d'environnement pour le proxy
env = os.environ.copy()
proxy_vars = ["HTTP_PROXY", "HTTPS_PROXY", "NO_PROXY", "http_proxy", "https_proxy", "no_proxy"]
proxy_env = {var: env[var] for var in proxy_vars if var in env}
# Ensure uppercase variants are set (needed by Node.js libraries)
if "HTTP_PROXY" not in proxy_env and "http_proxy" in proxy_env:
proxy_env["HTTP_PROXY"] = proxy_env["http_proxy"]
if "HTTPS_PROXY" not in proxy_env and "https_proxy" in proxy_env:
proxy_env["HTTPS_PROXY"] = proxy_env["https_proxy"]
if "NO_PROXY" not in proxy_env and "no_proxy" in proxy_env:
proxy_env["NO_PROXY"] = proxy_env["no_proxy"]
log_level = env.get("GEOCONTEXT_LOG_LEVEL", "error")

# Preload script to configure undici ProxyAgent for Node.js fetch
bootstrap_path = os.path.join(os.path.dirname(__file__), "proxy-bootstrap.js")
node_options = f"--require {bootstrap_path}"

mcp_env = {**proxy_env, "LOG_LEVEL": log_level, "NODE_OPTIONS": node_options}

client = MultiServerMCPClient(
{
"geocontext": {
"command": "npx",
"args": ["-y", "@ignfab/geocontext"],
"transport": "stdio",
"env": mcp_env
}
}
)
return client

33 changes: 33 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pytest
import pytest_asyncio
from langchain.chat_models import init_chat_model
from langchain_core.callbacks.base import BaseCallbackHandler
from config import MODEL_NAME, SYSTEM_PROMPT, get_mcp_client


class ToolCallTracker(BaseCallbackHandler):
def __init__(self):
self.tool_calls = []

def on_tool_start(self, serialized, input_str, **kwargs):
self.tool_calls.append({"name": serialized.get("name", "unknown"), "type": "start"})


@pytest_asyncio.fixture(scope="session")
async def mcp_tools():
"""Session-scoped MCP tools - spawns the MCP server only once."""
client = get_mcp_client()
tools = await client.get_tools()
yield tools


@pytest.fixture(scope="session")
def model():
"""Session-scoped model instance."""
return init_chat_model(MODEL_NAME, temperature=0.0)


@pytest.fixture
def tracker():
"""Per-test tool call tracker."""
return ToolCallTracker()
Loading
Loading