Working with AI & IDEs
Get Spectral working with your favorite AI assistant or code editor in under 5 minutes.
Quick Setup (Choose One)
Option 1: VS Code (Recommended)
Best for: Most developers, beginners
- Install the Spectral extension from VS Code marketplace
- Open any
.spectralfile - Get instant syntax highlighting, autocomplete, and error checking
That's it!
Option 2: Claude Desktop + AI Tools
Best for: AI-powered development
- Open
~/Library/Application Support/Claude/claude_desktop_config.json - Add:
{ "mcpServers": { "spectral": { "command": "/usr/local/bin/spectral-bin", "args": ["mcp", "--stdio"] } } } - Restart Claude
Now ask Claude: "Validate my Spectral code" or "Generate TypeScript from this spec"
Option 3: Other IDEs (Cursor, Windsurf, Zed)
Best for: Advanced users, specific IDE preferences
Same config as Claude, different location:
- Cursor:
~/.cursor/mcp_settings.json - Windsurf:
~/Library/Application Support/Windsurf/mcp_config.json - Zed:
~/.config/zed/settings.json
Find your path:
which spectral-bin
What You Can Do
Once set up, you can:
- Ask AI to validate your Spectral code
- Generate TypeScript/Python/Rust from specs
- Get autocomplete in your editor
- See errors as you type
- Convert natural language to Spectral
Generate Artifacts with AI Inference
Use the spectral inference command to generate production-ready artifacts:
# Generate GraphQL schema
spectral inference graphql app.spectral -o schema.graphql
# Generate Prisma database schema
spectral inference prisma app.spectral -o prisma/schema.prisma
# Generate route tree for React Router
spectral inference routes app.spectral --framework react-router
# Generate E2E test specifications
spectral inference e2e app.spectral -o tests/
See CLI Commands for the full list of inference subcommands.
Detailed Setup Guides
<details> <summary><strong>Claude Desktop (Expand for details)</strong></summary>Config Locations
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Linux: ~/.config/Claude/claude_desktop_config.json
Configuration
{
"mcpServers": {
"spectral": {
"command": "/usr/local/bin/spectral-bin",
"args": ["mcp", "--stdio"]
}
}
}
Restart Claude Desktop after saving.
Example Prompts
"Validate this Spectral code: visitor Admin { can manage users }"
"Generate TypeScript from: type User { id: string, name: string }"
"Explain what workflow OrderProcess does"
</details>
<details>
<summary><strong>Cursor IDE</strong></summary>
Config: ~/.cursor/mcp_settings.json
{
"mcpServers": {
"spectral": {
"command": "/usr/local/bin/spectral-bin",
"args": ["mcp", "--stdio"]
}
}
}
Restart Cursor, then use Cmd+K or Ctrl+K to access tools.
</details> <details> <summary><strong>Windsurf by Codeium</strong></summary>macOS: ~/Library/Application Support/Windsurf/mcp_config.json
Windows: %APPDATA%\Windsurf\mcp_config.json
Linux: ~/.config/Windsurf/mcp_config.json
{
"mcpServers": {
"spectral": {
"command": "/usr/local/bin/spectral-bin",
"args": ["mcp", "--stdio"]
}
}
}
</details>
<details>
<summary><strong>Cline (VS Code Extension)</strong></summary>
Open VS Code settings (JSON) and add:
{
"cline.mcpServers": {
"spectral": {
"command": "/usr/local/bin/spectral-bin",
"args": ["mcp", "--stdio"]
}
}
}
</details>
<details>
<summary><strong>Zed Editor</strong></summary>
Config: ~/.config/zed/settings.json
{
"context_servers": {
"spectral": {
"command": {
"path": "/usr/local/bin/spectral-bin",
"args": ["mcp", "--stdio"]
}
}
}
}
</details>
<details>
<summary><strong>Continue (VS Code Extension)</strong></summary>
Config: .continue/config.json
{
"mcpServers": [
{
"name": "spectral",
"command": "/usr/local/bin/spectral-bin",
"args": ["mcp", "--stdio"]
}
]
}
</details>
<details>
<summary><strong>GitHub Copilot</strong></summary>
Copilot works indirectly:
- Install Spectral VS Code extension (for context)
- Use CLI:
spectral implement app.spectral --agent copilot - Or generate code and let Copilot enhance it
VS Code Setup
<details> <summary><strong>Install Spectral Extension (Expand)</strong></summary>- Open VS Code Extensions (Cmd+Shift+X)
- Search "Spectral"
- Click Install
You get: Syntax highlighting, autocomplete, error checking, go-to-definition
</details> <details> <summary><strong>What You Can Do</strong></summary>- See errors as you type (red squiggles)
- Auto-complete types, visitors, workflows
- Hover for documentation
- Click to jump to definitions (F12)
- Find all references (Shift+F12)
Other Editors (Neovim, Emacs, Sublime)
<details> <summary><strong>Neovim</strong></summary>require('lspconfig').spectral.setup{
cmd = { "spectral", "lsp" },
filetypes = { "spectral" },
}
</details>
<details>
<summary><strong>Emacs</strong></summary>
(lsp-register-client
(make-lsp-client :new-connection (lsp-stdio-connection '("spectral" "lsp"))
:major-modes '(spectral-mode)
:server-id 'spectral))
</details>
<details>
<summary><strong>Sublime Text</strong></summary>
{
"clients": {
"spectral": {
"enabled": true,
"command": ["spectral", "lsp"],
"selector": "source.spectral"
}
}
}
</details>
Troubleshooting
AI not responding?
- Run
spectral mcp --list-toolsto check MCP server - Verify path with
which spectral-bin - Restart your AI client
VS Code extension not working?
- Reload window (Cmd+Shift+P -> "Reload Window")
- Check extension is installed and enabled
Need help?
- Check
spectral lspcommand works - See CLI Commands for more options
Next Steps
- Read the Language Reference for syntax details
- Explore Workflow Features for advanced patterns
- Check out Examples to see Spectral in action
- Join the community for tips and support
Need help? Ask your AI assistant or check the CLI Commands guide.