Skip to content
Merged
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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ Complete set of tools for managing Mapbox styles via the Styles API:
- Returns: URL to open the style preview in browser
- **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.

**ValidateStyleTool** - Validate Mapbox style JSON against the Mapbox Style Specification

- Input: `style` (Mapbox style JSON object or JSON string)
- Returns: Validation results including errors, warnings, info messages, and style summary
- Performs comprehensive offline validation checking:
- Required fields (version, sources, layers)
- Valid layer and source types
- Source references and layer IDs
- Common configuration issues
- **Note**: This is an offline validation tool that doesn't require API access or token scopes

**⚠️ Required Token Scopes:**

**All style tools require a valid Mapbox access token with specific scopes. Using a token without the correct scope will result in authentication errors.**
Expand Down
4 changes: 3 additions & 1 deletion src/tools/toolRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { StyleBuilderTool } from './style-builder-tool/StyleBuilderTool.js';
import { StyleComparisonTool } from './style-comparison-tool/StyleComparisonTool.js';
import { TilequeryTool } from './tilequery-tool/TilequeryTool.js';
import { UpdateStyleTool } from './update-style-tool/UpdateStyleTool.js';
import { ValidateStyleTool } from './validate-style-tool/ValidateStyleTool.js';
import { httpRequest } from '../utils/httpPipeline.js';

// Central registry of all tools
Expand All @@ -42,7 +43,8 @@ export const ALL_TOOLS = [
new GetMapboxDocSourceTool({ httpRequest }),
new GetReferenceTool(),
new StyleComparisonTool(),
new TilequeryTool({ httpRequest })
new TilequeryTool({ httpRequest }),
new ValidateStyleTool()
] as const;

export type ToolInstance = (typeof ALL_TOOLS)[number];
Expand Down
21 changes: 21 additions & 0 deletions src/tools/validate-style-tool/ValidateStyleTool.input.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Mapbox, Inc.
// Licensed under the MIT License.

import { z } from 'zod';

/**
* Input schema for ValidateStyleTool
* Validates Mapbox GL JS style JSON against the style specification
*/
export const ValidateStyleInputSchema = z.object({
style: z
.union([z.string(), z.record(z.unknown())])
.describe(
'Mapbox style JSON object or JSON string to validate against the Mapbox Style Specification'
)
});

/**
* Inferred TypeScript type for ValidateStyleTool input
*/
export type ValidateStyleInput = z.infer<typeof ValidateStyleInputSchema>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) Mapbox, Inc.
// Licensed under the MIT License.

import { z } from 'zod';

const ValidationIssueSchema = z.object({
severity: z
.enum(['error', 'warning', 'info'])
.describe('Severity level of the issue'),
message: z.string().describe('Description of the validation issue'),
path: z.string().optional().describe('JSON path to the problematic property'),
suggestion: z.string().optional().describe('Suggested fix for the issue')
});

/**
* Output schema for ValidateStyleTool
* Returns comprehensive validation results for a Mapbox style JSON
*/
export const ValidateStyleOutputSchema = z.object({
valid: z.boolean().describe('Whether the style is valid'),
errors: z
.array(ValidationIssueSchema)
.describe('Critical errors that prevent the style from working'),
warnings: z
.array(ValidationIssueSchema)
.describe('Non-critical issues that may cause unexpected behavior'),
info: z
.array(ValidationIssueSchema)
.describe('Informational messages and suggestions for improvement'),
summary: z
.object({
version: z.number().optional().describe('Style specification version'),
layerCount: z.number().describe('Number of layers'),
sourceCount: z.number().describe('Number of sources'),
hasSprite: z.boolean().describe('Whether style has sprite defined'),
hasGlyphs: z.boolean().describe('Whether style has glyphs defined')
})
.describe('Summary of style structure')
});

/**
* Type inference for ValidateStyleOutput
*/
export type ValidateStyleOutput = z.infer<typeof ValidateStyleOutputSchema>;
export type ValidationIssue = z.infer<typeof ValidationIssueSchema>;
Loading
Loading