GeneratorsFree
MCP Boilerplate Generator
Pick a language and framework to get working starter code that serves your manifest and tool endpoints, plus the in-page registration snippet.
Input
Install
npm install express
npm install -D typescript tsx @types/express @types/node
npx tsx server.tsStarter code
// Generated by Techorizone. WebMCP starter server (Express).
import express, { type Request, type Response } from "express";
interface ToolDef {
description: string;
inputSchema: Record<string, unknown>;
handler: (args: Record<string, unknown>) => Promise<unknown>;
}
// 1. Your tools. Keep this list in sync with your manifest.
const tools: Record<string, ToolDef> = {
get_weather: {
description: "Get the current weather for a city. Returns temperature and conditions.",
inputSchema: {
type: "object",
properties: { city: { type: "string", description: "City name, like Lahore" } },
required: ["city"],
},
handler: async (args) => {
// Replace with your real logic.
return { city: args.city, temperatureC: 21, conditions: "Sunny" };
},
},
};
function buildManifest() {
return {
name: "My Site",
description: "Tools for AI agents.",
version: "1.0.0",
tools: Object.entries(tools).map(([name, t]) => ({
name,
description: t.description,
endpoint: `/api/mcp/${name}`,
method: "POST",
inputSchema: t.inputSchema,
})),
};
}
const app = express();
app.use(express.json());
// 2. Manifest (WebMCP Manifest v1, platform convention).
app.get("/.well-known/mcp.json", (_req: Request, res: Response) => {
res.set("Access-Control-Allow-Origin", "*");
res.json(buildManifest());
});
// 3. Tool endpoints.
app.post("/api/mcp/:tool", async (req: Request, res: Response) => {
const name = String(req.params.tool);
const tool = Object.hasOwn(tools, name) ? tools[name] : undefined;
if (!tool) {
res.status(404).json({ error: "Unknown tool" });
return;
}
try {
res.json(await tool.handler(req.body ?? {}));
} catch {
res.status(500).json({ error: "Tool failed" });
}
});
const port = Number(process.env.PORT ?? 8080);
app.listen(port, () => console.log(`WebMCP server on http://localhost:${port}`));
Browser registration (optional)
// Generated by Techorizone.
// Registers your tools with the WebMCP in-page API (W3C draft).
// Browsers without the API simply skip this script.
(() => {
const mc =
(typeof document !== "undefined" && document.modelContext) ||
(typeof navigator !== "undefined" && navigator.modelContext);
if (!mc || typeof mc.registerTool !== "function") return;
const tools = [
{
"name": "get_weather",
"description": "Get the current weather for a city. Returns temperature and conditions.",
"endpoint": "/api/mcp/get_weather",
"inputSchema": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "City name, like Lahore"
}
},
"required": [
"city"
]
}
}
];
for (const tool of tools) {
try {
Promise.resolve(
mc.registerTool({
name: tool.name,
description: tool.description,
inputSchema: tool.inputSchema,
async execute(args) {
const res = await fetch(tool.endpoint, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(args ?? {}),
});
const text = await res.text();
return { content: [{ type: "text", text }], isError: !res.ok };
},
}),
).catch((err) => console.warn("WebMCP: could not register " + tool.name, err));
} catch (err) {
console.warn("WebMCP: could not register " + tool.name, err);
}
}
})();Add this script to your pages. Tools with an empty name are skipped. Add an inputSchema to each tool for best results (see the MCP Schema Generator).
This code does not need any WebMCP SDK. It serves your manifest at /.well-known/mcp.json and each tool at POST /api/mcp/<tool>, which matches our Proxy Configurator and SDK Generator.
Related Generators tools
About MCP Boilerplate Generator
Pick a language and framework to get working starter code that serves your manifest and tool endpoints, plus the in-page registration snippet.
How to use
- Fill in the form.
- Watch the preview update as you type.
- Copy the output or download the file.
Good to know
This tool runs in your browser. What you enter is not sent to our server.