Skip to content

Invalid schema for function. GPT models #668

@IvanMurzak

Description

@IvanMurzak

Copilot stopped accepting symbols in json schema of MCP tools:

  • [] - arrays
  • <> - generic classes
  • + - nested classes

Related

Upstream cause:

Same-class issues on Unity-MCP:

Related PRs:

ReflectorNet (where the fix likely lives):

⚠️ Warning — custom format is risky

Making a custom format for type names is dangerous because the C# type system has many edge-case shapes. Under-specification causes silent collisions (PR #629 was rejected partly for this reason). Any custom format must be:

  • Injective — no two distinct types collapse to the same short name
  • Round-trip cleanGetType(format(t)) == t for every t

C# syntactic shapes any custom format must cover

  1. Primitive value types (System.Int32, System.Boolean, System.Double, System.Char)
  2. Reference types (System.String, user classes)
  3. Enum types
  4. Struct types (user-defined value types)
  5. Single-dimensional arrays — T[]
  6. Multi-dimensional arrays — T[,], T[,,], T[,,,] (arbitrary rank)
  7. Jagged arrays — T[][], T[][][], and mixed T[,][]
  8. Closed generic types — List<int>, Dictionary<string, int>
  9. Open generic type definitions — List<>, Dictionary<,>
  10. Nested types — Outer+Inner
  11. Nested generic types — Outer<T>+Inner, Outer<T>+Inner<U>
  12. Deeply nested generics — List<Dictionary<string, List<int>>>
  13. Nullable value types — System.Nullable<T> / int?
  14. Tuples — System.ValueTuple<T1, T2, …>
  15. Generic type parameters — T, U (for reflection over unbound generics)
  16. Assembly-qualified names — Namespace.Type, Assembly, Version=..., Culture=..., PublicKeyToken=...
  17. Global-namespace types (no namespace prefix)
  18. Module types — <Module> and CLR-internal names
  19. Types whose FullName contains identifier characters that could collide with the sanitizer's separators (underscores, dots, Unicode letters)
  20. Pointer types — int* (unsafe)
  21. ByRef types — ref int, out T, in T
  22. Types from generic type definitions with constraints — List<T> where T : struct
  23. Covariant / contravariant generic args — IEnumerable<out T>, IComparer<in T>
  24. Types in assemblies with unusual naming — including dotted / dashed / Unicode assembly names

Solution (proposed)

During JSON Schema creation and during parsing type from name in SerializedMember and maybe in TypeUtils classes, handle the problematic symbols by replacing them with something else.

Proposed replacements:

  • +..
  • []__arr

(Alternative vocabularies under consideration — see #676 for related simplification work; both issues touch the same code and should ship together.)

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions