@valbuild/mcp 0.154.1 → 0.154.2

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.
@@ -3,8 +3,9 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var asyncToGenerator = require('./asyncToGenerator-8e5c36c8.cjs.prod.js');
6
+ var valMcpMetadata = require('./valMcpMetadata-5fa294f3.cjs.prod.js');
6
7
  var zod = require('zod');
7
- var internal$1 = require('@valbuild/server/internal');
8
+ var server = require('@valbuild/server');
8
9
  var core = require('@valbuild/core');
9
10
  var internal = require('@valbuild/shared/internal');
10
11
  var minimatch = require('minimatch');
@@ -13,7 +14,6 @@ var patch = require('@valbuild/core/patch');
13
14
  var fp = require('@valbuild/core/fp');
14
15
  var fs = require('node:fs/promises');
15
16
  var path = require('node:path');
16
- var server = require('@valbuild/server');
17
17
 
18
18
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
19
19
 
@@ -74,53 +74,6 @@ function _slicedToArray(r, e) {
74
74
  return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
75
75
  }
76
76
 
77
- function _toPrimitive(t, r) {
78
- if ("object" != typeof t || !t) return t;
79
- var e = t[Symbol.toPrimitive];
80
- if (void 0 !== e) {
81
- var i = e.call(t, r || "default");
82
- if ("object" != typeof i) return i;
83
- throw new TypeError("@@toPrimitive must return a primitive value.");
84
- }
85
- return ("string" === r ? String : Number)(t);
86
- }
87
-
88
- function _toPropertyKey(t) {
89
- var i = _toPrimitive(t, "string");
90
- return "symbol" == typeof i ? i : i + "";
91
- }
92
-
93
- function _defineProperty(e, r, t) {
94
- return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
95
- value: t,
96
- enumerable: !0,
97
- configurable: !0,
98
- writable: !0
99
- }) : e[r] = t, e;
100
- }
101
-
102
- function ownKeys(e, r) {
103
- var t = Object.keys(e);
104
- if (Object.getOwnPropertySymbols) {
105
- var o = Object.getOwnPropertySymbols(e);
106
- r && (o = o.filter(function (r) {
107
- return Object.getOwnPropertyDescriptor(e, r).enumerable;
108
- })), t.push.apply(t, o);
109
- }
110
- return t;
111
- }
112
- function _objectSpread2(e) {
113
- for (var r = 1; r < arguments.length; r++) {
114
- var t = null != arguments[r] ? arguments[r] : {};
115
- r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
116
- _defineProperty(e, r, t[r]);
117
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
118
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
119
- });
120
- }
121
- return e;
122
- }
123
-
124
77
  function _objectWithoutPropertiesLoose(r, e) {
125
78
  if (null == r) return {};
126
79
  var t = {};
@@ -238,7 +191,7 @@ function _typeof(o) {
238
191
  * have rejected.
239
192
  */
240
193
  function defineTool(definition, _handler) {
241
- return _objectSpread2(_objectSpread2({}, definition), {}, {
194
+ return valMcpMetadata._objectSpread2(valMcpMetadata._objectSpread2({}, definition), {}, {
242
195
  handler: function handler(args, deps) {
243
196
  return _handler(args, deps);
244
197
  }
@@ -381,14 +334,14 @@ function searchContentTool() {
381
334
  return _context.a(2, err("not-found", args.include || args.exclude ? "No modules matched include/exclude. get_all_schema lists the module paths." : "This project has no Val modules to search."));
382
335
  case 2:
383
336
  built = buildWithDeadline(deps.state, selected, args.timeoutMs);
384
- return _context.a(2, ok(_objectSpread2({
337
+ return _context.a(2, ok(valMcpMetadata._objectSpread2({
385
338
  // Answered per query rather than merged, because which guess found the
386
339
  // thing is most of why several were asked. One query gets a list of
387
340
  // one: a response shape that changes with the arguments is a shape
388
341
  // every caller has to branch on.
389
342
  queries: queries.map(function (query) {
390
343
  var found = internal.performSearch(built.index, query, args.limit, args.offset);
391
- return _objectSpread2({
344
+ return valMcpMetadata._objectSpread2({
392
345
  query: query,
393
346
  results: found.results.map(function (hit) {
394
347
  return {
@@ -834,7 +787,7 @@ function readTools() {
834
787
  }
835
788
  return _context6.a(2, ok(wanted.map(function (patch) {
836
789
  var failure = failures.get(patch.patchId);
837
- return _objectSpread2({
790
+ return valMcpMetadata._objectSpread2({
838
791
  patchId: patch.patchId,
839
792
  moduleFilePath: patch.path,
840
793
  createdAt: patch.createdAt,
@@ -1110,7 +1063,7 @@ function _validateSpeculatively() {
1110
1063
  }
1111
1064
  });
1112
1065
  case 2:
1113
- speculativeSources = _objectSpread2(_objectSpread2({}, state.sources), {}, _defineProperty({}, moduleFilePath, applied.value));
1066
+ speculativeSources = valMcpMetadata._objectSpread2(valMcpMetadata._objectSpread2({}, state.sources), {}, valMcpMetadata._defineProperty({}, moduleFilePath, applied.value));
1114
1067
  _context2.n = 3;
1115
1068
  return blockingErrorsIn(ops, state, speculativeSources, moduleFilePath, pendingFiles);
1116
1069
  case 3:
@@ -1183,7 +1136,7 @@ function _blockingErrorsIn() {
1183
1136
  _context3.n = 2;
1184
1137
  return ops.validateFiles(state.schemas, sources, validation.files, // The pending upload wins over the analysis, and has to: it is the newer
1185
1138
  // answer to "where are this path's bytes", and the analysis predates it.
1186
- _objectSpread2(_objectSpread2({}, state.analysis.fileLastUpdatedByPatchId), pendingFiles));
1139
+ valMcpMetadata._objectSpread2(valMcpMetadata._objectSpread2({}, state.analysis.fileLastUpdatedByPatchId), pendingFiles));
1187
1140
  case 2:
1188
1141
  fileErrors = _context3.v;
1189
1142
  // Merged rather than overwritten: a path can pick up an error from validation
@@ -1774,92 +1727,6 @@ function rejectFileOps(patch) {
1774
1727
  };
1775
1728
  }
1776
1729
 
1777
- /**
1778
- * The public surface of Val's server-side tool registry.
1779
- *
1780
- * Types only, deliberately: this file is the contract that the MCP hosts, the
1781
- * CLI's stdio transport and the tools themselves are all written against, and
1782
- * keeping it free of implementation means those can be built in any order
1783
- * without one of them owning the shape.
1784
- *
1785
- * The design this implements is `docs/plans/mcp.md`, Part A. Two constraints
1786
- * from it are load-bearing and easy to break by accident:
1787
- *
1788
- * 1. **Nothing here may import an MCP SDK.** That is what lets hosts other
1789
- * than the template consume these tools, and it is not hypothetical
1790
- * hygiene — the TypeScript SDK reorganised itself at v2.0.0, and a registry
1791
- * coupled to it would have moved with it.
1792
- * 2. **The result type is deliberately not MCP's `CallToolResult`.** Each host
1793
- * adapts {@link ValToolResult} at its own edge, which is also where an
1794
- * error becomes an in-band `isError` result the model can recover from
1795
- * rather than a transport failure.
1796
- */
1797
-
1798
- /** Why a tool call failed, in a form a host can map onto its own errors. */
1799
-
1800
- /**
1801
- * The same definition with `inputSchema` as JSON Schema, for hosts that want the
1802
- * wire shape rather than a Standard Schema.
1803
- *
1804
- * Typed as whatever zod's own converter produces, so deriving it needs no cast
1805
- * and no second hand-written description of the same input.
1806
- */
1807
-
1808
- /**
1809
- * How the caller was established, and there is one acceptable answer: the host
1810
- * **checked a signature**.
1811
- *
1812
- * A union of one, deliberately. It carried a second variant — a personal access
1813
- * token relayed to the backend unchecked, on the reasoning that the app cannot
1814
- * resolve one and the backend can. The reasoning held; the shape did not. A
1815
- * credential the host cannot check is one it also cannot refuse, so accepting
1816
- * one made "a deployed endpoint that authenticates nobody" a supported
1817
- * configuration, and it let a host serve these tools without ever being told
1818
- * where callers should authorize. The discriminant stays so that adding a
1819
- * second *verified* kind stays a one-line change at every call site.
1820
- */
1821
-
1822
- /**
1823
- * Who is calling, established once per request by the host.
1824
- *
1825
- * `null` means local fs mode, where there is no credential to hold and patches
1826
- * are written with no author, exactly as the Studio does locally (D.1). In
1827
- * proxy mode `null` is refused rather than falling back to the app's own API
1828
- * key: that key can do more than any single user, and quietly substituting it
1829
- * would turn a missing credential into full access.
1830
- */
1831
-
1832
- /**
1833
- * Brand a verified subject as an {@link AuthorId}.
1834
- *
1835
- * `AuthorId` is a branded string so that an id cannot be conjured from any
1836
- * string that happens to be lying around — which is exactly the mistake this
1837
- * type is guarding against. That makes one assertion unavoidable at the boundary
1838
- * where a real id enters the system, so it lives here, once, with a name that
1839
- * says what makes it legitimate: the caller has *verified* this subject, not
1840
- * received it.
1841
- *
1842
- * Do not reach for this to satisfy a type. If you are holding a string you did
1843
- * not verify, the honest value is `null`.
1844
- */
1845
- function authorIdFromVerifiedSubject(subject) {
1846
- return subject;
1847
- }
1848
-
1849
- /** Read access. Every call needs it, the writes included. */
1850
- var VAL_SCOPE_READ = "val:read";
1851
- /** Write access. Needed *in addition* by any tool not marked `readOnlyHint`. */
1852
- var VAL_SCOPE_WRITE = "val:write";
1853
-
1854
- /**
1855
- * The failure half of {@link ValToolResult}, on its own.
1856
- *
1857
- * Named because several internal steps can only fail — speculative validation
1858
- * rejecting a patch, an upload that did not land — and typing those as the
1859
- * whole union means the compiler cannot see that an early return is in fact an
1860
- * error return.
1861
- */
1862
-
1863
1730
  var _excluded = ["handler"],
1864
1731
  _excluded2 = ["handler", "inputSchema"];
1865
1732
  /**
@@ -1882,7 +1749,7 @@ function createValTools(valModules, options) {
1882
1749
  * is read by all, and the content is the head's -- made once per version,
1883
1750
  * not rebuilt per call.
1884
1751
  */
1885
- var ops = internal$1.valRuntime(valModules, options).ops;
1752
+ var ops = server.valRuntime(valModules, options).ops;
1886
1753
  var tools = [].concat(_toConsumableArray(readTools()), _toConsumableArray(writeTools()), _toConsumableArray(extraTools));
1887
1754
  var byName = new Map();
1888
1755
  var _iterator = _createForOfIteratorHelper(tools),
@@ -1917,7 +1784,7 @@ function createValTools(valModules, options) {
1917
1784
  _ref2.handler;
1918
1785
  var inputSchema = _ref2.inputSchema,
1919
1786
  rest = _objectWithoutProperties(_ref2, _excluded2);
1920
- return _objectSpread2(_objectSpread2({}, rest), {}, {
1787
+ return valMcpMetadata._objectSpread2(valMcpMetadata._objectSpread2({}, rest), {}, {
1921
1788
  // zod 4 derives this itself, so there is no JSON-Schema-to-zod
1922
1789
  // converter anywhere in the stack and no second description of the
1923
1790
  // same input to keep in step.
@@ -2231,7 +2098,7 @@ function refuseInsufficientScope(tool, ctx) {
2231
2098
  // wider scope would let a write-but-not-read token through here — today's
2232
2099
  // verifier refuses such a token before this point, but `createValTools` is
2233
2100
  // exported and another host may not.
2234
- var needed = (_tool$annotations = tool.annotations) !== null && _tool$annotations !== void 0 && _tool$annotations.readOnlyHint ? [VAL_SCOPE_READ] : [VAL_SCOPE_READ, VAL_SCOPE_WRITE];
2101
+ var needed = (_tool$annotations = tool.annotations) !== null && _tool$annotations !== void 0 && _tool$annotations.readOnlyHint ? [valMcpMetadata.VAL_SCOPE_READ] : [valMcpMetadata.VAL_SCOPE_READ, valMcpMetadata.VAL_SCOPE_WRITE];
2235
2102
  var granted = ctx.auth.scopes;
2236
2103
  var missing = needed.filter(function (scope) {
2237
2104
  return !granted.includes(scope);
@@ -2350,7 +2217,7 @@ function _load() {
2350
2217
  }
2351
2218
  return _context.a(2, err("internal", "The project ".concat(options.project, " has no remote file buckets configured, so there is nowhere to put a remote image.")));
2352
2219
  case 6:
2353
- return _context.a(2, _objectSpread2({
2220
+ return _context.a(2, valMcpMetadata._objectSpread2({
2354
2221
  status: "success",
2355
2222
  publicProjectId: settings.data.publicProjectId,
2356
2223
  buckets: buckets
@@ -2552,7 +2419,7 @@ function createValImageTools(processor, options) {
2552
2419
  }
2553
2420
  return _context.a(2, prepared.result);
2554
2421
  case 7:
2555
- metadata = _objectSpread2({
2422
+ metadata = valMcpMetadata._objectSpread2({
2556
2423
  width: prepared.width,
2557
2424
  height: prepared.height,
2558
2425
  mimeType: prepared.mimeType
@@ -2637,7 +2504,7 @@ function createValImageTools(processor, options) {
2637
2504
  case 18:
2638
2505
  return _context.a(2, {
2639
2506
  status: "ok",
2640
- data: _objectSpread2(_objectSpread2({}, saved.data), {}, {
2507
+ data: valMcpMetadata._objectSpread2(valMcpMetadata._objectSpread2({}, saved.data), {}, {
2641
2508
  filePath: file.ref,
2642
2509
  remote: file.remote,
2643
2510
  width: prepared.width,
@@ -3160,7 +3027,7 @@ function _uploadToField() {
3160
3027
  built = internal.safeParsePatch([{
3161
3028
  op: "replace",
3162
3029
  path: fieldPath,
3163
- value: _objectSpread2({
3030
+ value: valMcpMetadata._objectSpread2({
3164
3031
  path: file.ref
3165
3032
  }, file.metadata)
3166
3033
  }, {
@@ -3233,7 +3100,7 @@ function _uploadToGalleryBackedField() {
3233
3100
  }
3234
3101
  return _context8.a(2, reloaded.result);
3235
3102
  case 5:
3236
- fresh = _objectSpread2(_objectSpread2({}, deps), {}, {
3103
+ fresh = valMcpMetadata._objectSpread2(valMcpMetadata._objectSpread2({}, deps), {}, {
3237
3104
  state: reloaded.state
3238
3105
  });
3239
3106
  built = internal.safeParsePatch([{
@@ -3283,7 +3150,7 @@ function splitFileOps(patch, deps, file) {
3283
3150
  metadata = file.metadata;
3284
3151
  var textEncoder = new TextEncoder();
3285
3152
  var patchOps = patch.map(function (op) {
3286
- return op.op === "file" && typeof op.value === "string" ? _objectSpread2(_objectSpread2({}, op), {}, {
3153
+ return op.op === "file" && typeof op.value === "string" ? valMcpMetadata._objectSpread2(valMcpMetadata._objectSpread2({}, op), {}, {
3287
3154
  value: core.Internal.getSHA256Hash(textEncoder.encode(op.value))
3288
3155
  }) : op;
3289
3156
  });
@@ -3311,7 +3178,7 @@ function splitFileOps(patch, deps, file) {
3311
3178
  status: "ok",
3312
3179
  // Keyed by the REF, which is what `analyzePatches` will key the real
3313
3180
  // patch by once it exists — the file op carries the ref, not the path.
3314
- files: _defineProperty({}, ref, {
3181
+ files: valMcpMetadata._defineProperty({}, ref, {
3315
3182
  patchId: patchId,
3316
3183
  remote: remote,
3317
3184
  isDelete: false
@@ -3355,10 +3222,14 @@ var packageJson = {
3355
3222
  module: "./sharp/dist/valbuild-mcp-sharp.esm.js",
3356
3223
  "default": "./sharp/dist/valbuild-mcp-sharp.cjs.js"
3357
3224
  },
3225
+ "./metadata": {
3226
+ module: "./metadata/dist/valbuild-mcp-metadata.esm.js",
3227
+ "default": "./metadata/dist/valbuild-mcp-metadata.cjs.js"
3228
+ },
3358
3229
  "./package.json": "./package.json"
3359
3230
  },
3360
3231
  types: "dist/valbuild-mcp.cjs.d.ts",
3361
- version: "0.154.1",
3232
+ version: "0.154.2",
3362
3233
  scripts: {
3363
3234
  typecheck: "tsc --noEmit",
3364
3235
  test: "jest",
@@ -3367,7 +3238,8 @@ var packageJson = {
3367
3238
  preconstruct: {
3368
3239
  entrypoints: [
3369
3240
  "./index.ts",
3370
- "./sharp/index.ts"
3241
+ "./sharp/index.ts",
3242
+ "./metadata/index.ts"
3371
3243
  ],
3372
3244
  exports: true
3373
3245
  },
@@ -3399,7 +3271,9 @@ var packageJson = {
3399
3271
  "CHANGELOG.md",
3400
3272
  "dist",
3401
3273
  "sharp/dist",
3402
- "sharp/package.json"
3274
+ "sharp/package.json",
3275
+ "metadata/dist",
3276
+ "metadata/package.json"
3403
3277
  ]
3404
3278
  };
3405
3279
 
@@ -3892,21 +3766,21 @@ function _verifyValAccessToken() {
3892
3766
  return _context5.a(2, invalidToken("The access token has no subject."));
3893
3767
  case 19:
3894
3768
  scopes = readScopes(payload.scope);
3895
- if (scopes.includes(VAL_SCOPE_READ)) {
3769
+ if (scopes.includes(valMcpMetadata.VAL_SCOPE_READ)) {
3896
3770
  _context5.n = 20;
3897
3771
  break;
3898
3772
  }
3899
3773
  return _context5.a(2, {
3900
3774
  status: "refused",
3901
3775
  error: "insufficient_scope",
3902
- description: "The access token does not have the ".concat(VAL_SCOPE_READ, " scope, so it cannot read any content.")
3776
+ description: "The access token does not have the ".concat(valMcpMetadata.VAL_SCOPE_READ, " scope, so it cannot read any content.")
3903
3777
  });
3904
3778
  case 20:
3905
3779
  return _context5.a(2, {
3906
3780
  status: "ok",
3907
3781
  auth: {
3908
3782
  type: "verified-profile",
3909
- profileId: authorIdFromVerifiedSubject(subject),
3783
+ profileId: valMcpMetadata.authorIdFromVerifiedSubject(subject),
3910
3784
  scopes: scopes
3911
3785
  }
3912
3786
  });
@@ -4024,117 +3898,12 @@ function decodeJsonSegment(segment) {
4024
3898
  if (_typeof(parsed) !== "object" || parsed === null || Array.isArray(parsed)) {
4025
3899
  return null;
4026
3900
  }
4027
- return _objectSpread2({}, parsed);
3901
+ return valMcpMetadata._objectSpread2({}, parsed);
4028
3902
  } catch (_unused3) {
4029
3903
  return null;
4030
3904
  }
4031
3905
  }
4032
3906
 
4033
- /**
4034
- * The one document an MCP client needs before it can authorize: RFC 9728
4035
- * Protected Resource Metadata, served by the *resource* server.
4036
- *
4037
- * This is how a client discovers where to authorize. It asks the resource — this
4038
- * app — and the resource names its authorization server. Which is why this
4039
- * belongs here and the RFC 8414 *authorization server* metadata does not: that
4040
- * document lives at the issuer, describes the issuer's own endpoints, and is
4041
- * served by the issuer. An app serving a copy would be asserting the issuer's
4042
- * configuration on its behalf, and would be wrong the moment the issuer changed
4043
- * anything.
4044
- *
4045
- * The flow, so the split reads as a whole:
4046
- *
4047
- * 1. client → `{app}/api/mcp` with no token → `401` naming this document
4048
- * 2. client → `{app}/.well-known/oauth-protected-resource` → the issuer
4049
- * 3. client → `{issuer}/.well-known/oauth-authorization-server` → endpoints
4050
- * 4. client → issuer's `/authorize`, then `/token`
4051
- * 5. client → `{app}/api/mcp` with the token
4052
- */
4053
-
4054
- var CORS_HEADERS = {
4055
- // The document is public and contains no secrets — it exists to be read by
4056
- // clients whose origin we cannot know in advance, so `*` is the correct value
4057
- // rather than a lazy one. Note there is no `Access-Control-Allow-Credentials`:
4058
- // with it, `*` would be rejected by browsers, and this document is never
4059
- // fetched with credentials.
4060
- "Access-Control-Allow-Origin": "*",
4061
- "Access-Control-Allow-Methods": "GET, OPTIONS",
4062
- "Access-Control-Allow-Headers": "Content-Type, Authorization, MCP-Protocol-Version",
4063
- "Access-Control-Max-Age": "3600"
4064
- };
4065
- function createValMcpMetadata(oauth, scopesSupported) {
4066
- var document = {
4067
- // The resource identifier, which MUST be the value clients send as
4068
- // `resource` and the value that arrives back in `aud`. Same string as the
4069
- // audience this app verifies against — one value, so the two cannot drift.
4070
- resource: oauth.resource,
4071
- authorization_servers: [oauth.issuer],
4072
- scopes_supported: scopesSupported,
4073
- bearer_methods_supported: ["header"]
4074
- };
4075
- var body = JSON.stringify(document);
4076
- return {
4077
- GET: function GET() {
4078
- return new Response(body, {
4079
- status: 200,
4080
- headers: _objectSpread2({
4081
- "Content-Type": "application/json",
4082
- // Cacheable: it changes only when the app is reconfigured, and a
4083
- // client that re-reads it on every authorization costs a round trip
4084
- // for nothing.
4085
- "Cache-Control": "public, max-age=3600"
4086
- }, CORS_HEADERS)
4087
- });
4088
- },
4089
- OPTIONS: function OPTIONS() {
4090
- return new Response(null, {
4091
- status: 204,
4092
- headers: CORS_HEADERS
4093
- });
4094
- }
4095
- };
4096
- }
4097
-
4098
- /**
4099
- * The `WWW-Authenticate` value for a refusal (RFC 6750 section 3, RFC 9728
4100
- * section 5.1).
4101
- *
4102
- * `resource_metadata` is the load-bearing parameter: it is how a client that has
4103
- * never seen this server learns where to authorize. A `401` without it is a dead
4104
- * end — the client knows it needs a token and has no way to find out from where.
4105
- */
4106
- function wwwAuthenticate(oauth, scopesSupported, refusal) {
4107
- var metadataUrl = new URL("/.well-known/oauth-protected-resource", oauth.resource).toString();
4108
- var params = ["resource_metadata=\"".concat(metadataUrl, "\""), "scope=\"".concat(scopesSupported.join(" "), "\"")];
4109
- if (refusal) {
4110
- params.push("error=\"".concat(refusal.error, "\""));
4111
- params.push("error_description=\"".concat(headerSafe(refusal.description), "\""));
4112
- }
4113
- return "Bearer ".concat(params.join(", "));
4114
- }
4115
-
4116
- /**
4117
- * Make a string safe to put inside a quoted header parameter.
4118
- *
4119
- * Three classes go, and the third is the one that matters most:
4120
- *
4121
- * - a **quote** would close the parameter early;
4122
- * - a **backslash** would start an escape the rest of the value does not
4123
- * finish;
4124
- * - a **CR or LF** would end the header line, which is response splitting — an
4125
- * attacker-influenced description could inject a header of their own, or a
4126
- * whole second response.
4127
- *
4128
- * The descriptions passed here today are all literals from this package and
4129
- * contain none of it. That is a property of today's callers rather than of the
4130
- * type, and this function exists so it stays true when a future one interpolates
4131
- * something from a request.
4132
- */
4133
- function headerSafe(value) {
4134
- // eslint-disable-next-line no-control-regex -- the point is to remove them
4135
- return value.replace(/["\\]/g, "").replace(/[\u0000-\u001f\u007f]/g, " ");
4136
- }
4137
-
4138
3907
  /**
4139
3908
  * Val's tools over MCP, and the two checks that have to happen before a request
4140
3909
  * gets to them.
@@ -4170,7 +3939,7 @@ function initValMcp(valModules, config, opts) {
4170
3939
  while (1) switch (_context.n) {
4171
3940
  case 0:
4172
3941
  _context.n = 1;
4173
- return server.initHandlerOptions(route, _objectSpread2(_objectSpread2({}, config), {}, {
3942
+ return server.initHandlerOptions(route, valMcpMetadata._objectSpread2(valMcpMetadata._objectSpread2({}, config), {}, {
4174
3943
  versions: {
4175
3944
  core: coreVersion,
4176
3945
  next: hostVersion
@@ -4180,7 +3949,7 @@ function initValMcp(valModules, config, opts) {
4180
3949
  options = _context.v;
4181
3950
  return _context.a(2, {
4182
3951
  mode: options.mode,
4183
- tools: createValTools(valModules, _objectSpread2(_objectSpread2({}, options), {}, {
3952
+ tools: createValTools(valModules, valMcpMetadata._objectSpread2(valMcpMetadata._objectSpread2({}, options), {}, {
4184
3953
  formatter: opts === null || opts === void 0 ? void 0 : opts.formatter
4185
3954
  }), opts === null || opts === void 0 ? void 0 : opts.extraTools)
4186
3955
  });
@@ -4191,9 +3960,9 @@ function initValMcp(valModules, config, opts) {
4191
3960
  // handled per request
4192
3961
  });
4193
3962
  var oauth = opts === null || opts === void 0 ? void 0 : opts.oauth;
4194
- var scopesSupported = [VAL_SCOPE_READ, VAL_SCOPE_WRITE];
3963
+ var scopesSupported = valMcpMetadata.VAL_SCOPES_SUPPORTED;
4195
3964
  return {
4196
- valMcpMetadata: oauth ? createValMcpMetadata(oauth, scopesSupported) : null,
3965
+ valMcpMetadata: valMcpMetadata.valMcpMetadataOf(oauth),
4197
3966
  valMcpTools: function valMcpTools() {
4198
3967
  return asyncToGenerator._asyncToGenerator(/*#__PURE__*/asyncToGenerator._regenerator().m(function _callee2() {
4199
3968
  return asyncToGenerator._regenerator().w(function (_context2) {
@@ -4312,7 +4081,7 @@ function initValMcp(valModules, config, opts) {
4312
4081
  status: status,
4313
4082
  headers: {
4314
4083
  "Content-Type": "application/json",
4315
- "WWW-Authenticate": wwwAuthenticate(oauth, scopesSupported, {
4084
+ "WWW-Authenticate": valMcpMetadata.wwwAuthenticate(oauth, scopesSupported, {
4316
4085
  error: verified.error,
4317
4086
  description: verified.description
4318
4087
  })
@@ -4460,9 +4229,9 @@ function jsonResponse(status, body) {
4460
4229
  });
4461
4230
  }
4462
4231
 
4463
- exports.VAL_SCOPE_READ = VAL_SCOPE_READ;
4464
- exports.VAL_SCOPE_WRITE = VAL_SCOPE_WRITE;
4465
- exports.authorIdFromVerifiedSubject = authorIdFromVerifiedSubject;
4232
+ exports.VAL_SCOPE_READ = valMcpMetadata.VAL_SCOPE_READ;
4233
+ exports.VAL_SCOPE_WRITE = valMcpMetadata.VAL_SCOPE_WRITE;
4234
+ exports.authorIdFromVerifiedSubject = valMcpMetadata.authorIdFromVerifiedSubject;
4466
4235
  exports.createValImageTools = createValImageTools;
4467
4236
  exports.createValTools = createValTools;
4468
4237
  exports.defineTool = defineTool;