@vitemcp/server 1.9.17 → 1.10.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.
Files changed (37) hide show
  1. package/README.md +60 -1
  2. package/dist/ViteMCP.cjs +4 -4
  3. package/dist/ViteMCP.d.cts +18 -1
  4. package/dist/ViteMCP.d.ts +18 -1
  5. package/dist/ViteMCP.js +3 -3
  6. package/dist/auth/index.cjs +2 -2
  7. package/dist/auth/index.d.cts +21 -1
  8. package/dist/auth/index.d.ts +21 -1
  9. package/dist/auth/index.js +1 -1
  10. package/dist/{chunk-B3LLXB6O.js → chunk-3W6VP3KX.js} +32 -11
  11. package/dist/chunk-3W6VP3KX.js.map +1 -0
  12. package/dist/{chunk-ZEYQBA72.cjs → chunk-4LU4AXU4.cjs} +83 -39
  13. package/dist/chunk-4LU4AXU4.cjs.map +1 -0
  14. package/dist/{chunk-JMDI672G.js → chunk-BLXUZUZ4.js} +16 -1
  15. package/dist/chunk-BLXUZUZ4.js.map +1 -0
  16. package/dist/{chunk-TNT3APOK.cjs → chunk-FSPSPB7Y.cjs} +37 -16
  17. package/dist/chunk-FSPSPB7Y.cjs.map +1 -0
  18. package/dist/{chunk-4BX2CT5Z.js → chunk-NLBRDP5F.js} +84 -40
  19. package/dist/{chunk-4BX2CT5Z.js.map → chunk-NLBRDP5F.js.map} +1 -1
  20. package/dist/{chunk-QPVEGWOL.cjs → chunk-NZGRSB2D.cjs} +17 -2
  21. package/dist/chunk-NZGRSB2D.cjs.map +1 -0
  22. package/dist/edge/index.cjs +23 -10
  23. package/dist/edge/index.cjs.map +1 -1
  24. package/dist/edge/index.d.cts +11 -0
  25. package/dist/edge/index.d.ts +11 -0
  26. package/dist/edge/index.js +19 -6
  27. package/dist/edge/index.js.map +1 -1
  28. package/dist/openapi/index.cjs +43 -43
  29. package/dist/openapi/index.cjs.map +1 -1
  30. package/dist/openapi/index.js +33 -33
  31. package/dist/openapi/index.js.map +1 -1
  32. package/package.json +4 -4
  33. package/dist/chunk-B3LLXB6O.js.map +0 -1
  34. package/dist/chunk-JMDI672G.js.map +0 -1
  35. package/dist/chunk-QPVEGWOL.cjs.map +0 -1
  36. package/dist/chunk-TNT3APOK.cjs.map +0 -1
  37. package/dist/chunk-ZEYQBA72.cjs.map +0 -1
package/README.md CHANGED
@@ -748,6 +748,35 @@ server.addTool({
748
748
  });
749
749
  ```
750
750
 
751
+ #### Passing the caller's context
752
+
753
+ `embedded()` runs a loader outside any request, so by default its
754
+ `context.auth` is `undefined` and `canAccess` is not consulted. Pass the tool's
755
+ `context` to resolve the URI as `resources/read` would for that caller: the
756
+ loader receives that context, `auth` included, and a resource or template whose
757
+ `canAccess` refuses the caller is not found.
758
+
759
+ ```js
760
+ server.addTool({
761
+ name: "get_my_profile",
762
+ description: "Retrieve the caller's own profile",
763
+ parameters: z.object({}),
764
+ execute: async (args, context) => {
765
+ return {
766
+ content: [
767
+ {
768
+ type: "resource",
769
+ resource: await server.embedded("user://me", context),
770
+ },
771
+ ],
772
+ };
773
+ },
774
+ });
775
+ ```
776
+
777
+ Pass it whenever the URI comes from the tool's arguments, so the tool cannot
778
+ reach a resource its caller could not read directly.
779
+
751
780
  ### Prompts
752
781
 
753
782
  [Prompts](https://modelcontextprotocol.io/docs/concepts/prompts) enable servers to define reusable prompt templates and workflows that clients can easily surface to users and LLMs. They provide a powerful way to standardize and share common LLM interactions.
@@ -1768,6 +1797,36 @@ const transport = new StreamableHTTPClientTransport(
1768
1797
  await client.connect(transport);
1769
1798
  ```
1770
1799
 
1800
+ #### Request limits
1801
+
1802
+ Two limits bound what one request can make the server do:
1803
+
1804
+ - `httpStream.maxBodySize` caps the MCP endpoint's request body, in bytes
1805
+ (default: 1 MiB). A larger body is refused with a `400`, without being held
1806
+ in memory.
1807
+ - `maxToolInputElements` caps how many array elements and object members,
1808
+ counted together, one `tools/call` may carry in its arguments (default:
1809
+ 10,000). A call over it gets an error result before any schema validates it.
1810
+ The body cap alone does not bound what validation costs: half a million
1811
+ invalid elements fit in 1 MiB.
1812
+
1813
+ ```ts
1814
+ const server = new ViteMCP({
1815
+ name: "Bulk importer",
1816
+ version: "1.0.0",
1817
+ // Its tools take arrays of up to 50,000 numbers.
1818
+ maxToolInputElements: 60_000,
1819
+ });
1820
+
1821
+ server.start({
1822
+ transportType: "httpStream",
1823
+ httpStream: { port: 8080, maxBodySize: 4 * 1024 * 1024 },
1824
+ });
1825
+ ```
1826
+
1827
+ `maxToolInputElements` applies on every transport, stdio included. Pass
1828
+ `Infinity` to lift it.
1829
+
1771
1830
  #### HTTPS Support
1772
1831
 
1773
1832
  Pass SSL certificates to terminate TLS directly:
@@ -2030,7 +2089,7 @@ When running on edge runtimes:
2030
2089
  - **No filesystem access**: Use fetch APIs for external data
2031
2090
  - **V8 Isolates**: Fast cold starts and efficient resource usage
2032
2091
  - **Global deployment**: Automatic distribution to edge locations
2033
- - **Request size**: The MCP endpoint refuses a body over `maxBodySize` (1 MiB by default, as on Node). Routes added through `getApp()` are not covered
2092
+ - **Request size**: The MCP endpoint refuses a body over `maxBodySize` (1 MiB by default, as on Node), and a tool call whose arguments hold more than `maxToolInputElements` elements (10,000 by default, as on Node). Routes added through `getApp()` are not covered
2034
2093
  - **Schema libraries**: Zod, ArkType and Valibot describe a tool as they do on Node. Any other library that carries no JSON Schema of its own is not converted here: a tool written in one is left out and reported through the logger
2035
2094
 
2036
2095
  #### Custom Routes on Edge
package/dist/ViteMCP.cjs CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
 
12
12
 
13
- var _chunkTNT3APOKcjs = require('./chunk-TNT3APOK.cjs');
13
+ var _chunkFSPSPB7Ycjs = require('./chunk-FSPSPB7Y.cjs');
14
14
 
15
15
 
16
16
 
@@ -25,8 +25,8 @@ var _chunkTNT3APOKcjs = require('./chunk-TNT3APOK.cjs');
25
25
 
26
26
 
27
27
 
28
- var _chunkZEYQBA72cjs = require('./chunk-ZEYQBA72.cjs');
29
- require('./chunk-QPVEGWOL.cjs');
28
+ var _chunk4LU4AXU4cjs = require('./chunk-4LU4AXU4.cjs');
29
+ require('./chunk-NZGRSB2D.cjs');
30
30
 
31
31
 
32
32
 
@@ -52,5 +52,5 @@ require('./chunk-QPVEGWOL.cjs');
52
52
 
53
53
 
54
54
 
55
- exports.AuthProvider = _chunkZEYQBA72cjs.AuthProvider; exports.AzureProvider = _chunkZEYQBA72cjs.AzureProvider; exports.DiscoveryDocumentCache = _chunkTNT3APOKcjs.DiscoveryDocumentCache; exports.GitHubProvider = _chunkZEYQBA72cjs.GitHubProvider; exports.GoogleProvider = _chunkZEYQBA72cjs.GoogleProvider; exports.MEDIA_FETCH_TIMEOUT_MS = _chunkTNT3APOKcjs.MEDIA_FETCH_TIMEOUT_MS; exports.OAuthProvider = _chunkZEYQBA72cjs.OAuthProvider; exports.OAuthProxy = _chunkZEYQBA72cjs.OAuthProxy; exports.OAuthProxyError = _chunkZEYQBA72cjs.OAuthProxyError; exports.ServerState = _chunkTNT3APOKcjs.ServerState; exports.UnexpectedStateError = _chunkTNT3APOKcjs.UnexpectedStateError; exports.UserError = _chunkTNT3APOKcjs.UserError; exports.ViteMCP = _chunkTNT3APOKcjs.ViteMCP; exports.ViteMCPError = _chunkTNT3APOKcjs.ViteMCPError; exports.audioContent = _chunkTNT3APOKcjs.audioContent; exports.delay = _chunkTNT3APOKcjs.delay; exports.getAuthSession = _chunkZEYQBA72cjs.getAuthSession; exports.imageContent = _chunkTNT3APOKcjs.imageContent; exports.jsonSchemaAdapter = _chunkTNT3APOKcjs.jsonSchemaAdapter; exports.requireAll = _chunkZEYQBA72cjs.requireAll; exports.requireAny = _chunkZEYQBA72cjs.requireAny; exports.requireAuth = _chunkZEYQBA72cjs.requireAuth; exports.requireRole = _chunkZEYQBA72cjs.requireRole; exports.requireScopes = _chunkZEYQBA72cjs.requireScopes;
55
+ exports.AuthProvider = _chunk4LU4AXU4cjs.AuthProvider; exports.AzureProvider = _chunk4LU4AXU4cjs.AzureProvider; exports.DiscoveryDocumentCache = _chunkFSPSPB7Ycjs.DiscoveryDocumentCache; exports.GitHubProvider = _chunk4LU4AXU4cjs.GitHubProvider; exports.GoogleProvider = _chunk4LU4AXU4cjs.GoogleProvider; exports.MEDIA_FETCH_TIMEOUT_MS = _chunkFSPSPB7Ycjs.MEDIA_FETCH_TIMEOUT_MS; exports.OAuthProvider = _chunk4LU4AXU4cjs.OAuthProvider; exports.OAuthProxy = _chunk4LU4AXU4cjs.OAuthProxy; exports.OAuthProxyError = _chunk4LU4AXU4cjs.OAuthProxyError; exports.ServerState = _chunkFSPSPB7Ycjs.ServerState; exports.UnexpectedStateError = _chunkFSPSPB7Ycjs.UnexpectedStateError; exports.UserError = _chunkFSPSPB7Ycjs.UserError; exports.ViteMCP = _chunkFSPSPB7Ycjs.ViteMCP; exports.ViteMCPError = _chunkFSPSPB7Ycjs.ViteMCPError; exports.audioContent = _chunkFSPSPB7Ycjs.audioContent; exports.delay = _chunkFSPSPB7Ycjs.delay; exports.getAuthSession = _chunk4LU4AXU4cjs.getAuthSession; exports.imageContent = _chunkFSPSPB7Ycjs.imageContent; exports.jsonSchemaAdapter = _chunkFSPSPB7Ycjs.jsonSchemaAdapter; exports.requireAll = _chunk4LU4AXU4cjs.requireAll; exports.requireAny = _chunk4LU4AXU4cjs.requireAny; exports.requireAuth = _chunk4LU4AXU4cjs.requireAuth; exports.requireRole = _chunk4LU4AXU4cjs.requireRole; exports.requireScopes = _chunk4LU4AXU4cjs.requireScopes;
56
56
  //# sourceMappingURL=ViteMCP.cjs.map
@@ -364,6 +364,17 @@ type ServerOptions<T extends ViteMCPAuth> = {
364
364
  icons?: Icon[];
365
365
  instructions?: string;
366
366
  logger?: Logger;
367
+ /**
368
+ * Most array elements and object members, counted together, that one
369
+ * `tools/call` may carry in its arguments (default: 10,000). A call over it
370
+ * gets an error result before any schema sees it. Pass `Infinity` to lift
371
+ * the limit.
372
+ *
373
+ * `httpStream.maxBodySize` alone does not bound the cost of validating a
374
+ * call: half a million invalid elements fit in 1 MiB, and Zod kept half a
375
+ * gigabyte of issues reporting them.
376
+ */
377
+ maxToolInputElements?: number;
367
378
  name: string;
368
379
  oauth?: {
369
380
  authorizationServer?: Record<string, unknown>;
@@ -457,8 +468,14 @@ declare class ViteMCP<T extends ViteMCPAuth = ViteMCPAuth> {
457
468
  /**
458
469
  * Resolves a resource (or resource template) URI to an embeddable resource
459
470
  * body, for returning inline from a tool.
471
+ *
472
+ * Pass the calling tool's `context` to resolve the URI as `resources/read`
473
+ * would for that caller: the loader receives that context, `auth` included,
474
+ * and a resource or template whose `canAccess` refuses the caller is not
475
+ * found. Without one, the loader runs outside any request, with `auth`
476
+ * undefined, and `canAccess` is not consulted.
460
477
  */
461
- embedded(uri: string): Promise<LoadedResource>;
478
+ embedded(uri: string, context?: LoadContext<T>): Promise<LoadedResource>;
462
479
  /** The Hono app serving the HTTP transport, for mounting custom routes. */
463
480
  getApp(): Hono;
464
481
  /**
package/dist/ViteMCP.d.ts CHANGED
@@ -364,6 +364,17 @@ type ServerOptions<T extends ViteMCPAuth> = {
364
364
  icons?: Icon[];
365
365
  instructions?: string;
366
366
  logger?: Logger;
367
+ /**
368
+ * Most array elements and object members, counted together, that one
369
+ * `tools/call` may carry in its arguments (default: 10,000). A call over it
370
+ * gets an error result before any schema sees it. Pass `Infinity` to lift
371
+ * the limit.
372
+ *
373
+ * `httpStream.maxBodySize` alone does not bound the cost of validating a
374
+ * call: half a million invalid elements fit in 1 MiB, and Zod kept half a
375
+ * gigabyte of issues reporting them.
376
+ */
377
+ maxToolInputElements?: number;
367
378
  name: string;
368
379
  oauth?: {
369
380
  authorizationServer?: Record<string, unknown>;
@@ -457,8 +468,14 @@ declare class ViteMCP<T extends ViteMCPAuth = ViteMCPAuth> {
457
468
  /**
458
469
  * Resolves a resource (or resource template) URI to an embeddable resource
459
470
  * body, for returning inline from a tool.
471
+ *
472
+ * Pass the calling tool's `context` to resolve the URI as `resources/read`
473
+ * would for that caller: the loader receives that context, `auth` included,
474
+ * and a resource or template whose `canAccess` refuses the caller is not
475
+ * found. Without one, the loader runs outside any request, with `auth`
476
+ * undefined, and `canAccess` is not consulted.
460
477
  */
461
- embedded(uri: string): Promise<LoadedResource>;
478
+ embedded(uri: string, context?: LoadContext<T>): Promise<LoadedResource>;
462
479
  /** The Hono app serving the HTTP transport, for mounting custom routes. */
463
480
  getApp(): Hono;
464
481
  /**
package/dist/ViteMCP.js CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  delay,
11
11
  imageContent,
12
12
  jsonSchemaAdapter
13
- } from "./chunk-B3LLXB6O.js";
13
+ } from "./chunk-3W6VP3KX.js";
14
14
  import {
15
15
  AuthProvider,
16
16
  AzureProvider,
@@ -25,8 +25,8 @@ import {
25
25
  requireAuth,
26
26
  requireRole,
27
27
  requireScopes
28
- } from "./chunk-4BX2CT5Z.js";
29
- import "./chunk-JMDI672G.js";
28
+ } from "./chunk-NLBRDP5F.js";
29
+ import "./chunk-BLXUZUZ4.js";
30
30
  export {
31
31
  AuthProvider,
32
32
  AzureProvider,
@@ -24,7 +24,7 @@
24
24
 
25
25
 
26
26
 
27
- var _chunkZEYQBA72cjs = require('../chunk-ZEYQBA72.cjs');
27
+ var _chunk4LU4AXU4cjs = require('../chunk-4LU4AXU4.cjs');
28
28
 
29
29
 
30
30
 
@@ -51,5 +51,5 @@ var _chunkZEYQBA72cjs = require('../chunk-ZEYQBA72.cjs');
51
51
 
52
52
 
53
53
 
54
- exports.AuthProvider = _chunkZEYQBA72cjs.AuthProvider; exports.AzureProvider = _chunkZEYQBA72cjs.AzureProvider; exports.ConsentManager = _chunkZEYQBA72cjs.ConsentManager; exports.DEFAULT_ACCESS_TOKEN_TTL = _chunkZEYQBA72cjs.DEFAULT_ACCESS_TOKEN_TTL; exports.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH = _chunkZEYQBA72cjs.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH; exports.DEFAULT_AUTHORIZATION_CODE_TTL = _chunkZEYQBA72cjs.DEFAULT_AUTHORIZATION_CODE_TTL; exports.DEFAULT_REFRESH_TOKEN_TTL = _chunkZEYQBA72cjs.DEFAULT_REFRESH_TOKEN_TTL; exports.DEFAULT_TRANSACTION_TTL = _chunkZEYQBA72cjs.DEFAULT_TRANSACTION_TTL; exports.DiskStore = _chunkZEYQBA72cjs.DiskStore; exports.EncryptedTokenStorage = _chunkZEYQBA72cjs.EncryptedTokenStorage; exports.GitHubProvider = _chunkZEYQBA72cjs.GitHubProvider; exports.GoogleProvider = _chunkZEYQBA72cjs.GoogleProvider; exports.JWKSVerifier = _chunkZEYQBA72cjs.JWKSVerifier; exports.JWTIssuer = _chunkZEYQBA72cjs.JWTIssuer; exports.MemoryTokenStorage = _chunkZEYQBA72cjs.MemoryTokenStorage; exports.OAuthProvider = _chunkZEYQBA72cjs.OAuthProvider; exports.OAuthProxy = _chunkZEYQBA72cjs.OAuthProxy; exports.OAuthProxyError = _chunkZEYQBA72cjs.OAuthProxyError; exports.PKCEUtils = _chunkZEYQBA72cjs.PKCEUtils; exports.getAuthSession = _chunkZEYQBA72cjs.getAuthSession; exports.requireAll = _chunkZEYQBA72cjs.requireAll; exports.requireAny = _chunkZEYQBA72cjs.requireAny; exports.requireAuth = _chunkZEYQBA72cjs.requireAuth; exports.requireRole = _chunkZEYQBA72cjs.requireRole; exports.requireScopes = _chunkZEYQBA72cjs.requireScopes;
54
+ exports.AuthProvider = _chunk4LU4AXU4cjs.AuthProvider; exports.AzureProvider = _chunk4LU4AXU4cjs.AzureProvider; exports.ConsentManager = _chunk4LU4AXU4cjs.ConsentManager; exports.DEFAULT_ACCESS_TOKEN_TTL = _chunk4LU4AXU4cjs.DEFAULT_ACCESS_TOKEN_TTL; exports.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH = _chunk4LU4AXU4cjs.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH; exports.DEFAULT_AUTHORIZATION_CODE_TTL = _chunk4LU4AXU4cjs.DEFAULT_AUTHORIZATION_CODE_TTL; exports.DEFAULT_REFRESH_TOKEN_TTL = _chunk4LU4AXU4cjs.DEFAULT_REFRESH_TOKEN_TTL; exports.DEFAULT_TRANSACTION_TTL = _chunk4LU4AXU4cjs.DEFAULT_TRANSACTION_TTL; exports.DiskStore = _chunk4LU4AXU4cjs.DiskStore; exports.EncryptedTokenStorage = _chunk4LU4AXU4cjs.EncryptedTokenStorage; exports.GitHubProvider = _chunk4LU4AXU4cjs.GitHubProvider; exports.GoogleProvider = _chunk4LU4AXU4cjs.GoogleProvider; exports.JWKSVerifier = _chunk4LU4AXU4cjs.JWKSVerifier; exports.JWTIssuer = _chunk4LU4AXU4cjs.JWTIssuer; exports.MemoryTokenStorage = _chunk4LU4AXU4cjs.MemoryTokenStorage; exports.OAuthProvider = _chunk4LU4AXU4cjs.OAuthProvider; exports.OAuthProxy = _chunk4LU4AXU4cjs.OAuthProxy; exports.OAuthProxyError = _chunk4LU4AXU4cjs.OAuthProxyError; exports.PKCEUtils = _chunk4LU4AXU4cjs.PKCEUtils; exports.getAuthSession = _chunk4LU4AXU4cjs.getAuthSession; exports.requireAll = _chunk4LU4AXU4cjs.requireAll; exports.requireAny = _chunk4LU4AXU4cjs.requireAny; exports.requireAuth = _chunk4LU4AXU4cjs.requireAuth; exports.requireRole = _chunk4LU4AXU4cjs.requireRole; exports.requireScopes = _chunk4LU4AXU4cjs.requireScopes;
55
55
  //# sourceMappingURL=index.cjs.map
@@ -140,9 +140,29 @@ declare class DiskStore implements TokenStorage {
140
140
  */
141
141
  private ensureDirectory;
142
142
  /**
143
- * Get file path for a key
143
+ * Get file path for a key.
144
+ *
145
+ * Named after the key's SHA-256 digest, not the key itself. A digest cannot
146
+ * climb out of the directory, gives distinct keys distinct files (letter
147
+ * case included, which macOS and Windows fold by default), always fits the
148
+ * 255-byte file name limit, and keeps a directory listing from giving the
149
+ * keys away. The `.` sets it apart from every name an earlier version
150
+ * wrote, none of which has one before the extension.
144
151
  */
145
152
  private getFilePath;
153
+ /**
154
+ * Where a key's entry may be: its own file, then the one an earlier version
155
+ * would have written, so that entries persisted before an upgrade survive
156
+ * it.
157
+ */
158
+ private getFilePaths;
159
+ /**
160
+ * The file an earlier version stored a key in, or `undefined` when its name
161
+ * is too long to have ever been written. Every character outside
162
+ * `[a-zA-Z0-9_-]` became `_`, so `client:a.b` and `client:a_b` shared a
163
+ * file, and a key over the limit failed with `ENAMETOOLONG`.
164
+ */
165
+ private getLegacyFilePath;
146
166
  /**
147
167
  * One directory sweep. Always call through {@link cleanup}, which keeps
148
168
  * concurrent sweeps from overlapping.
@@ -140,9 +140,29 @@ declare class DiskStore implements TokenStorage {
140
140
  */
141
141
  private ensureDirectory;
142
142
  /**
143
- * Get file path for a key
143
+ * Get file path for a key.
144
+ *
145
+ * Named after the key's SHA-256 digest, not the key itself. A digest cannot
146
+ * climb out of the directory, gives distinct keys distinct files (letter
147
+ * case included, which macOS and Windows fold by default), always fits the
148
+ * 255-byte file name limit, and keeps a directory listing from giving the
149
+ * keys away. The `.` sets it apart from every name an earlier version
150
+ * wrote, none of which has one before the extension.
144
151
  */
145
152
  private getFilePath;
153
+ /**
154
+ * Where a key's entry may be: its own file, then the one an earlier version
155
+ * would have written, so that entries persisted before an upgrade survive
156
+ * it.
157
+ */
158
+ private getFilePaths;
159
+ /**
160
+ * The file an earlier version stored a key in, or `undefined` when its name
161
+ * is too long to have ever been written. Every character outside
162
+ * `[a-zA-Z0-9_-]` became `_`, so `client:a.b` and `client:a_b` shared a
163
+ * file, and a key over the limit failed with `ENAMETOOLONG`.
164
+ */
165
+ private getLegacyFilePath;
146
166
  /**
147
167
  * One directory sweep. Always call through {@link cleanup}, which keeps
148
168
  * concurrent sweeps from overlapping.
@@ -24,7 +24,7 @@ import {
24
24
  requireAuth,
25
25
  requireRole,
26
26
  requireScopes
27
- } from "../chunk-4BX2CT5Z.js";
27
+ } from "../chunk-NLBRDP5F.js";
28
28
  export {
29
29
  AuthProvider,
30
30
  AzureProvider,
@@ -1,12 +1,13 @@
1
1
  import {
2
2
  withoutTrailingSlash
3
- } from "./chunk-4BX2CT5Z.js";
3
+ } from "./chunk-NLBRDP5F.js";
4
4
  import {
5
5
  formatBytes,
6
6
  ownKeysOnly,
7
+ resolveMaxToolInputElements,
7
8
  toSdkSchema,
8
9
  valibotToJsonSchema
9
- } from "./chunk-JMDI672G.js";
10
+ } from "./chunk-BLXUZUZ4.js";
10
11
 
11
12
  // src/ViteMCP.ts
12
13
  import {
@@ -648,6 +649,7 @@ var ViteMCP = class {
648
649
  #honoApp = new Hono2();
649
650
  #httpServer = null;
650
651
  #logger;
652
+ #maxToolInputElements;
651
653
  #options;
652
654
  #prompts = [];
653
655
  /**
@@ -667,6 +669,9 @@ var ViteMCP = class {
667
669
  constructor(options) {
668
670
  this.#options = options;
669
671
  this.#logger = options.logger ?? console;
672
+ this.#maxToolInputElements = resolveMaxToolInputElements(
673
+ options.maxToolInputElements
674
+ );
670
675
  const provider = options.auth;
671
676
  this.#authenticate = options.authenticate ?? (provider ? ((request) => provider.authenticate(request)) : void 0);
672
677
  this.#honoApp = this.#freshApp();
@@ -747,13 +752,21 @@ var ViteMCP = class {
747
752
  /**
748
753
  * Resolves a resource (or resource template) URI to an embeddable resource
749
754
  * body, for returning inline from a tool.
755
+ *
756
+ * Pass the calling tool's `context` to resolve the URI as `resources/read`
757
+ * would for that caller: the loader receives that context, `auth` included,
758
+ * and a resource or template whose `canAccess` refuses the caller is not
759
+ * found. Without one, the loader runs outside any request, with `auth`
760
+ * undefined, and `canAccess` is not consulted.
750
761
  */
751
- async embedded(uri) {
752
- const direct = this.#resources.find((resource) => resource.uri === uri);
762
+ async embedded(uri, context) {
763
+ const visible = (entry) => !context || !entry.canAccess || entry.canAccess(context.auth);
764
+ const loadContext = () => context ?? this.#makeContext(void 0, void 0).context;
765
+ const direct = this.#resources.find(
766
+ (resource) => resource.uri === uri && visible(resource)
767
+ );
753
768
  if (direct) {
754
- const loaded = await direct.load(
755
- this.#makeContext(void 0, void 0).context
756
- );
769
+ const loaded = await direct.load(loadContext());
757
770
  const first = Array.isArray(loaded) ? loaded[0] : loaded;
758
771
  if (!first) {
759
772
  throw new UnexpectedStateError(`Resource loaded no content: ${uri}`, {
@@ -767,13 +780,16 @@ var ViteMCP = class {
767
780
  };
768
781
  }
769
782
  for (const template of this.#resourceTemplates) {
783
+ if (!visible(template)) {
784
+ continue;
785
+ }
770
786
  const params = new UriTemplate(template.uriTemplate).match(uri);
771
787
  if (!params) {
772
788
  continue;
773
789
  }
774
790
  const loaded = await template.load(
775
791
  params,
776
- this.#makeContext(void 0, void 0).context
792
+ loadContext()
777
793
  );
778
794
  const first = Array.isArray(loaded) ? loaded[0] : loaded;
779
795
  if (!first) {
@@ -939,7 +955,8 @@ var ViteMCP = class {
939
955
  // per-request opt-in, so the `logging/setLevel` it would promise that
940
956
  // client could never take effect.
941
957
  capabilities: era === "legacy" ? {} : { logging: {} },
942
- instructions: this.#options.instructions
958
+ instructions: this.#options.instructions,
959
+ maxToolInputElements: this.#maxToolInputElements
943
960
  }
944
961
  );
945
962
  const visible = (all) => all.filter((entry) => !entry.canAccess || entry.canAccess(auth));
@@ -1276,6 +1293,7 @@ var ViteMCP = class {
1276
1293
  return schemas;
1277
1294
  }
1278
1295
  async #startHttp(config) {
1296
+ const maxBodySize = config.maxBodySize ?? OAUTH_PROXY_MAX_BODY_SIZE;
1279
1297
  this.#handler = createMcpHandler(
1280
1298
  // Authentication has already run in the route below, which is the only
1281
1299
  // place that can turn a refusal into an HTTP status. What reaches here
@@ -1291,6 +1309,10 @@ var ViteMCP = class {
1291
1309
  // Tradeoff: `server/discover` advertises only 2026-07-28, so legacy
1292
1310
  // requests are answered unadvertised and skip Mcp-* validation.
1293
1311
  legacy: config.legacy ?? "stateless",
1312
+ // The SDK reads the body again, under a cap of its own: 4 MiB unless
1313
+ // told otherwise, which refused bodies a larger `maxBodySize` admits.
1314
+ // The request listener has applied this one already.
1315
+ maxRequestBodySize: maxBodySize,
1294
1316
  ...config.enableJsonResponse ? { responseMode: "json" } : {},
1295
1317
  onerror: (error) => this.#logger.error("[ViteMCP error]", error)
1296
1318
  }
@@ -1343,7 +1365,6 @@ var ViteMCP = class {
1343
1365
  return this.#authStore.run(authenticated, () => handler.fetch(c.req.raw));
1344
1366
  });
1345
1367
  const app = this.#honoApp;
1346
- const maxBodySize = config.maxBodySize ?? OAUTH_PROXY_MAX_BODY_SIZE;
1347
1368
  const useTls = Boolean(config.sslCert && config.sslKey);
1348
1369
  const requestListener = (req, res) => {
1349
1370
  void (async () => {
@@ -1690,4 +1711,4 @@ export {
1690
1711
  ServerState,
1691
1712
  ViteMCP
1692
1713
  };
1693
- //# sourceMappingURL=chunk-B3LLXB6O.js.map
1714
+ //# sourceMappingURL=chunk-3W6VP3KX.js.map