@netpad/mcp-server 2.3.1 → 2.4.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.
- package/dist/index.js +139 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -22053,7 +22053,7 @@ See the full source code in \`packages/demo-node/src/index.ts\` for complete imp
|
|
|
22053
22053
|
);
|
|
22054
22054
|
server.tool(
|
|
22055
22055
|
"generate_form",
|
|
22056
|
-
"Generate a complete NetPad form configuration from a description.
|
|
22056
|
+
"Generate a complete NetPad form configuration from a description. IMPORTANT: The output includes a direct import link that users should click to import the form into NetPad - always present this link prominently to users. Also returns TypeScript code for programmatic use.",
|
|
22057
22057
|
{
|
|
22058
22058
|
description: external_exports.string().describe("Natural language description of the form to generate"),
|
|
22059
22059
|
formName: external_exports.string().describe("Name of the form"),
|
|
@@ -22167,21 +22167,158 @@ async function main() {
|
|
|
22167
22167
|
functionsCode,
|
|
22168
22168
|
mainCode
|
|
22169
22169
|
});
|
|
22170
|
+
const importConfig = {
|
|
22171
|
+
name: schema.name,
|
|
22172
|
+
description: schema.description,
|
|
22173
|
+
fieldConfigs: schema.fieldConfigs,
|
|
22174
|
+
multiPage: schema.multiPage,
|
|
22175
|
+
theme: schema.theme
|
|
22176
|
+
};
|
|
22177
|
+
const base64Config = Buffer.from(JSON.stringify(importConfig)).toString("base64");
|
|
22178
|
+
const baseUrl = process.env.NETPAD_URL || "https://netpad.io";
|
|
22179
|
+
const importUrl = `${baseUrl}/api/forms/import?config=${base64Config}&source=claude-mcp`;
|
|
22170
22180
|
const output = createToolOutput({
|
|
22171
22181
|
code,
|
|
22172
22182
|
filename: `${slug}.ts`,
|
|
22173
22183
|
envVars: STANDARD_ENV_VARS
|
|
22174
22184
|
});
|
|
22185
|
+
const outputWithImport = `# ${schema.name}
|
|
22186
|
+
|
|
22187
|
+
${schema.description || ""}
|
|
22188
|
+
|
|
22189
|
+
## \u{1F680} Import to NetPad (Recommended)
|
|
22190
|
+
|
|
22191
|
+
Click this link to import the form directly into your NetPad account:
|
|
22192
|
+
|
|
22193
|
+
**[\u27A1\uFE0F Import "${schema.name}" to NetPad](${importUrl})**
|
|
22194
|
+
|
|
22195
|
+
This will open NetPad where you can:
|
|
22196
|
+
1. Select a project to import into
|
|
22197
|
+
2. Preview and customize the form
|
|
22198
|
+
3. Save and deploy
|
|
22199
|
+
|
|
22200
|
+
---
|
|
22201
|
+
|
|
22202
|
+
## Alternative: TypeScript Code
|
|
22203
|
+
|
|
22204
|
+
If you prefer to work with code, here's the complete TypeScript implementation:
|
|
22205
|
+
|
|
22206
|
+
${formatToolOutput(output)}`;
|
|
22175
22207
|
return {
|
|
22176
22208
|
content: [
|
|
22177
22209
|
{
|
|
22178
22210
|
type: "text",
|
|
22179
|
-
text:
|
|
22211
|
+
text: outputWithImport
|
|
22180
22212
|
}
|
|
22181
22213
|
]
|
|
22182
22214
|
};
|
|
22183
22215
|
}
|
|
22184
22216
|
);
|
|
22217
|
+
server.tool(
|
|
22218
|
+
"create_import_link",
|
|
22219
|
+
"Create a shareable import link for a NetPad form configuration. Use this to generate a short, reliable import URL that users can click to import the form directly into their NetPad account. Recommended for complex forms or when the base64 URL would be too long.",
|
|
22220
|
+
{
|
|
22221
|
+
config: external_exports.object({
|
|
22222
|
+
name: external_exports.string().describe("Form name"),
|
|
22223
|
+
description: external_exports.string().optional().describe("Form description"),
|
|
22224
|
+
fieldConfigs: external_exports.array(external_exports.object({
|
|
22225
|
+
path: external_exports.string(),
|
|
22226
|
+
label: external_exports.string(),
|
|
22227
|
+
type: external_exports.string(),
|
|
22228
|
+
included: external_exports.boolean(),
|
|
22229
|
+
required: external_exports.boolean().optional(),
|
|
22230
|
+
placeholder: external_exports.string().optional(),
|
|
22231
|
+
options: external_exports.array(external_exports.any()).optional(),
|
|
22232
|
+
validation: external_exports.any().optional(),
|
|
22233
|
+
conditionalLogic: external_exports.any().optional()
|
|
22234
|
+
})).describe("Array of field configurations"),
|
|
22235
|
+
multiPage: external_exports.any().optional().describe("Multi-page configuration"),
|
|
22236
|
+
theme: external_exports.any().optional().describe("Theme configuration")
|
|
22237
|
+
}).describe("Form configuration object"),
|
|
22238
|
+
projectId: external_exports.string().optional().describe("Target project ID (user will pick if not specified)"),
|
|
22239
|
+
expiresIn: external_exports.number().optional().describe("Expiry time in seconds (default: 24 hours, max: 7 days)")
|
|
22240
|
+
},
|
|
22241
|
+
async ({ config: config2, projectId, expiresIn }) => {
|
|
22242
|
+
const baseUrl = process.env.NETPAD_URL || "https://netpad.io";
|
|
22243
|
+
try {
|
|
22244
|
+
const response = await fetch(`${baseUrl}/api/forms/import`, {
|
|
22245
|
+
method: "POST",
|
|
22246
|
+
headers: {
|
|
22247
|
+
"Content-Type": "application/json"
|
|
22248
|
+
},
|
|
22249
|
+
body: JSON.stringify({
|
|
22250
|
+
config: config2,
|
|
22251
|
+
projectId,
|
|
22252
|
+
source: "claude-mcp",
|
|
22253
|
+
expiresIn: expiresIn || 86400,
|
|
22254
|
+
// Default 24 hours
|
|
22255
|
+
mcpVersion: "2.3.0"
|
|
22256
|
+
})
|
|
22257
|
+
});
|
|
22258
|
+
if (!response.ok) {
|
|
22259
|
+
const error48 = await response.json().catch(() => ({}));
|
|
22260
|
+
return {
|
|
22261
|
+
content: [
|
|
22262
|
+
{
|
|
22263
|
+
type: "text",
|
|
22264
|
+
text: `\u274C Failed to create import link: ${error48.error || response.statusText}
|
|
22265
|
+
|
|
22266
|
+
Fallback: Use the generate_form tool with outputFormat: "json" and manually import the config.`
|
|
22267
|
+
}
|
|
22268
|
+
]
|
|
22269
|
+
};
|
|
22270
|
+
}
|
|
22271
|
+
const result = await response.json();
|
|
22272
|
+
return {
|
|
22273
|
+
content: [
|
|
22274
|
+
{
|
|
22275
|
+
type: "text",
|
|
22276
|
+
text: `\u2705 **Import Link Created!**
|
|
22277
|
+
|
|
22278
|
+
**Form:** ${config2.name}
|
|
22279
|
+
**Fields:** ${config2.fieldConfigs.length}
|
|
22280
|
+
**Expires:** ${new Date(result.expiresAt).toLocaleString()}
|
|
22281
|
+
|
|
22282
|
+
---
|
|
22283
|
+
|
|
22284
|
+
## Click to Import
|
|
22285
|
+
|
|
22286
|
+
[**\u2192 Import "${config2.name}" to NetPad**](${result.importUrl})
|
|
22287
|
+
|
|
22288
|
+
---
|
|
22289
|
+
|
|
22290
|
+
**Import ID:** \`${result.importId}\`
|
|
22291
|
+
**Direct URL:** ${result.importUrl}
|
|
22292
|
+
|
|
22293
|
+
The user will be prompted to log in (if needed) and select a project before importing.`
|
|
22294
|
+
}
|
|
22295
|
+
]
|
|
22296
|
+
};
|
|
22297
|
+
} catch (error48) {
|
|
22298
|
+
const base64Config = Buffer.from(JSON.stringify(config2)).toString("base64");
|
|
22299
|
+
const fallbackUrl = `${baseUrl}/api/forms/import?config=${base64Config}&source=claude-mcp`;
|
|
22300
|
+
return {
|
|
22301
|
+
content: [
|
|
22302
|
+
{
|
|
22303
|
+
type: "text",
|
|
22304
|
+
text: `\u26A0\uFE0F Could not create short import link (API unavailable). Using fallback URL.
|
|
22305
|
+
|
|
22306
|
+
**Form:** ${config2.name}
|
|
22307
|
+
**Fields:** ${config2.fieldConfigs.length}
|
|
22308
|
+
|
|
22309
|
+
---
|
|
22310
|
+
|
|
22311
|
+
## Fallback Import Link
|
|
22312
|
+
|
|
22313
|
+
[**\u2192 Import "${config2.name}" to NetPad**](${fallbackUrl})
|
|
22314
|
+
|
|
22315
|
+
Note: This URL may be long. If it doesn't work, ask the user to use the NetPad form builder directly.`
|
|
22316
|
+
}
|
|
22317
|
+
]
|
|
22318
|
+
};
|
|
22319
|
+
}
|
|
22320
|
+
}
|
|
22321
|
+
);
|
|
22185
22322
|
server.tool(
|
|
22186
22323
|
"generate_field",
|
|
22187
22324
|
"Generate a single field configuration for a NetPad form. Use this when you need to add a specific field to an existing form.",
|