@mcp-web/mcpb 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 Fritz Lekschas
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,148 @@
1
+ # @mcp-web/mcpb
2
+
3
+ Generate pre-configured MCPB bundles for one-click installation in Claude Desktop.
4
+
5
+ ## Overview
6
+
7
+ `@mcp-web/mcpb` enables websites running MCP-Web to generate `.mcpb` files (MCP Bundle format) that users can install in Claude Desktop with a single click. The auth token and bridge connection URL are pre-baked into the bundle, eliminating any manual configuration.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @mcp-web/mcpb
13
+ # or
14
+ pnpm add @mcp-web/mcpb
15
+ # or
16
+ yarn add @mcp-web/mcpb
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ### Basic Example
22
+
23
+ ```typescript
24
+ import { MCPWeb } from '@mcp-web/core';
25
+ import { getMcpBundle } from '@mcp-web/mcpb';
26
+
27
+ // Create your MCP-Web instance
28
+ const mcp = new MCPWeb({
29
+ name: 'My Todo App',
30
+ description: 'AI-controllable todo application',
31
+ autoConnect: true,
32
+ });
33
+
34
+ // Register your tools
35
+ mcp.addTool({
36
+ name: 'create_todo',
37
+ description: 'Create a new todo',
38
+ handler: (input) => {
39
+ // Your logic here
40
+ },
41
+ });
42
+
43
+ // Generate MCPB bundle
44
+ async function handleInstallClick() {
45
+ const bundle = await getMcpBundle(mcp, {
46
+ displayName: 'My Todo App - Claude Extension',
47
+ version: '1.0.0',
48
+ author: {
49
+ name: 'Your Name',
50
+ url: 'https://yourwebsite.com'
51
+ }
52
+ });
53
+
54
+ // Trigger browser download
55
+ bundle.download();
56
+ }
57
+ ```
58
+
59
+ ### With Icon
60
+
61
+ ```typescript
62
+ const bundle = await getMcpBundle(mcp, {
63
+ displayName: 'My App',
64
+ version: '1.0.0',
65
+ icon: 'https://yourwebsite.com/icon.png', // URL to icon
66
+ // or
67
+ icon: iconBlob, // Blob object
68
+ });
69
+ ```
70
+
71
+ ### Custom Client Bundle URL
72
+
73
+ If you want to host the client bundle yourself:
74
+
75
+ ```typescript
76
+ const bundle = await getMcpBundle(mcp, {
77
+ clientBundleUrl: 'https://yourcdn.com/mcp-web-client.js',
78
+ });
79
+ ```
80
+
81
+ ## API
82
+
83
+ ### `getMcpBundle(mcpWeb, options?)`
84
+
85
+ Generates a pre-configured MCPB bundle.
86
+
87
+ **Parameters:**
88
+ - `mcpWeb` (MCPWeb): The MCPWeb instance to create a bundle for
89
+ - `options` (McpBundleOptions, optional):
90
+ - `displayName` (string): Display name in Claude Desktop (defaults to mcpWeb config name)
91
+ - `version` (string): Semantic version (defaults to "1.0.0")
92
+ - `description` (string): Bundle description (defaults to mcpWeb config description)
93
+ - `author` (object): Author info with `name`, `email`, and `url` fields
94
+ - `icon` (string | Blob): Icon as URL or Blob (PNG recommended)
95
+ - `clientBundleUrl` (string): Custom URL for client bundle
96
+
97
+ **Returns:** `Promise<McpBundleResult>`
98
+ - `blob` (Blob): The .mcpb file as a Blob
99
+ - `filename` (string): Suggested filename (e.g., "my-app.mcpb")
100
+ - `download()` (function): Helper to trigger browser download
101
+
102
+ ## How It Works
103
+
104
+ 1. **Generate Manifest**: Creates a `manifest.json` with pre-baked environment variables:
105
+ - `MCP_SERVER_URL`: Bridge connection URL
106
+ - `AUTH_TOKEN`: Unique authentication token
107
+
108
+ 2. **Fetch Client Bundle**: Downloads the standalone `@mcp-web/client` from CDN (unpkg with jsdelivr fallback)
109
+
110
+ 3. **Create Archive**: Packages everything into a `.mcpb` zip file:
111
+ ```
112
+ my-app.mcpb
113
+ ├── manifest.json
114
+ ├── server/
115
+ │ └── index.js (standalone client)
116
+ └── icon.png (optional)
117
+ ```
118
+
119
+ 4. **Download**: User downloads the `.mcpb` file and double-clicks to install in Claude Desktop
120
+
121
+ ## User Experience
122
+
123
+ From the user's perspective:
124
+
125
+ 1. Visit your website
126
+ 2. Click "Install Extension" button
127
+ 3. Download `.mcpb` file
128
+ 4. Double-click to open with Claude Desktop
129
+ 5. Click "Install"
130
+ 6. Done! No configuration needed.
131
+
132
+ ## Security
133
+
134
+ The auth token is:
135
+ - **User-specific**: Generated uniquely for each user
136
+ - **Permanent**: Valid until explicitly revoked
137
+ - **Local**: Stored only on the user's machine
138
+ - **Equivalent** to manually editing Claude Desktop's config file
139
+
140
+ ## Requirements
141
+
142
+ - Node.js 22+ (specified in bundle manifest)
143
+ - Browser environment with `fetch` and `Blob` support
144
+ - Network access to CDN (unless using custom `clientBundleUrl`)
145
+
146
+ ## License
147
+
148
+ MIT
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Fetches the pre-built @mcp-web/client standalone bundle from CDN.
3
+ *
4
+ * Tries the primary CDN (unpkg) first, then falls back to jsdelivr if that fails.
5
+ * If a custom URL is provided, only that URL is tried.
6
+ *
7
+ * @param customUrl - Optional custom URL to fetch the bundle from
8
+ * @returns The client bundle code as a string
9
+ * @throws Error if all CDN attempts fail
10
+ */
11
+ export declare function fetchClientBundle(customUrl?: string): Promise<string>;
12
+ //# sourceMappingURL=fetch-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-client.d.ts","sourceRoot":"","sources":["../src/fetch-client.ts"],"names":[],"mappings":"AAaA;;;;;;;;;GASG;AACH,wBAAsB,iBAAiB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAkB3E"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Default CDN URL for fetching the @mcp-web/client standalone bundle.
3
+ * Uses unpkg as the primary CDN.
4
+ */
5
+ const DEFAULT_CDN_URL = 'https://unpkg.com/@mcp-web/client@latest/dist/standalone.js';
6
+ /**
7
+ * Fallback CDN URL using jsdelivr.
8
+ */
9
+ const FALLBACK_CDN_URL = 'https://cdn.jsdelivr.net/npm/@mcp-web/client@latest/dist/standalone.js';
10
+ /**
11
+ * Fetches the pre-built @mcp-web/client standalone bundle from CDN.
12
+ *
13
+ * Tries the primary CDN (unpkg) first, then falls back to jsdelivr if that fails.
14
+ * If a custom URL is provided, only that URL is tried.
15
+ *
16
+ * @param customUrl - Optional custom URL to fetch the bundle from
17
+ * @returns The client bundle code as a string
18
+ * @throws Error if all CDN attempts fail
19
+ */
20
+ export async function fetchClientBundle(customUrl) {
21
+ const urls = customUrl ? [customUrl] : [DEFAULT_CDN_URL, FALLBACK_CDN_URL];
22
+ for (const url of urls) {
23
+ try {
24
+ const response = await fetch(url);
25
+ if (response.ok) {
26
+ return await response.text();
27
+ }
28
+ }
29
+ catch (error) {
30
+ // Try next URL
31
+ console.warn(`Failed to fetch client bundle from ${url}:`, error);
32
+ }
33
+ }
34
+ throw new Error('Failed to fetch @mcp-web/client bundle from CDN. Please check your network connection or provide a custom clientBundleUrl.');
35
+ }
36
+ //# sourceMappingURL=fetch-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-client.js","sourceRoot":"","sources":["../src/fetch-client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,eAAe,GACnB,6DAA6D,CAAC;AAEhE;;GAEG;AACH,MAAM,gBAAgB,GACpB,wEAAwE,CAAC;AAE3E;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,SAAkB;IACxD,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAC;IAE3E,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;YAClC,IAAI,QAAQ,CAAC,EAAE,EAAE,CAAC;gBAChB,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YAC/B,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,eAAe;YACf,OAAO,CAAC,IAAI,CAAC,sCAAsC,GAAG,GAAG,EAAE,KAAK,CAAC,CAAC;QACpE,CAAC;IACH,CAAC;IAED,MAAM,IAAI,KAAK,CACb,4HAA4H,CAC7H,CAAC;AACJ,CAAC"}
@@ -0,0 +1,40 @@
1
+ import type { MCPWeb } from '@mcp-web/core';
2
+ import type { McpBundleOptions, McpBundleResult } from './types.js';
3
+ /**
4
+ * Generates a pre-configured MCPB bundle for installation in Claude Desktop.
5
+ *
6
+ * This function creates a `.mcpb` file (which is a zip archive) containing:
7
+ * - manifest.json with pre-baked MCP_SERVER_URL and AUTH_TOKEN
8
+ * - server/index.js (the standalone @mcp-web/client bundle)
9
+ * - icon.png (optional, if provided in options)
10
+ *
11
+ * The resulting bundle can be installed in Claude Desktop with a single click,
12
+ * with no manual configuration required.
13
+ *
14
+ * @param mcpWeb - The MCPWeb instance to generate a bundle for
15
+ * @param options - Optional customization options
16
+ * @returns Promise resolving to the bundle result with blob, filename, and download helper
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * import { MCPWeb } from '@mcp-web/core';
21
+ * import { getMcpBundle } from '@mcp-web/mcpb';
22
+ *
23
+ * const mcp = new MCPWeb({
24
+ * name: 'My Todo App',
25
+ * description: 'AI-controllable todo application',
26
+ * autoConnect: true,
27
+ * });
28
+ *
29
+ * // Generate and download bundle
30
+ * const bundle = await getMcpBundle(mcp, {
31
+ * displayName: 'My Todo App - Claude Extension',
32
+ * version: '1.0.0',
33
+ * author: { name: 'Acme Corp', url: 'https://acme.com' }
34
+ * });
35
+ *
36
+ * bundle.download(); // Triggers browser download
37
+ * ```
38
+ */
39
+ export declare function getMcpBundle(mcpWeb: MCPWeb, options?: McpBundleOptions): Promise<McpBundleResult>;
40
+ //# sourceMappingURL=get-mcp-bundle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-mcp-bundle.d.ts","sourceRoot":"","sources":["../src/get-mcp-bundle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAI5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,eAAe,CAAC,CA6D1B"}
@@ -0,0 +1,95 @@
1
+ import JSZip from 'jszip';
2
+ import { fetchClientBundle } from './fetch-client.js';
3
+ import { generateManifest } from './manifest.js';
4
+ /**
5
+ * Generates a pre-configured MCPB bundle for installation in Claude Desktop.
6
+ *
7
+ * This function creates a `.mcpb` file (which is a zip archive) containing:
8
+ * - manifest.json with pre-baked MCP_SERVER_URL and AUTH_TOKEN
9
+ * - server/index.js (the standalone @mcp-web/client bundle)
10
+ * - icon.png (optional, if provided in options)
11
+ *
12
+ * The resulting bundle can be installed in Claude Desktop with a single click,
13
+ * with no manual configuration required.
14
+ *
15
+ * @param mcpWeb - The MCPWeb instance to generate a bundle for
16
+ * @param options - Optional customization options
17
+ * @returns Promise resolving to the bundle result with blob, filename, and download helper
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * import { MCPWeb } from '@mcp-web/core';
22
+ * import { getMcpBundle } from '@mcp-web/mcpb';
23
+ *
24
+ * const mcp = new MCPWeb({
25
+ * name: 'My Todo App',
26
+ * description: 'AI-controllable todo application',
27
+ * autoConnect: true,
28
+ * });
29
+ *
30
+ * // Generate and download bundle
31
+ * const bundle = await getMcpBundle(mcp, {
32
+ * displayName: 'My Todo App - Claude Extension',
33
+ * version: '1.0.0',
34
+ * author: { name: 'Acme Corp', url: 'https://acme.com' }
35
+ * });
36
+ *
37
+ * bundle.download(); // Triggers browser download
38
+ * ```
39
+ */
40
+ export async function getMcpBundle(mcpWeb, options = {}) {
41
+ // Generate manifest with pre-baked auth token and bridge URL
42
+ const manifest = generateManifest(mcpWeb, options);
43
+ // Fetch the pre-built client bundle from CDN
44
+ const clientCode = await fetchClientBundle(options.clientBundleUrl);
45
+ // Create zip archive
46
+ const zip = new JSZip();
47
+ // Add manifest.json
48
+ zip.file('manifest.json', JSON.stringify(manifest, null, 2));
49
+ // Add server/index.js (the client bundle)
50
+ const serverFolder = zip.folder('server');
51
+ if (!serverFolder) {
52
+ throw new Error('Failed to create server folder in zip');
53
+ }
54
+ serverFolder.file('index.js', clientCode);
55
+ // Add icon if provided
56
+ // TODO: Consider adding validation for icon format (PNG) and size in future versions
57
+ if (options.icon) {
58
+ if (typeof options.icon === 'string') {
59
+ // Fetch icon from URL
60
+ try {
61
+ const iconResponse = await fetch(options.icon);
62
+ if (iconResponse.ok) {
63
+ const iconBlob = await iconResponse.blob();
64
+ zip.file('icon.png', iconBlob);
65
+ }
66
+ else {
67
+ console.warn(`Failed to fetch icon from ${options.icon}: ${iconResponse.status}`);
68
+ }
69
+ }
70
+ catch (error) {
71
+ console.warn(`Failed to fetch icon from ${options.icon}:`, error);
72
+ }
73
+ }
74
+ else {
75
+ // Blob provided directly
76
+ zip.file('icon.png', options.icon);
77
+ }
78
+ }
79
+ // Generate the .mcpb blob
80
+ const blob = await zip.generateAsync({ type: 'blob' });
81
+ const filename = `${manifest.name}.mcpb`;
82
+ // Create download helper
83
+ const download = () => {
84
+ const url = URL.createObjectURL(blob);
85
+ const a = document.createElement('a');
86
+ a.href = url;
87
+ a.download = filename;
88
+ document.body.appendChild(a);
89
+ a.click();
90
+ document.body.removeChild(a);
91
+ URL.revokeObjectURL(url);
92
+ };
93
+ return { blob, filename, download };
94
+ }
95
+ //# sourceMappingURL=get-mcp-bundle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-mcp-bundle.js","sourceRoot":"","sources":["../src/get-mcp-bundle.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,iBA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
+ * This package provides utilities for generating pre-configured MCPB bundles
5
+ * that can be installed in Claude Desktop with a single click.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { MCPWeb } from '@mcp-web/core';
10
+ * import { getMcpBundle } from '@mcp-web/mcpb';
11
+ *
12
+ * const mcp = new MCPWeb({
13
+ * name: 'My App',
14
+ * description: 'AI-controllable application',
15
+ * autoConnect: true,
16
+ * });
17
+ *
18
+ * // Generate bundle
19
+ * const bundle = await getMcpBundle(mcp, {
20
+ * displayName: 'My App - Claude Extension',
21
+ * version: '1.0.0',
22
+ * });
23
+ *
24
+ * // Download in browser
25
+ * bundle.download();
26
+ * ```
27
+ *
28
+ * @packageDocumentation
29
+ */
30
+ export { getMcpBundle } from './get-mcp-bundle.js';
31
+ export type { ManifestJson, McpBundleOptions, McpBundleResult, } from './types.js';
32
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,YAAY,EACV,YAAY,EACZ,gBAAgB,EAChB,eAAe,GAChB,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @mcp-web/mcpb - MCPB Bundle Generation for MCP-Web
3
+ *
4
+ * This package provides utilities for generating pre-configured MCPB bundles
5
+ * that can be installed in Claude Desktop with a single click.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { MCPWeb } from '@mcp-web/core';
10
+ * import { getMcpBundle } from '@mcp-web/mcpb';
11
+ *
12
+ * const mcp = new MCPWeb({
13
+ * name: 'My App',
14
+ * description: 'AI-controllable application',
15
+ * autoConnect: true,
16
+ * });
17
+ *
18
+ * // Generate bundle
19
+ * const bundle = await getMcpBundle(mcp, {
20
+ * displayName: 'My App - Claude Extension',
21
+ * version: '1.0.0',
22
+ * });
23
+ *
24
+ * // Download in browser
25
+ * bundle.download();
26
+ * ```
27
+ *
28
+ * @packageDocumentation
29
+ */
30
+ export { getMcpBundle } from './get-mcp-bundle.js';
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { MCPWeb } from '@mcp-web/core';
2
+ import type { ManifestJson, McpBundleOptions } from './types.js';
3
+ /**
4
+ * Generates a MCPB manifest.json from an MCPWeb instance and options.
5
+ *
6
+ * The manifest includes pre-baked environment variables (MCP_SERVER_URL and AUTH_TOKEN)
7
+ * so the user doesn't need to configure anything after installation.
8
+ *
9
+ * @param mcpWeb - The MCPWeb instance to generate manifest for
10
+ * @param options - Optional customization for the bundle
11
+ * @returns A complete manifest.json object conforming to MCPB spec v0.3
12
+ */
13
+ export declare function generateManifest(mcpWeb: MCPWeb, options?: McpBundleOptions): ManifestJson;
14
+ //# sourceMappingURL=manifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAajE;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,gBAAqB,GAC7B,YAAY,CAoCd"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Converts a string to kebab-case.
3
+ * Examples: "My App" -> "my-app", "MyApp" -> "my-app"
4
+ */
5
+ function toKebabCase(str) {
6
+ return str
7
+ .replace(/([a-z])([A-Z])/g, '$1-$2')
8
+ .replace(/[\s_]+/g, '-')
9
+ .toLowerCase();
10
+ }
11
+ /**
12
+ * Generates a MCPB manifest.json from an MCPWeb instance and options.
13
+ *
14
+ * The manifest includes pre-baked environment variables (MCP_SERVER_URL and AUTH_TOKEN)
15
+ * so the user doesn't need to configure anything after installation.
16
+ *
17
+ * @param mcpWeb - The MCPWeb instance to generate manifest for
18
+ * @param options - Optional customization for the bundle
19
+ * @returns A complete manifest.json object conforming to MCPB spec v0.3
20
+ */
21
+ export function generateManifest(mcpWeb, options = {}) {
22
+ const config = mcpWeb.config;
23
+ const mcpConfig = mcpWeb.mcpConfig;
24
+ const serverName = Object.keys(mcpConfig)[0];
25
+ const serverEnv = mcpConfig[serverName].env;
26
+ return {
27
+ manifest_version: '0.3',
28
+ name: toKebabCase(config.name),
29
+ display_name: options.displayName || config.name,
30
+ version: options.version || '1.0.0',
31
+ description: options.description || config.description,
32
+ author: options.author || { name: 'MCP-Web App' },
33
+ server: {
34
+ type: 'node',
35
+ entry_point: 'server/index.js',
36
+ mcp_config: {
37
+ command: 'node',
38
+ args: ['${__dirname}/server/index.js'],
39
+ env: {
40
+ // Pre-baked values - no user_config needed!
41
+ MCP_SERVER_URL: serverEnv.MCP_SERVER_URL,
42
+ AUTH_TOKEN: serverEnv.AUTH_TOKEN,
43
+ },
44
+ },
45
+ },
46
+ icon: options.icon && typeof options.icon === 'string' ? 'icon.png' : undefined,
47
+ tools_generated: true,
48
+ compatibility: {
49
+ platforms: ['darwin', 'win32', 'linux'],
50
+ runtimes: {
51
+ node: '>=22.0.0',
52
+ },
53
+ },
54
+ };
55
+ }
56
+ //# sourceMappingURL=manifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.js","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,SAAS,WAAW,CAAC,GAAW;IAC9B,OAAO,GAAG;SACP,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC;SACnC,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AAC;YACvC,QAAQ,EAAE;gBACR,IAAI,EAAE,UAAU;aACjB;SACF;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Options for generating an MCPB bundle.
3
+ */
4
+ export interface McpBundleOptions {
5
+ /**
6
+ * Display name shown in Claude Desktop's extension list.
7
+ * Defaults to the MCPWeb config name.
8
+ */
9
+ displayName?: string;
10
+ /**
11
+ * Bundle version (semantic version format).
12
+ * Defaults to "1.0.0".
13
+ */
14
+ version?: string;
15
+ /**
16
+ * Bundle description.
17
+ * Defaults to the MCPWeb config description.
18
+ */
19
+ description?: string;
20
+ /**
21
+ * Author information.
22
+ */
23
+ author?: {
24
+ name: string;
25
+ email?: string;
26
+ url?: string;
27
+ };
28
+ /**
29
+ * Icon for the extension. Can be:
30
+ * - A URL to fetch the icon from
31
+ * - A Blob containing the icon data
32
+ *
33
+ * Should be a PNG image. If provided, it will be included in the bundle as icon.png.
34
+ */
35
+ icon?: string | Blob;
36
+ /**
37
+ * Override the default CDN URL for fetching the @mcp-web/client bundle.
38
+ * By default, fetches from unpkg with jsdelivr fallback.
39
+ */
40
+ clientBundleUrl?: string;
41
+ }
42
+ /**
43
+ * Result of generating an MCPB bundle.
44
+ */
45
+ export interface McpBundleResult {
46
+ /**
47
+ * The .mcpb file as a Blob, ready to be downloaded or processed.
48
+ */
49
+ blob: Blob;
50
+ /**
51
+ * Suggested filename for the bundle (e.g., "my-app.mcpb").
52
+ */
53
+ filename: string;
54
+ /**
55
+ * Helper function to trigger browser download of the bundle.
56
+ * Creates a temporary download link and clicks it.
57
+ */
58
+ download: () => void;
59
+ }
60
+ /**
61
+ * MCPB manifest.json structure (v0.3).
62
+ */
63
+ export interface ManifestJson {
64
+ manifest_version: string;
65
+ name: string;
66
+ display_name?: string;
67
+ version: string;
68
+ description: string;
69
+ author: {
70
+ name: string;
71
+ email?: string;
72
+ url?: string;
73
+ };
74
+ server: {
75
+ type: 'node';
76
+ entry_point: string;
77
+ mcp_config: {
78
+ command: string;
79
+ args: string[];
80
+ env: Record<string, string>;
81
+ };
82
+ };
83
+ icon?: string;
84
+ tools_generated: boolean;
85
+ compatibility: {
86
+ platforms: string[];
87
+ runtimes: {
88
+ node: string;
89
+ };
90
+ };
91
+ }
92
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,MAAM,CAAC,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,CAAC;IAEF;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAErB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,IAAI,EAAE,IAAI,CAAC;IAEX;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,gBAAgB,EAAE,MAAM,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,CAAC;IACF,MAAM,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE;YACV,OAAO,EAAE,MAAM,CAAC;YAChB,IAAI,EAAE,MAAM,EAAE,CAAC;YACf,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;SAC7B,CAAC;KACH,CAAC;IACF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,OAAO,CAAC;IACzB,aAAa,EAAE;QACb,SAAS,EAAE,MAAM,EAAE,CAAC;QACpB,QAAQ,EAAE;YACR,IAAI,EAAE,MAAM,CAAC;SACd,CAAC;KACH,CAAC;CACH"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@mcp-web/mcpb",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "exports": {
7
+ ".": "./dist/index.js"
8
+ },
9
+ "dependencies": {
10
+ "jszip": "^3.10.1"
11
+ },
12
+ "peerDependencies": {
13
+ "@mcp-web/core": "0.1.0"
14
+ },
15
+ "devDependencies": {
16
+ "@types/node": "^25.0.9",
17
+ "typescript": "~5.9.3",
18
+ "@mcp-web/core": "0.1.0"
19
+ },
20
+ "scripts": {
21
+ "dev": "tsc --watch",
22
+ "build": "tsc",
23
+ "clean": "rm -rf dist"
24
+ }
25
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Default CDN URL for fetching the @mcp-web/client standalone bundle.
3
+ * Uses unpkg as the primary CDN.
4
+ */
5
+ const DEFAULT_CDN_URL =
6
+ 'https://unpkg.com/@mcp-web/client@latest/dist/standalone.js';
7
+
8
+ /**
9
+ * Fallback CDN URL using jsdelivr.
10
+ */
11
+ const FALLBACK_CDN_URL =
12
+ 'https://cdn.jsdelivr.net/npm/@mcp-web/client@latest/dist/standalone.js';
13
+
14
+ /**
15
+ * Fetches the pre-built @mcp-web/client standalone bundle from CDN.
16
+ *
17
+ * Tries the primary CDN (unpkg) first, then falls back to jsdelivr if that fails.
18
+ * If a custom URL is provided, only that URL is tried.
19
+ *
20
+ * @param customUrl - Optional custom URL to fetch the bundle from
21
+ * @returns The client bundle code as a string
22
+ * @throws Error if all CDN attempts fail
23
+ */
24
+ export async function fetchClientBundle(customUrl?: string): Promise<string> {
25
+ const urls = customUrl ? [customUrl] : [DEFAULT_CDN_URL, FALLBACK_CDN_URL];
26
+
27
+ for (const url of urls) {
28
+ try {
29
+ const response = await fetch(url);
30
+ if (response.ok) {
31
+ return await response.text();
32
+ }
33
+ } catch (error) {
34
+ // Try next URL
35
+ console.warn(`Failed to fetch client bundle from ${url}:`, error);
36
+ }
37
+ }
38
+
39
+ throw new Error(
40
+ 'Failed to fetch @mcp-web/client bundle from CDN. Please check your network connection or provide a custom clientBundleUrl.',
41
+ );
42
+ }
@@ -0,0 +1,107 @@
1
+ import type { MCPWeb } from '@mcp-web/core';
2
+ import JSZip from 'jszip';
3
+ import { fetchClientBundle } from './fetch-client.js';
4
+ import { generateManifest } from './manifest.js';
5
+ import type { McpBundleOptions, McpBundleResult } from './types.js';
6
+
7
+ /**
8
+ * Generates a pre-configured MCPB bundle for installation in Claude Desktop.
9
+ *
10
+ * This function creates a `.mcpb` file (which is a zip archive) containing:
11
+ * - manifest.json with pre-baked MCP_SERVER_URL and AUTH_TOKEN
12
+ * - server/index.js (the standalone @mcp-web/client bundle)
13
+ * - icon.png (optional, if provided in options)
14
+ *
15
+ * The resulting bundle can be installed in Claude Desktop with a single click,
16
+ * with no manual configuration required.
17
+ *
18
+ * @param mcpWeb - The MCPWeb instance to generate a bundle for
19
+ * @param options - Optional customization options
20
+ * @returns Promise resolving to the bundle result with blob, filename, and download helper
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * import { MCPWeb } from '@mcp-web/core';
25
+ * import { getMcpBundle } from '@mcp-web/mcpb';
26
+ *
27
+ * const mcp = new MCPWeb({
28
+ * name: 'My Todo App',
29
+ * description: 'AI-controllable todo application',
30
+ * autoConnect: true,
31
+ * });
32
+ *
33
+ * // Generate and download bundle
34
+ * const bundle = await getMcpBundle(mcp, {
35
+ * displayName: 'My Todo App - Claude Extension',
36
+ * version: '1.0.0',
37
+ * author: { name: 'Acme Corp', url: 'https://acme.com' }
38
+ * });
39
+ *
40
+ * bundle.download(); // Triggers browser download
41
+ * ```
42
+ */
43
+ export async function getMcpBundle(
44
+ mcpWeb: MCPWeb,
45
+ options: McpBundleOptions = {},
46
+ ): Promise<McpBundleResult> {
47
+ // Generate manifest with pre-baked auth token and bridge URL
48
+ const manifest = generateManifest(mcpWeb, options);
49
+
50
+ // Fetch the pre-built client bundle from CDN
51
+ const clientCode = await fetchClientBundle(options.clientBundleUrl);
52
+
53
+ // Create zip archive
54
+ const zip = new JSZip();
55
+
56
+ // Add manifest.json
57
+ zip.file('manifest.json', JSON.stringify(manifest, null, 2));
58
+
59
+ // Add server/index.js (the client bundle)
60
+ const serverFolder = zip.folder('server');
61
+ if (!serverFolder) {
62
+ throw new Error('Failed to create server folder in zip');
63
+ }
64
+ serverFolder.file('index.js', clientCode);
65
+
66
+ // Add icon if provided
67
+ // TODO: Consider adding validation for icon format (PNG) and size in future versions
68
+ if (options.icon) {
69
+ if (typeof options.icon === 'string') {
70
+ // Fetch icon from URL
71
+ try {
72
+ const iconResponse = await fetch(options.icon);
73
+ if (iconResponse.ok) {
74
+ const iconBlob = await iconResponse.blob();
75
+ zip.file('icon.png', iconBlob);
76
+ } else {
77
+ console.warn(
78
+ `Failed to fetch icon from ${options.icon}: ${iconResponse.status}`,
79
+ );
80
+ }
81
+ } catch (error) {
82
+ console.warn(`Failed to fetch icon from ${options.icon}:`, error);
83
+ }
84
+ } else {
85
+ // Blob provided directly
86
+ zip.file('icon.png', options.icon);
87
+ }
88
+ }
89
+
90
+ // Generate the .mcpb blob
91
+ const blob = await zip.generateAsync({ type: 'blob' });
92
+ const filename = `${manifest.name}.mcpb`;
93
+
94
+ // Create download helper
95
+ const download = () => {
96
+ const url = URL.createObjectURL(blob);
97
+ const a = document.createElement('a');
98
+ a.href = url;
99
+ a.download = filename;
100
+ document.body.appendChild(a);
101
+ a.click();
102
+ document.body.removeChild(a);
103
+ URL.revokeObjectURL(url);
104
+ };
105
+
106
+ return { blob, filename, download };
107
+ }
package/src/index.ts ADDED
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @mcp-web/mcpb - MCPB Bundle Generation for MCP-Web
3
+ *
4
+ * This package provides utilities for generating pre-configured MCPB bundles
5
+ * that can be installed in Claude Desktop with a single click.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { MCPWeb } from '@mcp-web/core';
10
+ * import { getMcpBundle } from '@mcp-web/mcpb';
11
+ *
12
+ * const mcp = new MCPWeb({
13
+ * name: 'My App',
14
+ * description: 'AI-controllable application',
15
+ * autoConnect: true,
16
+ * });
17
+ *
18
+ * // Generate bundle
19
+ * const bundle = await getMcpBundle(mcp, {
20
+ * displayName: 'My App - Claude Extension',
21
+ * version: '1.0.0',
22
+ * });
23
+ *
24
+ * // Download in browser
25
+ * bundle.download();
26
+ * ```
27
+ *
28
+ * @packageDocumentation
29
+ */
30
+
31
+ export { getMcpBundle } from './get-mcp-bundle.js';
32
+ export type {
33
+ ManifestJson,
34
+ McpBundleOptions,
35
+ McpBundleResult,
36
+ } from './types.js';
@@ -0,0 +1,64 @@
1
+ import type { MCPWeb } from '@mcp-web/core';
2
+ import type { ManifestJson, McpBundleOptions } from './types.js';
3
+
4
+ /**
5
+ * Converts a string to kebab-case.
6
+ * Examples: "My App" -> "my-app", "MyApp" -> "my-app"
7
+ */
8
+ function toKebabCase(str: string): string {
9
+ return str
10
+ .replace(/([a-z])([A-Z])/g, '$1-$2')
11
+ .replace(/[\s_]+/g, '-')
12
+ .toLowerCase();
13
+ }
14
+
15
+ /**
16
+ * Generates a MCPB manifest.json from an MCPWeb instance and options.
17
+ *
18
+ * The manifest includes pre-baked environment variables (MCP_SERVER_URL and AUTH_TOKEN)
19
+ * so the user doesn't need to configure anything after installation.
20
+ *
21
+ * @param mcpWeb - The MCPWeb instance to generate manifest for
22
+ * @param options - Optional customization for the bundle
23
+ * @returns A complete manifest.json object conforming to MCPB spec v0.3
24
+ */
25
+ export function generateManifest(
26
+ mcpWeb: MCPWeb,
27
+ options: McpBundleOptions = {},
28
+ ): ManifestJson {
29
+ const config = mcpWeb.config;
30
+ const mcpConfig = mcpWeb.mcpConfig;
31
+ const serverName = Object.keys(mcpConfig)[0];
32
+ const serverEnv = mcpConfig[serverName].env;
33
+
34
+ return {
35
+ manifest_version: '0.3',
36
+ name: toKebabCase(config.name),
37
+ display_name: options.displayName || config.name,
38
+ version: options.version || '1.0.0',
39
+ description: options.description || config.description,
40
+ author: options.author || { name: 'MCP-Web App' },
41
+ server: {
42
+ type: 'node',
43
+ entry_point: 'server/index.js',
44
+ mcp_config: {
45
+ command: 'node',
46
+ args: ['${__dirname}/server/index.js'],
47
+ env: {
48
+ // Pre-baked values - no user_config needed!
49
+ MCP_SERVER_URL: serverEnv.MCP_SERVER_URL,
50
+ AUTH_TOKEN: serverEnv.AUTH_TOKEN,
51
+ },
52
+ },
53
+ },
54
+ icon:
55
+ options.icon && typeof options.icon === 'string' ? 'icon.png' : undefined,
56
+ tools_generated: true,
57
+ compatibility: {
58
+ platforms: ['darwin', 'win32', 'linux'],
59
+ runtimes: {
60
+ node: '>=22.0.0',
61
+ },
62
+ },
63
+ };
64
+ }
package/src/types.ts ADDED
@@ -0,0 +1,102 @@
1
+ import type { MCPWeb } from '@mcp-web/core';
2
+
3
+ /**
4
+ * Options for generating an MCPB bundle.
5
+ */
6
+ export interface McpBundleOptions {
7
+ /**
8
+ * Display name shown in Claude Desktop's extension list.
9
+ * Defaults to the MCPWeb config name.
10
+ */
11
+ displayName?: string;
12
+
13
+ /**
14
+ * Bundle version (semantic version format).
15
+ * Defaults to "1.0.0".
16
+ */
17
+ version?: string;
18
+
19
+ /**
20
+ * Bundle description.
21
+ * Defaults to the MCPWeb config description.
22
+ */
23
+ description?: string;
24
+
25
+ /**
26
+ * Author information.
27
+ */
28
+ author?: {
29
+ name: string;
30
+ email?: string;
31
+ url?: string;
32
+ };
33
+
34
+ /**
35
+ * Icon for the extension. Can be:
36
+ * - A URL to fetch the icon from
37
+ * - A Blob containing the icon data
38
+ *
39
+ * Should be a PNG image. If provided, it will be included in the bundle as icon.png.
40
+ */
41
+ icon?: string | Blob;
42
+
43
+ /**
44
+ * Override the default CDN URL for fetching the @mcp-web/client bundle.
45
+ * By default, fetches from unpkg with jsdelivr fallback.
46
+ */
47
+ clientBundleUrl?: string;
48
+ }
49
+
50
+ /**
51
+ * Result of generating an MCPB bundle.
52
+ */
53
+ export interface McpBundleResult {
54
+ /**
55
+ * The .mcpb file as a Blob, ready to be downloaded or processed.
56
+ */
57
+ blob: Blob;
58
+
59
+ /**
60
+ * Suggested filename for the bundle (e.g., "my-app.mcpb").
61
+ */
62
+ filename: string;
63
+
64
+ /**
65
+ * Helper function to trigger browser download of the bundle.
66
+ * Creates a temporary download link and clicks it.
67
+ */
68
+ download: () => void;
69
+ }
70
+
71
+ /**
72
+ * MCPB manifest.json structure (v0.3).
73
+ */
74
+ export interface ManifestJson {
75
+ manifest_version: string;
76
+ name: string;
77
+ display_name?: string;
78
+ version: string;
79
+ description: string;
80
+ author: {
81
+ name: string;
82
+ email?: string;
83
+ url?: string;
84
+ };
85
+ server: {
86
+ type: 'node';
87
+ entry_point: string;
88
+ mcp_config: {
89
+ command: string;
90
+ args: string[];
91
+ env: Record<string, string>;
92
+ };
93
+ };
94
+ icon?: string;
95
+ tools_generated: boolean;
96
+ compatibility: {
97
+ platforms: string[];
98
+ runtimes: {
99
+ node: string;
100
+ };
101
+ };
102
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "node16",
5
+ "moduleResolution": "node16",
6
+ "lib": ["ES2022", "DOM"],
7
+ "outDir": "dist",
8
+ "rootDir": "src"
9
+ },
10
+ "include": ["src/**/*"],
11
+ "exclude": ["node_modules", "dist", "**/*.test.ts"]
12
+ }