quicktype-mcp

AscEmon/quicktype-mcp

3.2

If you are the rightful owner of quicktype-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The Quicktype MCP Server is a specialized tool for generating Dart models from JSON, designed to simplify the creation of type-safe Dart models for Flutter and Dart applications.

Tools
1
Resources
0
Prompts
0

Quicktype MCP Server

An MCP (Model Context Protocol) server specifically designed for generating models from JSON. This tool simplifies the process of creating type-safe models for various programming languages including Dart, Kotlin.

Features

  • Generate models for multiple programming languages
  • Automatic JSON validation and fixing
  • Generates null-safe models
  • Handles complex nested JSON structures
  • Includes serialization/deserialization methods

Prerequisites

  • Python 3.10 or higher
  • Internet connection (to access the quicktype.io API)

Usage as MCP Server

This tool is designed to be used as an MCP server that other applications can connect to. The server exposes a simple API for generating models from JSON input.

API

The server exposes the following endpoint:

  • generate_model: Generates a model from JSON input

Parameters:

  • json_input: The JSON string to generate a model from
  • class_name: The name of the generated class (default: Model)
  • language: The programming language to generate code for (dart, kotlin, typescript, swift, python, java, go)
{
  "quicktype-mcp": {
    "command": "uv",
    "args": [
      "--directory",
      "/path/to/quicktype-mcp",
      "run",
      "main.py",
    ]
  }
}

Available MCP Tools

  1. generate_model: Generate models from JSON

    • Parameters:
      • json_input: The JSON string to generate a model from
      • class_name: The name of the generated class (default: "Model")
      • language: The programming language to generate code for (dart, kotlin)
  2. list_languages: List all supported languages

  3. fix_json: Fix and format invalid JSON input

Supported Languages

The server currently supports generating models for the following languages:

Dart (with built-in serialization)

For Dart, the generated models include built-in serialization methods (fromJson and toJson):

// To parse this JSON data, do
//
//     final model = modelFromJson(jsonString);

import 'dart:convert';

class Model {
  int? id;
  String? name;

  Model({
    this.id,
    this.name,
  });

  factory Model.fromJson(Map<String, dynamic> json) => Model(
    id: json["id"],
    name: json["name"],
  );

  Map<String, dynamic> toJson() => {
    "id": id,
    "name": name,
  };
}

Kotlin (with kotlinx.serialization)

For Kotlin, the generated models use kotlinx.serialization annotations:

// To parse the JSON, install kotlin's serialization plugin and do:
//
// val json = Json { allowStructuredMapKeys = true }
// val model = json.decodeFromString(Model.serializer(), jsonString)

import kotlinx.serialization.*
import kotlinx.serialization.json.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*

@Serializable
data class Model(
    val id: Int? = null,
    val name: String? = null
)

The Kotlin generator produces code that:

  • Uses kotlinx.serialization annotations for automatic serialization/deserialization
  • Handles nullable types properly with Kotlin's null safety features
  • Converts snake_case JSON keys to camelCase Kotlin properties
  • Uses @SerialName annotations when the property name differs from the JSON key
  • Supports nested objects, lists, and complex data structures

Troubleshooting

If you encounter issues with the server not running, make sure:

  1. You have an active internet connection
  2. All dependencies are installed
  3. The correct Python version is being used (3.10+)

For issues with the generated models:

  1. Ensure your JSON is valid
  2. Try simplifying complex JSON structures if you encounter errors
  3. Check that the class name follows the naming conventions for the target language

Features of Generated Models

  • Null Safety: All fields are properly marked as nullable when appropriate
  • JSON Serialization: Includes serialization/deserialization methods
  • Nested Objects: Properly handles nested objects with their own classes
  • Lists and Maps: Correctly handles collections and their generic types
  • Type Safety: Uses appropriate types for JSON values

License

This project is licensed under the MIT License - see the LICENSE file for details.