@graphql-hive/plugin-mcp 0.2.4-alpha-ce8e2f1a5a5d2bd9bcc62d2ece78d8127b4996c7 → 0.2.4

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.
package/CHANGELOG.md CHANGED
@@ -1,13 +1,15 @@
1
1
  # @graphql-hive/plugin-mcp
2
2
 
3
- ## 0.2.4-alpha-ce8e2f1a5a5d2bd9bcc62d2ece78d8127b4996c7
3
+ ## 0.2.4
4
4
  ### Patch Changes
5
5
 
6
6
 
7
7
 
8
- - [#2754](https://github.com/graphql-hive/gateway/pull/2754) [`efa7d86`](https://github.com/graphql-hive/gateway/commit/efa7d864454aa8e2a3d9ad6fdf1d4223f5232aad) Thanks [@dependabot](https://github.com/apps/dependabot)! - dependencies updates:
8
+ - [#2757](https://github.com/graphql-hive/gateway/pull/2757) [`5bff6f5`](https://github.com/graphql-hive/gateway/commit/5bff6f566edf402558fc3dc84d34b4c4c5497ce2) Thanks [@RMHonor](https://github.com/RMHonor)! - Allow `null` in the generated tool `outputSchema` for nullable GraphQL fields
9
9
 
10
- - Updated dependency [`@graphql-hive/core@0.24.0` ↗︎](https://www.npmjs.com/package/@graphql-hive/core/v/0.24.0) (from `0.22.1`, in `dependencies`)
10
+ **Behaviour change:** the `outputSchema` published in `tools/list` previously ignored nullability, so `T` and `T!` produced the same schema. GraphQL returns an explicit `null` for nullable fields, which violated that schema and made MCP hosts that validate `structuredContent` (such as Claude Desktop) reject the tool result.
11
+
12
+ Nullable fields now allow `null` (e.g. `{ "type": ["string", "null"] }`, with `null` added to `enum` for nullable enums, or `anyOf` with `{ "type": "null" }` for types without a single `type` such as unions). `NonNull` fields stay strict and the root schema is still a plain `object`. Clients that inspect `outputSchema` programmatically will now see `type` as an array for nullable fields.
11
13
 
12
14
  ## 0.2.3
13
15
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -511,8 +511,19 @@ function selectionSetToOutputSchema(document, schema) {
511
511
  }
512
512
  function outputTypeToSchema(type, selectionSet, schema) {
513
513
  if (graphql.isNonNullType(type)) {
514
- return outputTypeToSchema(type.ofType, selectionSet);
514
+ return nonNullOutputTypeToSchema(type.ofType, selectionSet);
515
515
  }
516
+ const result = nonNullOutputTypeToSchema(type, selectionSet);
517
+ if (typeof result.type !== "string") {
518
+ return { anyOf: [result, { type: "null" }] };
519
+ }
520
+ return {
521
+ ...result,
522
+ type: [result.type, "null"],
523
+ ...result.enum && { enum: [...result.enum, null] }
524
+ };
525
+ }
526
+ function nonNullOutputTypeToSchema(type, selectionSet, schema) {
516
527
  if (graphql.isListType(type)) {
517
528
  return {
518
529
  type: "array",
@@ -549,13 +560,14 @@ function getByPath(obj, path) {
549
560
  return current;
550
561
  }
551
562
  function getSchemaByPath(schema, path) {
563
+ const is = (s, t) => [s.type].flat().includes(t);
552
564
  let current = schema;
553
565
  for (const key of path.split(".")) {
554
- if (current.type === "object" && current.properties?.[key]) {
566
+ if (is(current, "object") && current.properties?.[key]) {
555
567
  current = current.properties[key];
556
- } else if (current.type === "array" && current.items) {
568
+ } else if (is(current, "array") && current.items) {
557
569
  const items = current.items;
558
- if (items.type === "object" && items.properties?.[key]) {
570
+ if (is(items, "object") && items.properties?.[key]) {
559
571
  current = items.properties[key];
560
572
  } else {
561
573
  return void 0;
@@ -1287,23 +1299,9 @@ async function handleMCPRequest(ctx, body, options, providerContext) {
1287
1299
  }
1288
1300
  }
1289
1301
  function setSchemaDescriptionByPath(schema, path, description) {
1290
- const keys = path.split(".");
1291
- let current = schema;
1292
- for (const key of keys) {
1293
- if (current.type === "object" && current.properties?.[key]) {
1294
- current = current.properties[key];
1295
- } else if (current.type === "array" && current.items) {
1296
- const items = current.items;
1297
- if (items.type === "object" && items.properties?.[key]) {
1298
- current = items.properties[key];
1299
- } else {
1300
- return false;
1301
- }
1302
- } else {
1303
- return false;
1304
- }
1305
- }
1306
- current.description = description;
1302
+ const target = getSchemaByPath(schema, path);
1303
+ if (!target) return false;
1304
+ target.description = description;
1307
1305
  return true;
1308
1306
  }
1309
1307
 
package/dist/index.js CHANGED
@@ -509,8 +509,19 @@ function selectionSetToOutputSchema(document, schema) {
509
509
  }
510
510
  function outputTypeToSchema(type, selectionSet, schema) {
511
511
  if (isNonNullType(type)) {
512
- return outputTypeToSchema(type.ofType, selectionSet);
512
+ return nonNullOutputTypeToSchema(type.ofType, selectionSet);
513
513
  }
514
+ const result = nonNullOutputTypeToSchema(type, selectionSet);
515
+ if (typeof result.type !== "string") {
516
+ return { anyOf: [result, { type: "null" }] };
517
+ }
518
+ return {
519
+ ...result,
520
+ type: [result.type, "null"],
521
+ ...result.enum && { enum: [...result.enum, null] }
522
+ };
523
+ }
524
+ function nonNullOutputTypeToSchema(type, selectionSet, schema) {
514
525
  if (isListType(type)) {
515
526
  return {
516
527
  type: "array",
@@ -547,13 +558,14 @@ function getByPath(obj, path) {
547
558
  return current;
548
559
  }
549
560
  function getSchemaByPath(schema, path) {
561
+ const is = (s, t) => [s.type].flat().includes(t);
550
562
  let current = schema;
551
563
  for (const key of path.split(".")) {
552
- if (current.type === "object" && current.properties?.[key]) {
564
+ if (is(current, "object") && current.properties?.[key]) {
553
565
  current = current.properties[key];
554
- } else if (current.type === "array" && current.items) {
566
+ } else if (is(current, "array") && current.items) {
555
567
  const items = current.items;
556
- if (items.type === "object" && items.properties?.[key]) {
568
+ if (is(items, "object") && items.properties?.[key]) {
557
569
  current = items.properties[key];
558
570
  } else {
559
571
  return void 0;
@@ -1285,23 +1297,9 @@ async function handleMCPRequest(ctx, body, options, providerContext) {
1285
1297
  }
1286
1298
  }
1287
1299
  function setSchemaDescriptionByPath(schema, path, description) {
1288
- const keys = path.split(".");
1289
- let current = schema;
1290
- for (const key of keys) {
1291
- if (current.type === "object" && current.properties?.[key]) {
1292
- current = current.properties[key];
1293
- } else if (current.type === "array" && current.items) {
1294
- const items = current.items;
1295
- if (items.type === "object" && items.properties?.[key]) {
1296
- current = items.properties[key];
1297
- } else {
1298
- return false;
1299
- }
1300
- } else {
1301
- return false;
1302
- }
1303
- }
1304
- current.description = description;
1300
+ const target = getSchemaByPath(schema, path);
1301
+ if (!target) return false;
1302
+ target.description = description;
1305
1303
  return true;
1306
1304
  }
1307
1305
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-hive/plugin-mcp",
3
- "version": "0.2.4-alpha-ce8e2f1a5a5d2bd9bcc62d2ece78d8127b4996c7",
3
+ "version": "0.2.4",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -59,7 +59,7 @@
59
59
  }
60
60
  },
61
61
  "dependencies": {
62
- "@graphql-hive/core": "0.24.0",
62
+ "@graphql-hive/core": "0.22.1",
63
63
  "@graphql-hive/logger": "^1.2.0",
64
64
  "@graphql-tools/graphql-file-loader": "^8.1.12",
65
65
  "@graphql-tools/load": "^8.1.8",
@@ -69,12 +69,12 @@
69
69
  "tslib": "^2.8.1"
70
70
  },
71
71
  "devDependencies": {
72
- "@graphql-hive/gateway-runtime": "^2.14.0",
72
+ "@graphql-hive/gateway-runtime": "^2.14.1",
73
73
  "@langfuse/client": "^5.0.2",
74
74
  "@opentelemetry/api": "^1.9.1",
75
75
  "graphql": "^16.13.2",
76
76
  "graphql-yoga": "^5.21.1",
77
- "pkgroll": "2.29.1"
77
+ "pkgroll": "2.27.1"
78
78
  },
79
79
  "sideEffects": false
80
80
  }