-
Notifications
You must be signed in to change notification settings - Fork 168
feat: operation input to MCP compatible json schema converter #1124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c7b87f5
feat: MCP graph server
StarpTech bef34ad
chore: proper nullable handling, graceful shutdown mcp
StarpTech 6e08818
chore: readd deleted files
StarpTech f218226
chore: implement get_schema, execute_graphql and refactor code
StarpTech c225f72
chore: fix lint
StarpTech 59d52af
chore: adopt visitor pattern
StarpTech 29060dc
chore: use string for enums
StarpTech cc1c4a8
chore: remove leftovers
StarpTech 0a8bf5e
chore: use empty object to represent scalars
StarpTech c04fd6b
chore: improve tests readability
StarpTech 77b353d
chore: handle scalars correct, consider type comments
StarpTech aa2e389
chore: correctly implement visitor
StarpTech b2e117f
Update v2/pkg/engine/jsonschema/variables_schema.go
StarpTech 9d4f78c
chore: avoid defer in walker
StarpTech c95cb11
chore: fix merge issue
StarpTech 705a07b
chore: early return
StarpTech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,206 @@ | ||
| package jsonschema | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| ) | ||
|
|
||
| // SchemaType represents the type of a JSON Schema property | ||
| type SchemaType string | ||
|
|
||
| const ( | ||
| TypeObject SchemaType = "object" | ||
| TypeArray SchemaType = "array" | ||
| TypeString SchemaType = "string" | ||
| TypeNumber SchemaType = "number" | ||
| TypeInteger SchemaType = "integer" | ||
| TypeBoolean SchemaType = "boolean" | ||
| TypeNull SchemaType = "null" | ||
| ) | ||
|
|
||
| // JsonSchema represents a JSON Schema definition | ||
| type JsonSchema struct { | ||
| // Core schema fields | ||
| Type SchemaType `json:"type,omitempty"` | ||
| Properties map[string]*JsonSchema `json:"properties,omitempty"` | ||
| Required []string `json:"required,omitempty"` | ||
| AdditionalProperties *bool `json:"additionalProperties,omitempty"` | ||
| Description string `json:"description,omitempty"` | ||
| Nullable bool `json:"nullable,omitempty"` | ||
|
|
||
| // Array-specific fields | ||
| Items *JsonSchema `json:"items,omitempty"` | ||
|
|
||
| // Enum values | ||
| Enum []string `json:"enum,omitempty"` | ||
|
|
||
| // Default value | ||
| Default interface{} `json:"default,omitempty"` | ||
|
|
||
| // String-specific fields | ||
| Format string `json:"format,omitempty"` | ||
|
|
||
| // Number-specific fields | ||
| Minimum *float64 `json:"minimum,omitempty"` | ||
| Maximum *float64 `json:"maximum,omitempty"` | ||
|
|
||
| // Additional validation | ||
| Pattern string `json:"pattern,omitempty"` | ||
| } | ||
|
|
||
| // MarshalJSON customizes JSON serialization to omit empty fields | ||
| func (s *JsonSchema) MarshalJSON() ([]byte, error) { | ||
| // Use a map to only include non-empty fields | ||
| m := make(map[string]interface{}) | ||
|
|
||
| if s.Type != "" { | ||
| // Always use a single type, regardless of nullability | ||
| m["type"] = string(s.Type) | ||
| } | ||
|
|
||
| if len(s.Properties) > 0 { | ||
| m["properties"] = s.Properties | ||
| } | ||
|
|
||
| if len(s.Required) > 0 { | ||
| m["required"] = s.Required | ||
| } | ||
|
|
||
| if s.AdditionalProperties != nil { | ||
| m["additionalProperties"] = *s.AdditionalProperties | ||
| } | ||
|
|
||
| if s.Description != "" { | ||
| m["description"] = s.Description | ||
| } | ||
|
|
||
| // For object types, always include nullable field regardless of value | ||
| // For other types, only include nullable when it's true | ||
| if s.Type == TypeObject || s.Nullable { | ||
| m["nullable"] = s.Nullable | ||
| } | ||
|
|
||
| if s.Items != nil { | ||
| m["items"] = s.Items | ||
| } | ||
|
|
||
| if len(s.Enum) > 0 { | ||
| m["enum"] = s.Enum | ||
| } | ||
|
|
||
| if s.Default != nil { | ||
| m["default"] = s.Default | ||
| } | ||
|
|
||
| if s.Format != "" { | ||
| m["format"] = s.Format | ||
| } | ||
|
|
||
| if s.Minimum != nil { | ||
| m["minimum"] = *s.Minimum | ||
| } | ||
|
|
||
| if s.Maximum != nil { | ||
| m["maximum"] = *s.Maximum | ||
| } | ||
|
|
||
| if s.Pattern != "" { | ||
| m["pattern"] = s.Pattern | ||
| } | ||
|
|
||
| return json.Marshal(m) | ||
| } | ||
|
|
||
| // NewObjectSchema creates a new schema for an object type | ||
| func NewObjectSchema() *JsonSchema { | ||
| additionalProps := false | ||
|
|
||
| return &JsonSchema{ | ||
| Type: TypeObject, | ||
| Properties: make(map[string]*JsonSchema), | ||
| AdditionalProperties: &additionalProps, | ||
| Required: []string{}, | ||
| Nullable: true, // Default to nullable | ||
| } | ||
| } | ||
|
|
||
| // NewAnySchema creates a schema representing any value (serialized as {} in JSON) | ||
| func NewAnySchema() *JsonSchema { | ||
| // This will represent as an empty object in JSON schema | ||
| return &JsonSchema{ | ||
| Nullable: true, // Default to nullable | ||
| } | ||
| } | ||
|
|
||
| // NewArraySchema creates a new schema for an array type | ||
| func NewArraySchema(items *JsonSchema) *JsonSchema { | ||
| return &JsonSchema{ | ||
| Type: TypeArray, | ||
| Items: items, | ||
| Nullable: true, // Default to nullable | ||
| } | ||
| } | ||
|
|
||
| // NewStringSchema creates a new schema for a string type | ||
| func NewStringSchema() *JsonSchema { | ||
| return &JsonSchema{ | ||
| Type: TypeString, | ||
| Nullable: true, // Default to nullable | ||
| } | ||
| } | ||
|
|
||
| // NewIntegerSchema creates a new schema for an integer type | ||
| func NewIntegerSchema() *JsonSchema { | ||
| return &JsonSchema{ | ||
| Type: TypeInteger, | ||
| Nullable: true, // Default to nullable | ||
| } | ||
| } | ||
|
|
||
| // NewNumberSchema creates a new schema for a number type | ||
| func NewNumberSchema() *JsonSchema { | ||
| return &JsonSchema{ | ||
| Type: TypeNumber, | ||
| Nullable: true, // Default to nullable | ||
| } | ||
| } | ||
|
|
||
| // NewBooleanSchema creates a new schema for a boolean type | ||
| func NewBooleanSchema() *JsonSchema { | ||
| return &JsonSchema{ | ||
| Type: TypeBoolean, | ||
| Nullable: true, // Default to nullable | ||
| } | ||
| } | ||
|
|
||
| // NewEnumSchema creates a new schema for an enum type | ||
| func NewEnumSchema(values []string) *JsonSchema { | ||
| return &JsonSchema{ | ||
| Type: TypeString, | ||
| Enum: values, | ||
| Nullable: true, // Default to nullable | ||
| } | ||
| } | ||
|
|
||
| // WithDescription adds a description to the schema | ||
| func (s *JsonSchema) WithDescription(description string) *JsonSchema { | ||
| s.Description = description | ||
| return s | ||
| } | ||
|
|
||
| // WithDefault adds a default value to the schema | ||
| func (s *JsonSchema) WithDefault(defaultValue interface{}) *JsonSchema { | ||
| s.Default = defaultValue | ||
| return s | ||
| } | ||
|
|
||
| // WithFormat adds a format to a string schema | ||
| func (s *JsonSchema) WithFormat(format string) *JsonSchema { | ||
| s.Format = format | ||
| return s | ||
| } | ||
|
|
||
| // WithNullable marks a schema as nullable | ||
| func (s *JsonSchema) WithNullable(nullable bool) *JsonSchema { | ||
| s.Nullable = nullable | ||
| return s | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.