Skip to content

Commit e7bb2f4

Browse files
committed
style builder tool with resources
1 parent 4eaf75c commit e7bb2f4

17 files changed

Lines changed: 3597 additions & 384 deletions

docs/style-resource-example.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# Mapbox Style Layers Resource Example
2+
3+
This example demonstrates how the Mapbox Style Layers Resource guides LLMs in creating Mapbox styles based on natural language requests.
4+
5+
## How It Works
6+
7+
1. The `MapboxStyleLayersResource` is registered as an MCP resource at `resource://mapbox-style-layers`
8+
2. When an LLM receives a request like "create a style that highlights railways and parks, and changes water to yellow", it can:
9+
- Query the resource to understand available layers
10+
- Get the correct source-layer names, filters, and properties
11+
- Generate proper Mapbox GL style JSON
12+
13+
## Example User Requests
14+
15+
### Request 1: "Highlight railways and parks, make water yellow"
16+
17+
The resource guides the LLM to:
18+
19+
- Use `water` layer (source-layer: "water") with `fill-color: "#ffff00"`
20+
- Use `landuse` layer filtered by `class: "park"` with bright green color
21+
- Use `road` layer filtered by `class: ["major_rail", "minor_rail"]` with red color
22+
23+
### Request 2: "Create a dark mode map with prominent buildings"
24+
25+
The resource guides the LLM to:
26+
27+
- Set `land` background layer to dark color
28+
- Use `building` layer with light color and high opacity
29+
- Adjust text colors for visibility on dark background
30+
31+
### Request 3: "Show only major roads and hide all labels"
32+
33+
The resource guides the LLM to:
34+
35+
- Include only `motorways` and `primary_roads` layers
36+
- Exclude all label layers (`place_labels`, `road_labels`, `poi_labels`)
37+
- Use appropriate filters like `["match", ["get", "class"], ["motorway", "trunk"], true, false]`
38+
39+
## Resource Content Structure
40+
41+
The resource provides:
42+
43+
1. **Quick Reference**: Maps common user requests to specific layers
44+
2. **Layer Categories**: Groups layers by type (water, transportation, labels, etc.)
45+
3. **Detailed Specifications**: For each layer:
46+
- Description
47+
- Source layer name
48+
- Layer type (fill, line, symbol, etc.)
49+
- Common filters
50+
- Paint properties with examples
51+
- Layout properties with examples
52+
- Example user requests
53+
54+
4. **Expression Examples**: Common Mapbox GL expression patterns:
55+
- Zoom-based interpolation
56+
- Feature property matching
57+
- Conditional styling
58+
59+
## Usage in LLM Context
60+
61+
When the LLM needs to create or modify a Mapbox style:
62+
63+
1. It reads the resource to understand available layers
64+
2. Maps user intent to specific layers using the descriptions and examples
65+
3. Generates proper filter expressions using the provided patterns
66+
4. Creates valid paint and layout properties
67+
68+
## Example Generated Style
69+
70+
Based on "highlight railways and parks, yellow water":
71+
72+
```json
73+
{
74+
"version": 8,
75+
"name": "Custom Style",
76+
"sources": {
77+
"composite": {
78+
"type": "vector",
79+
"url": "mapbox://mapbox.mapbox-streets-v8"
80+
}
81+
},
82+
"layers": [
83+
{
84+
"id": "land",
85+
"type": "background",
86+
"paint": {
87+
"background-color": "#f8f4f0"
88+
}
89+
},
90+
{
91+
"id": "water",
92+
"type": "fill",
93+
"source": "composite",
94+
"source-layer": "water",
95+
"paint": {
96+
"fill-color": "#ffff00"
97+
}
98+
},
99+
{
100+
"id": "parks",
101+
"type": "fill",
102+
"source": "composite",
103+
"source-layer": "landuse",
104+
"filter": ["==", ["get", "class"], "park"],
105+
"paint": {
106+
"fill-color": "#00ff00",
107+
"fill-opacity": 0.9
108+
}
109+
},
110+
{
111+
"id": "railways",
112+
"type": "line",
113+
"source": "composite",
114+
"source-layer": "road",
115+
"filter": [
116+
"match",
117+
["get", "class"],
118+
["major_rail", "minor_rail"],
119+
true,
120+
false
121+
],
122+
"paint": {
123+
"line-color": "#ff0000",
124+
"line-width": [
125+
"interpolate",
126+
["exponential", 1.5],
127+
["zoom"],
128+
14,
129+
2,
130+
20,
131+
8
132+
]
133+
}
134+
}
135+
]
136+
}
137+
```
138+
139+
## Benefits
140+
141+
1. **Accuracy**: LLM uses correct source-layer names and properties
142+
2. **Completeness**: All necessary filter expressions are included
143+
3. **Best Practices**: Follows Mapbox GL style specification patterns
144+
4. **Natural Language**: Users can describe what they want without knowing technical details

0 commit comments

Comments
 (0)