Skip to main content
Glama
MIT License
20
schema.go1.09 kB
package tool import ( "github.com/vektah/gqlparser/v2/ast" "github.com/vektah/gqlparser/v2/parser" ) func ExtractInputSchema(rawQuery string) (map[string]any, error) { doc, err := parser.ParseQuery(&ast.Source{Input: rawQuery}) if err != nil { return nil, err } if len(doc.Operations) == 0 { return nil, nil } op := doc.Operations[0] props := map[string]any{} required := []string{} for _, v := range op.VariableDefinitions { schema := map[string]any{ "type": graphqlTypeToJSONSchemaType(v.Type), } props[v.Variable] = schema if v.Type.NonNull { required = append(required, v.Variable) } } result := map[string]any{ "type": "object", "properties": props, } if len(required) > 0 { result["required"] = required } return result, nil } func graphqlTypeToJSONSchemaType(t *ast.Type) string { if t.Elem != nil { return "array" } switch t.NamedType { case "String", "ID": return "string" case "Int": return "integer" case "Float": return "number" case "Boolean": return "boolean" default: return "string" // fallback } }

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/fotoetienne/gqai'

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