anyapi-mcp-server 1.8.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,14 @@
1
- import { GraphQLSchema, GraphQLObjectType, GraphQLInputObjectType, GraphQLScalarType, GraphQLString, GraphQLInt, GraphQLFloat, GraphQLBoolean, GraphQLList, GraphQLNonNull, isObjectType, isListType, isScalarType, graphql as executeGraphQL, printSchema, } from "graphql";
1
+ import { GraphQLSchema, GraphQLObjectType, GraphQLInputObjectType, GraphQLScalarType, GraphQLString, GraphQLInt, GraphQLFloat, GraphQLBoolean, GraphQLList, GraphQLNonNull, isObjectType, isListType, isScalarType, parse, validate, execute, specifiedRules, FieldsOnCorrectTypeRule, ScalarLeafsRule, printSchema, } from "graphql";
2
2
  import { createHash } from "node:crypto";
3
3
  const MAX_ARRAY_LIMIT = 50;
4
4
  const MAX_SAMPLE_SIZE = 50;
5
5
  const MAJORITY_THRESHOLD = 0.6;
6
+ /**
7
+ * Validation rules that skip FieldsOnCorrectTypeRule and ScalarLeafsRule.
8
+ * This allows queries to select subfields on empty arrays (inferred as [JSON])
9
+ * and unknown fields (which silently resolve to undefined/omitted).
10
+ */
11
+ const lenientRules = specifiedRules.filter((rule) => rule !== FieldsOnCorrectTypeRule && rule !== ScalarLeafsRule);
6
12
  /**
7
13
  * Estimate token cost of a JSON value by walking its structure.
8
14
  * For scalars, estimates based on string length (long strings cost more tokens).
@@ -757,11 +763,13 @@ export async function executeQuery(schema, data, query) {
757
763
  const fullQuery = trimmed.startsWith("query") || trimmed.startsWith("mutation") || trimmed.startsWith("{")
758
764
  ? trimmed
759
765
  : `{ ${trimmed} }`;
760
- const result = await executeGraphQL({
761
- schema,
762
- source: fullQuery,
763
- rootValue: data,
764
- });
766
+ const document = parse(fullQuery);
767
+ const validationErrors = validate(schema, document, lenientRules);
768
+ if (validationErrors.length > 0) {
769
+ const messages = validationErrors.map((e) => e.message).join("; ");
770
+ throw new Error(`GraphQL query error: ${messages}`);
771
+ }
772
+ const result = await execute({ schema, document, rootValue: data });
765
773
  if (result.errors && result.errors.length > 0) {
766
774
  const messages = result.errors.map((e) => e.message).join("; ");
767
775
  throw new Error(`GraphQL query error: ${messages}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anyapi-mcp-server",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "A universal MCP server that connects any REST API (via OpenAPI spec) to AI assistants, with GraphQL-style field selection and automatic schema inference.",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",