@valbuild/mcp 0.154.0 → 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.
@@ -1,6 +1,8 @@
1
1
  import { _ as _asyncToGenerator, a as _regenerator } from './asyncToGenerator-500f022f.esm.js';
2
+ import { _ as _objectSpread2, a as _defineProperty, V as VAL_SCOPE_READ, b as VAL_SCOPE_WRITE, c as authorIdFromVerifiedSubject, v as valMcpMetadataOf, w as wwwAuthenticate, d as VAL_SCOPES_SUPPORTED } from './valMcpMetadata-fe8120c8.esm.js';
3
+ export { V as VAL_SCOPE_READ, b as VAL_SCOPE_WRITE, c as authorIdFromVerifiedSubject } from './valMcpMetadata-fe8120c8.esm.js';
2
4
  import { z } from 'zod';
3
- import { valRuntime } from '@valbuild/server/internal';
5
+ import { valRuntime, getSettings, resolveRemoteFileAuth, getFileExt, initHandlerOptions } from '@valbuild/server';
4
6
  import { Internal, getSourcePathFromRoute, DEFAULT_VAL_REMOTE_HOST } from '@valbuild/core';
5
7
  import { performSearch, createSearchIndex, indexModule, filterBlockingValidationErrors, describeContainerAtPath, chainHeadOf, safeParsePatch, buildDuplicatePatch, buildEmptyAtPathPatch, declaredLocales, buildRemoveImageGalleryEntryPatch, resolveEncodeSettings, resolveSerializedSchemaAtPath, withExtension, fitWithin, isSkippedSource, ENCODE_MIME_TYPE_OF, isMimeTypeAccepted, chooseEncoded, buildImageGalleryPatch } from '@valbuild/shared/internal';
6
8
  import { minimatch } from 'minimatch';
@@ -9,7 +11,6 @@ import { JSONOps, applyPatch, deepClone } from '@valbuild/core/patch';
9
11
  import { result } from '@valbuild/core/fp';
10
12
  import fs from 'node:fs/promises';
11
13
  import path from 'node:path';
12
- import { getSettings, resolveRemoteFileAuth, getFileExt, initHandlerOptions } from '@valbuild/server';
13
14
 
14
15
  function _arrayWithHoles(r) {
15
16
  if (Array.isArray(r)) return r;
@@ -65,53 +66,6 @@ function _slicedToArray(r, e) {
65
66
  return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
66
67
  }
67
68
 
68
- function _toPrimitive(t, r) {
69
- if ("object" != typeof t || !t) return t;
70
- var e = t[Symbol.toPrimitive];
71
- if (void 0 !== e) {
72
- var i = e.call(t, r || "default");
73
- if ("object" != typeof i) return i;
74
- throw new TypeError("@@toPrimitive must return a primitive value.");
75
- }
76
- return ("string" === r ? String : Number)(t);
77
- }
78
-
79
- function _toPropertyKey(t) {
80
- var i = _toPrimitive(t, "string");
81
- return "symbol" == typeof i ? i : i + "";
82
- }
83
-
84
- function _defineProperty(e, r, t) {
85
- return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
86
- value: t,
87
- enumerable: !0,
88
- configurable: !0,
89
- writable: !0
90
- }) : e[r] = t, e;
91
- }
92
-
93
- function ownKeys(e, r) {
94
- var t = Object.keys(e);
95
- if (Object.getOwnPropertySymbols) {
96
- var o = Object.getOwnPropertySymbols(e);
97
- r && (o = o.filter(function (r) {
98
- return Object.getOwnPropertyDescriptor(e, r).enumerable;
99
- })), t.push.apply(t, o);
100
- }
101
- return t;
102
- }
103
- function _objectSpread2(e) {
104
- for (var r = 1; r < arguments.length; r++) {
105
- var t = null != arguments[r] ? arguments[r] : {};
106
- r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
107
- _defineProperty(e, r, t[r]);
108
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
109
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
110
- });
111
- }
112
- return e;
113
- }
114
-
115
69
  function _objectWithoutPropertiesLoose(r, e) {
116
70
  if (null == r) return {};
117
71
  var t = {};
@@ -1765,92 +1719,6 @@ function rejectFileOps(patch) {
1765
1719
  };
1766
1720
  }
1767
1721
 
1768
- /**
1769
- * The public surface of Val's server-side tool registry.
1770
- *
1771
- * Types only, deliberately: this file is the contract that the MCP hosts, the
1772
- * CLI's stdio transport and the tools themselves are all written against, and
1773
- * keeping it free of implementation means those can be built in any order
1774
- * without one of them owning the shape.
1775
- *
1776
- * The design this implements is `docs/plans/mcp.md`, Part A. Two constraints
1777
- * from it are load-bearing and easy to break by accident:
1778
- *
1779
- * 1. **Nothing here may import an MCP SDK.** That is what lets hosts other
1780
- * than the template consume these tools, and it is not hypothetical
1781
- * hygiene — the TypeScript SDK reorganised itself at v2.0.0, and a registry
1782
- * coupled to it would have moved with it.
1783
- * 2. **The result type is deliberately not MCP's `CallToolResult`.** Each host
1784
- * adapts {@link ValToolResult} at its own edge, which is also where an
1785
- * error becomes an in-band `isError` result the model can recover from
1786
- * rather than a transport failure.
1787
- */
1788
-
1789
- /** Why a tool call failed, in a form a host can map onto its own errors. */
1790
-
1791
- /**
1792
- * The same definition with `inputSchema` as JSON Schema, for hosts that want the
1793
- * wire shape rather than a Standard Schema.
1794
- *
1795
- * Typed as whatever zod's own converter produces, so deriving it needs no cast
1796
- * and no second hand-written description of the same input.
1797
- */
1798
-
1799
- /**
1800
- * How the caller was established, and there is one acceptable answer: the host
1801
- * **checked a signature**.
1802
- *
1803
- * A union of one, deliberately. It carried a second variant — a personal access
1804
- * token relayed to the backend unchecked, on the reasoning that the app cannot
1805
- * resolve one and the backend can. The reasoning held; the shape did not. A
1806
- * credential the host cannot check is one it also cannot refuse, so accepting
1807
- * one made "a deployed endpoint that authenticates nobody" a supported
1808
- * configuration, and it let a host serve these tools without ever being told
1809
- * where callers should authorize. The discriminant stays so that adding a
1810
- * second *verified* kind stays a one-line change at every call site.
1811
- */
1812
-
1813
- /**
1814
- * Who is calling, established once per request by the host.
1815
- *
1816
- * `null` means local fs mode, where there is no credential to hold and patches
1817
- * are written with no author, exactly as the Studio does locally (D.1). In
1818
- * proxy mode `null` is refused rather than falling back to the app's own API
1819
- * key: that key can do more than any single user, and quietly substituting it
1820
- * would turn a missing credential into full access.
1821
- */
1822
-
1823
- /**
1824
- * Brand a verified subject as an {@link AuthorId}.
1825
- *
1826
- * `AuthorId` is a branded string so that an id cannot be conjured from any
1827
- * string that happens to be lying around — which is exactly the mistake this
1828
- * type is guarding against. That makes one assertion unavoidable at the boundary
1829
- * where a real id enters the system, so it lives here, once, with a name that
1830
- * says what makes it legitimate: the caller has *verified* this subject, not
1831
- * received it.
1832
- *
1833
- * Do not reach for this to satisfy a type. If you are holding a string you did
1834
- * not verify, the honest value is `null`.
1835
- */
1836
- function authorIdFromVerifiedSubject(subject) {
1837
- return subject;
1838
- }
1839
-
1840
- /** Read access. Every call needs it, the writes included. */
1841
- var VAL_SCOPE_READ = "val:read";
1842
- /** Write access. Needed *in addition* by any tool not marked `readOnlyHint`. */
1843
- var VAL_SCOPE_WRITE = "val:write";
1844
-
1845
- /**
1846
- * The failure half of {@link ValToolResult}, on its own.
1847
- *
1848
- * Named because several internal steps can only fail — speculative validation
1849
- * rejecting a patch, an upload that did not land — and typing those as the
1850
- * whole union means the compiler cannot see that an early return is in fact an
1851
- * error return.
1852
- */
1853
-
1854
1722
  var _excluded = ["handler"],
1855
1723
  _excluded2 = ["handler", "inputSchema"];
1856
1724
  /**
@@ -3346,10 +3214,14 @@ var packageJson = {
3346
3214
  module: "./sharp/dist/valbuild-mcp-sharp.esm.js",
3347
3215
  "default": "./sharp/dist/valbuild-mcp-sharp.cjs.js"
3348
3216
  },
3217
+ "./metadata": {
3218
+ module: "./metadata/dist/valbuild-mcp-metadata.esm.js",
3219
+ "default": "./metadata/dist/valbuild-mcp-metadata.cjs.js"
3220
+ },
3349
3221
  "./package.json": "./package.json"
3350
3222
  },
3351
3223
  types: "dist/valbuild-mcp.cjs.d.ts",
3352
- version: "0.154.0",
3224
+ version: "0.154.2",
3353
3225
  scripts: {
3354
3226
  typecheck: "tsc --noEmit",
3355
3227
  test: "jest",
@@ -3358,7 +3230,8 @@ var packageJson = {
3358
3230
  preconstruct: {
3359
3231
  entrypoints: [
3360
3232
  "./index.ts",
3361
- "./sharp/index.ts"
3233
+ "./sharp/index.ts",
3234
+ "./metadata/index.ts"
3362
3235
  ],
3363
3236
  exports: true
3364
3237
  },
@@ -3390,7 +3263,9 @@ var packageJson = {
3390
3263
  "CHANGELOG.md",
3391
3264
  "dist",
3392
3265
  "sharp/dist",
3393
- "sharp/package.json"
3266
+ "sharp/package.json",
3267
+ "metadata/dist",
3268
+ "metadata/package.json"
3394
3269
  ]
3395
3270
  };
3396
3271
 
@@ -4021,111 +3896,6 @@ function decodeJsonSegment(segment) {
4021
3896
  }
4022
3897
  }
4023
3898
 
4024
- /**
4025
- * The one document an MCP client needs before it can authorize: RFC 9728
4026
- * Protected Resource Metadata, served by the *resource* server.
4027
- *
4028
- * This is how a client discovers where to authorize. It asks the resource — this
4029
- * app — and the resource names its authorization server. Which is why this
4030
- * belongs here and the RFC 8414 *authorization server* metadata does not: that
4031
- * document lives at the issuer, describes the issuer's own endpoints, and is
4032
- * served by the issuer. An app serving a copy would be asserting the issuer's
4033
- * configuration on its behalf, and would be wrong the moment the issuer changed
4034
- * anything.
4035
- *
4036
- * The flow, so the split reads as a whole:
4037
- *
4038
- * 1. client → `{app}/api/mcp` with no token → `401` naming this document
4039
- * 2. client → `{app}/.well-known/oauth-protected-resource` → the issuer
4040
- * 3. client → `{issuer}/.well-known/oauth-authorization-server` → endpoints
4041
- * 4. client → issuer's `/authorize`, then `/token`
4042
- * 5. client → `{app}/api/mcp` with the token
4043
- */
4044
-
4045
- var CORS_HEADERS = {
4046
- // The document is public and contains no secrets — it exists to be read by
4047
- // clients whose origin we cannot know in advance, so `*` is the correct value
4048
- // rather than a lazy one. Note there is no `Access-Control-Allow-Credentials`:
4049
- // with it, `*` would be rejected by browsers, and this document is never
4050
- // fetched with credentials.
4051
- "Access-Control-Allow-Origin": "*",
4052
- "Access-Control-Allow-Methods": "GET, OPTIONS",
4053
- "Access-Control-Allow-Headers": "Content-Type, Authorization, MCP-Protocol-Version",
4054
- "Access-Control-Max-Age": "3600"
4055
- };
4056
- function createValMcpMetadata(oauth, scopesSupported) {
4057
- var document = {
4058
- // The resource identifier, which MUST be the value clients send as
4059
- // `resource` and the value that arrives back in `aud`. Same string as the
4060
- // audience this app verifies against — one value, so the two cannot drift.
4061
- resource: oauth.resource,
4062
- authorization_servers: [oauth.issuer],
4063
- scopes_supported: scopesSupported,
4064
- bearer_methods_supported: ["header"]
4065
- };
4066
- var body = JSON.stringify(document);
4067
- return {
4068
- GET: function GET() {
4069
- return new Response(body, {
4070
- status: 200,
4071
- headers: _objectSpread2({
4072
- "Content-Type": "application/json",
4073
- // Cacheable: it changes only when the app is reconfigured, and a
4074
- // client that re-reads it on every authorization costs a round trip
4075
- // for nothing.
4076
- "Cache-Control": "public, max-age=3600"
4077
- }, CORS_HEADERS)
4078
- });
4079
- },
4080
- OPTIONS: function OPTIONS() {
4081
- return new Response(null, {
4082
- status: 204,
4083
- headers: CORS_HEADERS
4084
- });
4085
- }
4086
- };
4087
- }
4088
-
4089
- /**
4090
- * The `WWW-Authenticate` value for a refusal (RFC 6750 section 3, RFC 9728
4091
- * section 5.1).
4092
- *
4093
- * `resource_metadata` is the load-bearing parameter: it is how a client that has
4094
- * never seen this server learns where to authorize. A `401` without it is a dead
4095
- * end — the client knows it needs a token and has no way to find out from where.
4096
- */
4097
- function wwwAuthenticate(oauth, scopesSupported, refusal) {
4098
- var metadataUrl = new URL("/.well-known/oauth-protected-resource", oauth.resource).toString();
4099
- var params = ["resource_metadata=\"".concat(metadataUrl, "\""), "scope=\"".concat(scopesSupported.join(" "), "\"")];
4100
- if (refusal) {
4101
- params.push("error=\"".concat(refusal.error, "\""));
4102
- params.push("error_description=\"".concat(headerSafe(refusal.description), "\""));
4103
- }
4104
- return "Bearer ".concat(params.join(", "));
4105
- }
4106
-
4107
- /**
4108
- * Make a string safe to put inside a quoted header parameter.
4109
- *
4110
- * Three classes go, and the third is the one that matters most:
4111
- *
4112
- * - a **quote** would close the parameter early;
4113
- * - a **backslash** would start an escape the rest of the value does not
4114
- * finish;
4115
- * - a **CR or LF** would end the header line, which is response splitting — an
4116
- * attacker-influenced description could inject a header of their own, or a
4117
- * whole second response.
4118
- *
4119
- * The descriptions passed here today are all literals from this package and
4120
- * contain none of it. That is a property of today's callers rather than of the
4121
- * type, and this function exists so it stays true when a future one interpolates
4122
- * something from a request.
4123
- */
4124
- function headerSafe(value) {
4125
- // eslint-disable-next-line no-control-regex -- the point is to remove them
4126
- return value.replace(/["\\]/g, "").replace(/[\u0000-\u001f\u007f]/g, " ");
4127
- }
4128
-
4129
3899
  /**
4130
3900
  * Val's tools over MCP, and the two checks that have to happen before a request
4131
3901
  * gets to them.
@@ -4182,9 +3952,9 @@ function initValMcp(valModules, config, opts) {
4182
3952
  // handled per request
4183
3953
  });
4184
3954
  var oauth = opts === null || opts === void 0 ? void 0 : opts.oauth;
4185
- var scopesSupported = [VAL_SCOPE_READ, VAL_SCOPE_WRITE];
3955
+ var scopesSupported = VAL_SCOPES_SUPPORTED;
4186
3956
  return {
4187
- valMcpMetadata: oauth ? createValMcpMetadata(oauth, scopesSupported) : null,
3957
+ valMcpMetadata: valMcpMetadataOf(oauth),
4188
3958
  valMcpTools: function valMcpTools() {
4189
3959
  return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
4190
3960
  return _regenerator().w(function (_context2) {
@@ -4451,4 +4221,4 @@ function jsonResponse(status, body) {
4451
4221
  });
4452
4222
  }
4453
4223
 
4454
- export { VAL_SCOPE_READ, VAL_SCOPE_WRITE, authorIdFromVerifiedSubject, createValImageTools, createValTools, defineTool, err, initValMcp, ok, savePatch };
4224
+ export { createValImageTools, createValTools, defineTool, err, initValMcp, ok, savePatch };
@@ -0,0 +1,2 @@
1
+ export * from "../../dist/declarations/src/metadata/index.js";
2
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmFsYnVpbGQtbWNwLW1ldGFkYXRhLmNqcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vZGlzdC9kZWNsYXJhdGlvbnMvc3JjL21ldGFkYXRhL2luZGV4LmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var valMcpMetadata = require('../../dist/valMcpMetadata-d03c8610.cjs.dev.js');
6
+
7
+
8
+
9
+ exports.VAL_SCOPES_SUPPORTED = valMcpMetadata.VAL_SCOPES_SUPPORTED;
10
+ exports.createValMcpMetadata = valMcpMetadata.createValMcpMetadata;
11
+ exports.valMcpMetadataOf = valMcpMetadata.valMcpMetadataOf;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./valbuild-mcp-metadata.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./valbuild-mcp-metadata.cjs.dev.js");
7
+ }
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var valMcpMetadata = require('../../dist/valMcpMetadata-5fa294f3.cjs.prod.js');
6
+
7
+
8
+
9
+ exports.VAL_SCOPES_SUPPORTED = valMcpMetadata.VAL_SCOPES_SUPPORTED;
10
+ exports.createValMcpMetadata = valMcpMetadata.createValMcpMetadata;
11
+ exports.valMcpMetadataOf = valMcpMetadata.valMcpMetadataOf;
@@ -0,0 +1 @@
1
+ export { d as VAL_SCOPES_SUPPORTED, e as createValMcpMetadata, v as valMcpMetadataOf } from '../../dist/valMcpMetadata-fe8120c8.esm.js';
@@ -0,0 +1,4 @@
1
+ {
2
+ "main": "dist/valbuild-mcp-metadata.cjs.js",
3
+ "module": "dist/valbuild-mcp-metadata.esm.js"
4
+ }
package/package.json CHANGED
@@ -17,23 +17,28 @@
17
17
  "module": "./sharp/dist/valbuild-mcp-sharp.esm.js",
18
18
  "default": "./sharp/dist/valbuild-mcp-sharp.cjs.js"
19
19
  },
20
+ "./metadata": {
21
+ "module": "./metadata/dist/valbuild-mcp-metadata.esm.js",
22
+ "default": "./metadata/dist/valbuild-mcp-metadata.cjs.js"
23
+ },
20
24
  "./package.json": "./package.json"
21
25
  },
22
26
  "types": "dist/valbuild-mcp.cjs.d.ts",
23
- "version": "0.154.0",
27
+ "version": "0.154.2",
24
28
  "preconstruct": {
25
29
  "entrypoints": [
26
30
  "./index.ts",
27
- "./sharp/index.ts"
31
+ "./sharp/index.ts",
32
+ "./metadata/index.ts"
28
33
  ],
29
34
  "exports": true
30
35
  },
31
36
  "dependencies": {
32
37
  "minimatch": "^10.2.6",
33
38
  "zod": "^4.6.6",
34
- "@valbuild/core": "0.153.5",
35
- "@valbuild/server": "0.154.0",
36
- "@valbuild/shared": "0.154.0"
39
+ "@valbuild/core": "0.154.2",
40
+ "@valbuild/server": "0.154.2",
41
+ "@valbuild/shared": "0.154.2"
37
42
  },
38
43
  "devDependencies": {
39
44
  "@prettier/sync": "^0.6.1",
@@ -56,7 +61,9 @@
56
61
  "CHANGELOG.md",
57
62
  "dist",
58
63
  "sharp/dist",
59
- "sharp/package.json"
64
+ "sharp/package.json",
65
+ "metadata/dist",
66
+ "metadata/package.json"
60
67
  ],
61
68
  "scripts": {
62
69
  "typecheck": "tsc --noEmit",