Skip to main content
Glama

migrate_v1_to_v2

Analyze Pydantic v1 code to identify migration issues for v2 and optionally apply fixes.

Instructions

Analyze a snippet or model source for common Pydantic v1-to-v2 migration issues.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeNo
targetNo
apply_fixesNo

Implementation Reference

  • The main handler function for migrate_v1_to_v2 which processes code or target model for migration issues.
    def migrate_v1_to_v2(
        code: str | None = None,
        target: str | None = None,
        apply_fixes: bool = False,
    ) -> ToolResponse:
        """Analyze a snippet or model source for common Pydantic v1-to-v2 migration issues."""
        if code is None and target is None:
            return make_response(
                diagnostics=[
                    Diagnostic(
                        level="error",
                        message="Provide either `code` or `target`.",
                        code="missing_input",
                    )
                ],
                result={"findings": [], "risk_level": "none", "updated_code": None},
            )
        if code is None and target is not None:
            runtime_target = resolve_target(
                target,
                registry=REGISTRY,
                settings=SERVER_SETTINGS,
            )
            code = inspect.getsource(
                runtime_target.model_class or runtime_target.annotation
            )
            response = migration_report(code, apply_fixes=apply_fixes)
            response.resolved_target = runtime_target.resolved
            return response
        return migration_report(code or "", apply_fixes=apply_fixes)
  • Registration of the migrate_v1_to_v2 tool in the server module.
    migrate_v1_to_v2 = _tools.migrate_v1_to_v2
    parse_partial_json = _tools.parse_partial_json
    generate_model_from_json = _tools.generate_model_from_json
    server_capabilities = _resources.server_capabilities
    models_index = _resources.models_index
    model_metadata = _resources.model_metadata
    model_schema = _resources.model_schema
    model_examples = _resources.model_examples
    reference_overview = _resources.reference_overview
    project_settings = _resources.project_settings
    project_import_roots = _resources.project_import_roots
    recent_errors = _resources.recent_errors
    migration_rules = _resources.migration_rules
    changed_models = _resources.changed_models
    
    __all__ = [
        "SERVER_NAME",
        "SERVER_SETTINGS",
        "SERVER_VERSION",
        "build_capabilities",
        "changed_models",
        "compare_validation_modes",
        "create_example_payload",
        "explain_model",
        "generate_json_schema",
        "generate_model_from_json",
        "inspect_type",
        "list_models",
        "main",
        "mcp",
        "migrate_v1_to_v2",

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/BitingSnakes/pydantic-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server