-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGpfWfsSearchTypesTool.ts
More file actions
80 lines (67 loc) · 2.92 KB
/
GpfWfsSearchTypesTool.ts
File metadata and controls
80 lines (67 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* MCP tool exposing keyword-based search over the embedded WFS type catalog.
*/
import { MCPTool } from "mcp-framework";
import { z } from "zod";
import { READ_ONLY_OPEN_WORLD_TOOL_ANNOTATIONS } from "../helpers/toolAnnotations.js";
import { wfsClient } from "../gpf/wfs-schema-catalog.js";
// --- Schema ---
const gpfWfsSearchTypesInputSchema = z.object({
query: z
.string()
.trim()
.min(1, "la requête de recherche ne doit pas être vide")
.describe("La requête de recherche"),
max_results: z
.number()
.int()
.min(1)
.max(50)
.optional()
.describe("Le nombre maximum de résultats à retourner (entre 1 et 50). Défaut : 10."),
}).strict();
// --- Types ---
type GpfWfsSearchTypesInput = z.infer<typeof gpfWfsSearchTypesInputSchema>;
const gpfWfsSearchTypeResultSchema = z.object({
id: z.string().describe("L'identifiant complet du type WFS."),
title: z.string().describe("Le titre lisible du type WFS."),
description: z.string().describe("La description du type WFS."),
score: z.number().describe("Le score de pertinence de la recherche.").optional(),
});
const gpfWfsSearchTypesOutputSchema = z.object({
results: z.array(gpfWfsSearchTypeResultSchema).describe("La liste ordonnée des types WFS trouvés."),
});
// --- Tool ---
class GpfWfsSearchTypesTool extends MCPTool<GpfWfsSearchTypesInput> {
name = "gpf_wfs_search_types";
title = "Recherche de types WFS";
annotations = READ_ONLY_OPEN_WORLD_TOOL_ANNOTATIONS;
description = [
"Recherche des types WFS de la Géoplateforme (GPF) à partir de mots-clés afin de trouver un identifiant de type (`typename`) valide.",
"La recherche est textuelle (mini-search) et retourne une liste ordonnée de candidats avec leur identifiant, leur titre, leur description et un score de pertinence éventuel.",
"Le paramètre `max_results` permet d'élargir le nombre de candidats retournés (10 par défaut).",
"**Important** : Utiliser ce tool avant `gpf_wfs_describe_type` ou `gpf_wfs_get_features` lorsque le nom exact du type n'est pas connu.",
"**Important** : Privilégier des termes métier en français pour la recherche."
].join("\n");
protected outputSchemaShape = gpfWfsSearchTypesOutputSchema;
schema = gpfWfsSearchTypesInputSchema;
/**
* Searches the embedded WFS type catalog from a free-text query.
*
* @param input Normalized tool input.
* @returns The ordered search results, optionally enriched with relevance scores.
*/
async execute(input: GpfWfsSearchTypesInput) {
const maxResults = input.max_results || 10;
const featureTypes = await wfsClient.searchFeatureTypesWithScores(input.query, maxResults);
return {
results: featureTypes.map(({ collection, score }) => ({
id: collection.id,
title: collection.title,
description: collection.description,
...(score !== undefined ? { score } : {}),
})),
};
}
}
export default GpfWfsSearchTypesTool;