Skip to main content

MCP Server

The zuraffa_mcp_server exposes Zuraffa v3 CLI features over MCP, so AI-enabled IDEs can call generators and inspect project structure safely.

What is MCP?

The Model Context Protocol is a standardized protocol that allows AI assistants to access tools, resources, and configuration within your development environment. MCP enables AI agents to:

  • Execute CLI commands
  • Access project files
  • Generate code
  • Create entities and data models
  • Retrieve project metadata
  • Integrate with your development workflow

Installation Options

Zuraffa MCP server offers three installation approaches to suit different needs. Additionally, you can configure Zorphy (entity generation) defaults via startup flags.

Zorphy Configuration Flags

Enable Zorphy-style typed entity patches by default for all MCP tool calls:

{
"mcpServers": {
"zuraffa": {
"command": "/usr/local/bin/zuraffa_mcp_server",
"args": ["--zorphy"],
"cwd": "/path/to/your/flutter/project"
}
}
}

Available flags:

  • --zorphy / --always-zorphy: Enable Zorphy by default

When enabled, all code generation will use Zorphy-style typed patches instead of Partial<T> for update operations. You can still override this per-request using the zorphy: false parameter.

# Activate globally
dart pub global activate zuraffa

# MCP server is immediately available
zuraffa_mcp_server

Benefits:

  • Single command installation
  • Dart automatically compiles and caches the executable
  • Fast startup after first run
  • Automatic updates with dart pub global activate zuraffa

2. Pre-compiled Binaries (Fastest - No Compilation Needed)

Pre-built binaries are automatically published to GitHub Releases for instant startup:

  • macOS ARM64: zuraffa_mcp_server-macos-arm64
  • macOS x64: zuraffa_mcp_server-macos-x64
  • Linux x64: zuraffa_mcp_server-linux-x64
  • Windows x64: zuraffa_mcp_server-windows-x64.exe
# Download and install (macOS example)
curl -L https://github.com/arrrrny/zuraffa/releases/latest/download/zuraffa_mcp_server-macos-arm64 -o zuraffa_mcp_server
chmod +x zuraffa_mcp_server
sudo mv zuraffa_mcp_server /usr/local/bin/

Benefits:

  • Zero startup time - ready to use immediately
  • No compilation overhead
  • Optimized for performance
  • Instant availability after download

3. Compile from Source (For Developers)

Build the server from source for full control:

# Clone the repository
git clone https://github.com/arrrrny/zuraffa.git
cd zuraffa

# Compile executable
dart compile exe bin/zuraffa_mcp_server.dart -o zuraffa_mcp_server

# Install to system path (optional)
sudo mv zuraffa_mcp_server /usr/local/bin/

Benefits:

  • Full control over compilation
  • Ability to modify source code
  • Custom optimizations
  • Development flexibility

Configuration

Claude Desktop

Configure MCP server in Claude Desktop by adding to your configuration file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%\Claude\claude_desktop_config.json Linux: ~/.config/Claude/claude_desktop_config.json

{
"mcpServers": {
"zuraffa": {
"command": "/usr/local/bin/zuraffa_mcp_server",
"args": [],
"cwd": "/path/to/your/flutter/project"
}
}
}
tip

Use the full path to the binary for reliability. Find it with which zuraffa_mcp_server.

Cursor / VS Code

Add to your workspace settings (.vscode/settings.json) or MCP configuration:

{
"mcp.servers": {
"zuraffa": {
"command": "zuraffa_mcp_server",
"args": [],
"cwd": "${workspaceFolder}"
}
}
}

Zed Editor

Configure in Zed settings:

{
"lsp": {
"mcp_servers": {
"zuraffa": {
"command": "/usr/local/bin/zuraffa_mcp_server",
"args": [],
"env": {}
}
}
}
}

Available Tools

The MCP server exposes Zuraffa CLI functionality as MCP tools:

Clean Architecture Tools

zuraffa_generate

Generate Clean Architecture code for your Flutter project.

Parameters:

ParameterTypeRequiredDescription
namestringYesEntity or UseCase name in PascalCase
methodsarrayNoMethods: get, getList, create, update, delete, watch, watchList
vpcbooleanNoGenerate View, Presenter, Controller (presentation layer)
pcbooleanNoGenerate Presenter + Controller only (preserve custom View)
pcsbooleanNoGenerate Presenter + Controller + State (preserve custom View)
statebooleanNoGenerate State object with granular loading states
databooleanNoGenerate data layer (DataRepository + DataSource)
datasourcebooleanNoGenerate DataSource only
initbooleanNoGenerate initialize method for repository and datasource
id_fieldstringNoID field name (default: id)
id_field_typestringNoID field type (default: String)
query_fieldstringNoQuery field name for get/watch (default: id)
query_field_typestringNoQuery field type (default: matches id_field_type)
zorphybooleanNoUse Zorphy-style typed patches
repostringNoRepository to inject (enforces Single Responsibility Principle)
usecasesarrayNoUseCases to compose (orchestrator pattern)
variantsarrayNoVariants for polymorphic pattern
domainstringNoDomain folder for custom UseCases (required for custom)
paramsstringNoParams type for custom UseCase (default: NoParams)
returnsstringNoReturn type for custom UseCase (default: void)
typestringNoUseCase type: usecase, stream, background, completable
outputstringNoOutput directory (default: lib/src)
dry_runbooleanNoPreview without writing files
forcebooleanNoOverwrite existing files
cachebooleanNoEnable caching with dual datasources
cache_policystringNoCache policy: daily, restart, ttl
cache_storagestringNoLocal storage: hive, sqlite, shared_preferences
mockbooleanNoGenerate mock data files
mock_data_onlybooleanNoGenerate only mock data files
use_mockbooleanNoUse mock datasource in DI (default: remote)
dibooleanNoGenerate dependency injection files (get_it)

Example Usage:

{
"name": "zuraffa_generate",
"arguments": {
"name": "Product",
"methods": ["get", "getList", "create"],
"vpc": true,
"data": true,
"state": true
}
}

zuraffa_initialize

Initialize a test entity to quickly try out Zuraffa.

Parameters:

ParameterTypeRequiredDescription
entitystringNoEntity name to generate (default: Product)
outputstringNoOutput directory (default: lib/src)
forcebooleanNoOverwrite existing files
dry_runbooleanNoPreview without writing files

zuraffa_schema

Get the JSON schema for ZFA configuration validation.

Parameters: None

zuraffa_validate

Validate a JSON configuration file.

Parameters:

  • config (object, required): The configuration to validate

Entity Generation Tools (NEW!)

entity_create

Create a new Zorphy entity with fields. Supports JSON serialization, sealed classes, inheritance, and all Zorphy features.

Parameters:

ParameterTypeRequiredDescription
namestringYesEntity name in PascalCase (e.g., User, Product)
outputstringNoOutput directory (default: lib/src/domain/entities)
fieldsarrayNoFields in format "name:type" or "name:type?" for nullable
jsonbooleanNoEnable JSON serialization (default: true)
sealedbooleanNoCreate sealed abstract class (use $$ prefix)
non_sealedbooleanNoCreate non-sealed abstract class
copywith_fnbooleanNoEnable function-based copyWith
comparebooleanNoEnable compareTo generation
extendsstringNoInterface to extend (e.g., $BaseEntity)
subtypearrayNoExplicit subtypes for polymorphism (e.g., ["$Dog", "$Cat"])

Example Usage:

{
"name": "entity_create",
"arguments": {
"name": "User",
"fields": ["name:String", "email:String?", "age:int"],
"json": true
}
}

entity_enum

Create a new enum in the entities/enums directory with automatic barrel export.

Parameters:

ParameterTypeRequiredDescription
namestringYesEnum name in PascalCase (e.g., Status, UserRole)
outputstringNoOutput base directory (default: lib/src/domain/entities)
valuesarrayYesEnum values (e.g., ["active", "inactive", "pending"])

Example Usage:

{
"name": "entity_enum",
"arguments": {
"name": "OrderStatus",
"values": ["pending", "processing", "shipped", "delivered", "cancelled"]
}
}

entity_add_field

Add field(s) to an existing Zorphy entity. Automatically updates imports if needed.

Parameters:

ParameterTypeRequiredDescription
namestringYesEntity name (e.g., User)
outputstringNoOutput base directory (default: lib/src/domain/entities)
fieldsarrayYesFields to add in format "name:type" or "name:type?"

Example Usage:

{
"name": "entity_add_field",
"arguments": {
"name": "User",
"fields": ["phone:String?", "address:$Address"]
}
}

entity_from_json

Create Zorphy entity/ies from a JSON file. Automatically infers types and creates nested entities.

Parameters:

ParameterTypeRequiredDescription
filestringYesPath to JSON file
namestringNoEntity name (inferred from file if not provided)
outputstringNoOutput base directory (default: lib/src/domain/entities)
jsonbooleanNoEnable JSON serialization (default: true)
prefix_nestedbooleanNoPrefix nested entities with parent name (default: true)

Example Usage:

{
"name": "entity_from_json",
"arguments": {
"file": "user_data.json",
"name": "UserProfile",
"json": true
}
}

entity_list

List all Zorphy entities and enums in the project with their properties.

Parameters:

ParameterTypeRequiredDescription
outputstringNoDirectory to search (default: lib/src/domain/entities)

Example Usage:

{
"name": "entity_list",
"arguments": {
"output": "lib/src/domain/entities"
}
}

entity_new

Quick-create a simple Zorphy entity with basic defaults. Good for prototyping.

Parameters:

ParameterTypeRequiredDescription
namestringYesEntity name in PascalCase
outputstringNoOutput directory (default: lib/src/domain/entities)
jsonbooleanNoEnable JSON serialization (default: true)

Example Usage:

{
"name": "entity_new",
"arguments": {
"name": "Product",
"json": true
}
}

Project Resources

The MCP server provides access to your project's generated resources:

resources/list

List all available files in your project's Clean Architecture and entity directories:

  • lib/src/domain/repositories - Repository interfaces
  • lib/src/domain/usecases - UseCase implementations
  • lib/src/data/data_sources - Data source implementations
  • lib/src/data/repositories - Data repository implementations
  • lib/src/presentation - Views, Presenters, Controllers
  • lib/src/domain/entities - Entity definitions (Zorphy entities)
  • lib/src/domain/entities/enums - Enum definitions

Example Response:

{
"resources": [
{
"uri": "file://lib/src/domain/entities/user/user.dart",
"name": "user",
"description": "user.dart",
"mimeType": "text/dart"
},
{
"uri": "file://lib/src/domain/entities/enums/status.dart",
"name": "status",
"description": "status.dart",
"mimeType": "text/dart"
},
{
"uri": "file://lib/src/domain/repositories/product_repository.dart",
"name": "product_repository",
"description": "product_repository.dart",
"mimeType": "text/dart"
}
]
}

resources/read

Read the contents of a specific file using its URI from resources/list.

Parameters:

  • uri (string, required): File URI to read (from the resources/list response)

Example:

{
"jsonrpc": "2.0",
"method": "resources/read",
"id": 10,
"params": {
"uri": "file://lib/src/domain/entities/user/user.dart"
}
}

AI/IDE Integration Examples

Generate Complete Feature with Entities

# AI agent workflow in Claude Desktop:
1. Create enum: entity_enum(name="OrderStatus", values=["pending","shipped"])
2. Create entity: entity_create(name="Order", fields=["customer:$Customer", "total:double"])
3. Generate architecture: zuraffa_generate(name="Order", methods=["get","create"], data=true, vpc=true)
4. Build: Automatic via notifications

Iterate on Entity Design

// AI agent conversation:
{
"role": "user",
"content": "Create a User entity with name, email, and address fields"
}

// Agent calls:
{
"name": "entity_create",
"arguments": {
"name": "User",
"fields": ["name:String", "email:String?", "address:$Address"]
}
}

Import from API Response

// After receiving API documentation:
{
"name": "entity_from_json",
"arguments": {
"file": "api_response.json",
"name": "ApiResponse",
"json": true
}
}

Notifications

When tools create new files, the MCP server automatically sends resource change notifications to the agent. This ensures the agent is aware of newly generated files without needing to explicitly query them.

Example notification after entity creation:

{
"jsonrpc": "2.0",
"method": "notifications/resources/list_changed",
"params": {
"changes": [
{
"type": "created",
"uri": "file://lib/src/domain/entities/user/user.dart"
},
{
"type": "created",
"uri": "file://lib/src/domain/entities/user/user.zorphy.dart"
},
{
"type": "created",
"uri": "file://lib/src/domain/entities/user/user.g.dart"
}
]
}
}

Testing

Test the server directly:

# Test initialize
echo '{"jsonrpc":"2.0","method":"initialize","id":1}' | zuraffa_mcp_server

# List tools (includes entity commands!)
echo '{"jsonrpc":"2.0","method":"tools/list","id":2}' | zuraffa_mcp_server

# Create entity via MCP
echo '{"jsonrpc":"2.0","method":"tools/call","id":3,"params":{"name":"entity_create","arguments":{"name":"TestUser","fields":["name:String"]}}}' | zuraffa_mcp_server

Troubleshooting

Timeout Issues

Problem: MCP client times out during connection or requests.

Cause: Using dart run compiles the package on every invocation, taking 10-30 seconds.

Solution: Use a precompiled executable:

dart compile exe bin/zuraffa_mcp_server.dart -o zuraffa_mcp_server

Build Errors After Entity Creation

Problem: Generated entity code has compilation errors.

Solution: Run zfa build after entity creation:

zfa entity create -n User --field name:String
zfa build # This generates the implementation

Best Practices

1. Create Entities Before Architecture

Always create entities before generating Clean Architecture:

// ✅ Good - Create entity first
entity_create(name="Product", fields=["name:String", "price:double"])
zuraffa_generate(name="Product", methods=["get", "create"], data=true)

// ❌ Bad - Product entity doesn't exist yet
zuraffa_generate(name="Product", methods=["get", "create"], data=true)

2. Use --dry-run for Testing

When working with AI agents, preview changes first:

{
"name": "entity_create",
"arguments": {
"name": "User",
"fields": ["name:String"],
"dry_run": true
}
}

3. Leverage Resource Notifications

Monitor file creation notifications to understand what was generated:

# Agent receives notifications for:
# - user.dart (your definition)
# - user.zorphy.dart (generated implementation)
# - user.g.dart (JSON serialization)

Next Steps