Skip to content

Commit 0474af2

Browse files
Merge pull request #49 from mapbox/add-validate-style-tool
Add validate_style_tool for offline Mapbox style validation
2 parents e279a15 + 6ce9ca6 commit 0474af2

File tree

7 files changed

+766
-1
lines changed

7 files changed

+766
-1
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,17 @@ Complete set of tools for managing Mapbox styles via the Styles API:
189189
- Returns: URL to open the style preview in browser
190190
- **Note**: This tool automatically fetches the first available public token from your account for the preview URL. Requires at least one public token with `styles:read` scope.
191191

192+
**ValidateStyleTool** - Validate Mapbox style JSON against the Mapbox Style Specification
193+
194+
- Input: `style` (Mapbox style JSON object or JSON string)
195+
- Returns: Validation results including errors, warnings, info messages, and style summary
196+
- Performs comprehensive offline validation checking:
197+
- Required fields (version, sources, layers)
198+
- Valid layer and source types
199+
- Source references and layer IDs
200+
- Common configuration issues
201+
- **Note**: This is an offline validation tool that doesn't require API access or token scopes
202+
192203
**⚠️ Required Token Scopes:**
193204

194205
**All style tools require a valid Mapbox access token with specific scopes. Using a token without the correct scope will result in authentication errors.**

src/tools/toolRegistry.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { StyleBuilderTool } from './style-builder-tool/StyleBuilderTool.js';
2020
import { StyleComparisonTool } from './style-comparison-tool/StyleComparisonTool.js';
2121
import { TilequeryTool } from './tilequery-tool/TilequeryTool.js';
2222
import { UpdateStyleTool } from './update-style-tool/UpdateStyleTool.js';
23+
import { ValidateStyleTool } from './validate-style-tool/ValidateStyleTool.js';
2324
import { httpRequest } from '../utils/httpPipeline.js';
2425

2526
// Central registry of all tools
@@ -42,7 +43,8 @@ export const ALL_TOOLS = [
4243
new GetMapboxDocSourceTool({ httpRequest }),
4344
new GetReferenceTool(),
4445
new StyleComparisonTool(),
45-
new TilequeryTool({ httpRequest })
46+
new TilequeryTool({ httpRequest }),
47+
new ValidateStyleTool()
4648
] as const;
4749

4850
export type ToolInstance = (typeof ALL_TOOLS)[number];
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) Mapbox, Inc.
2+
// Licensed under the MIT License.
3+
4+
import { z } from 'zod';
5+
6+
/**
7+
* Input schema for ValidateStyleTool
8+
* Validates Mapbox GL JS style JSON against the style specification
9+
*/
10+
export const ValidateStyleInputSchema = z.object({
11+
style: z
12+
.union([z.string(), z.record(z.unknown())])
13+
.describe(
14+
'Mapbox style JSON object or JSON string to validate against the Mapbox Style Specification'
15+
)
16+
});
17+
18+
/**
19+
* Inferred TypeScript type for ValidateStyleTool input
20+
*/
21+
export type ValidateStyleInput = z.infer<typeof ValidateStyleInputSchema>;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) Mapbox, Inc.
2+
// Licensed under the MIT License.
3+
4+
import { z } from 'zod';
5+
6+
const ValidationIssueSchema = z.object({
7+
severity: z
8+
.enum(['error', 'warning', 'info'])
9+
.describe('Severity level of the issue'),
10+
message: z.string().describe('Description of the validation issue'),
11+
path: z.string().optional().describe('JSON path to the problematic property'),
12+
suggestion: z.string().optional().describe('Suggested fix for the issue')
13+
});
14+
15+
/**
16+
* Output schema for ValidateStyleTool
17+
* Returns comprehensive validation results for a Mapbox style JSON
18+
*/
19+
export const ValidateStyleOutputSchema = z.object({
20+
valid: z.boolean().describe('Whether the style is valid'),
21+
errors: z
22+
.array(ValidationIssueSchema)
23+
.describe('Critical errors that prevent the style from working'),
24+
warnings: z
25+
.array(ValidationIssueSchema)
26+
.describe('Non-critical issues that may cause unexpected behavior'),
27+
info: z
28+
.array(ValidationIssueSchema)
29+
.describe('Informational messages and suggestions for improvement'),
30+
summary: z
31+
.object({
32+
version: z.number().optional().describe('Style specification version'),
33+
layerCount: z.number().describe('Number of layers'),
34+
sourceCount: z.number().describe('Number of sources'),
35+
hasSprite: z.boolean().describe('Whether style has sprite defined'),
36+
hasGlyphs: z.boolean().describe('Whether style has glyphs defined')
37+
})
38+
.describe('Summary of style structure')
39+
});
40+
41+
/**
42+
* Type inference for ValidateStyleOutput
43+
*/
44+
export type ValidateStyleOutput = z.infer<typeof ValidateStyleOutputSchema>;
45+
export type ValidationIssue = z.infer<typeof ValidationIssueSchema>;

0 commit comments

Comments
 (0)