integration · SvelteKit

SvelteKit MCP integration.

Your SvelteKit 2 app already has +server.ts routes and form actions handling JSON traffic; here's how to expose them as MCP tools an agent can call, without writing a parallel API layer.

wmcp.sh is not affiliated with the Svelte project or Anthropic. SvelteKit and +server.ts are Svelte project features.

Your +server.ts routes already answer JSON. They just don't ship a schema.

What you have today

Route files at src/routes/**/+server.ts exporting GET / POST / PATCH handlers, plus form actions at +page.server.ts. Running under adapter-node, adapter-cloudflare, adapter-vercel, or adapter-netlify.

What agents need

A Model Context Protocol server with typed tool schemas. wmcp.sh reads an OpenAPI 3 document describing your routes and emits the MCP server at https://wmcp.sh/mcp/<your-id>.

A +server.ts route, exposed as a tool.

Plain SvelteKit 2; the OpenAPI bit is what wmcp.sh ingests.

// src/routes/api/inventory/+server.ts — SvelteKit 2
import { json, error } from '@sveltejs/kit';
import { z } from 'zod';
import type { RequestHandler } from './$types';

const Body = z.object({
  sku: z.string().min(1),
  warehouse: z.string().optional(),
});

export const POST: RequestHandler = async ({ request }) => {
  const parsed = Body.safeParse(await request.json());
  if (!parsed.success) throw error(400, 'invalid body');
  const { sku, warehouse } = parsed.data;
  const row = await lookupInventory(sku, warehouse);
  return json({ sku, warehouse: warehouse ?? 'default', on_hand: row.qty });
};

// Publish OpenAPI at /openapi.json (hand-written or generated from Zod).
// Register: curl 'https://wmcp.sh/api/v1/tools?url=https://acme.example.com/openapi.json'

Hand-rolled MCP server vs wmcp.sh on SvelteKit.

CapabilityHand-rolledwmcp.sh + SvelteKit OpenAPI
Tool schemas in sync with routes ⚠️ Manual; drifts on every refactor ✅ Spec is source of truth; one re-ingest on deploy
Form actions exposed ⚠️ Possible via FormData → JSON wrapper ✅ Same wrapper; spec it once, agents see it
SSE / Streamable HTTP transport ⚠️ You build it on top of +server.ts ✅ MCP transport served at https://wmcp.sh/mcp/<your-id>
Multi-adapter portability ⚠️ Tied to one runtime ✅ wmcp.sh proxies any HTTPS origin
CSRF handling ⚠️ You configure handle hooks per route ✅ Configurable per-spec; or wmcp.sh forwards a matching Origin
Per-tool auth ⚠️ Custom middleware ✅ Bearer / API-key / OAuth 2.1 declared in securitySchemes

Common questions from SvelteKit teams.

Do form actions become MCP tools?
Form actions accept FormData, not JSON. Wrap each action in a sibling +server.ts JSON handler that calls the same underlying function. The action keeps serving your UI; the +server.ts version serves agents.
Which adapter should I use?
Any. wmcp.sh proxies to whatever URL your OpenAPI spec advertises. adapter-node, adapter-cloudflare, adapter-vercel, and adapter-netlify all work identically.
How do I generate the OpenAPI spec?
SvelteKit has no built-in generator. Hand-write a small spec at src/routes/openapi.json/+server.ts, convert your Zod schemas with @asteasolutions/zod-to-openapi, or factor handlers into a Hono sub-app and use its generator.
Does SvelteKit's CSRF protection block agent traffic?
It can. SvelteKit blocks cross-origin POSTs with non-form content types by default. Either disable for specific paths in your handle hook, route agent traffic through a path that's exempt, or have wmcp.sh forward a matching Origin header. Always keep production auth on the endpoint.
Can I use load functions as MCP read-only tools?
No — load functions return data to pages, not standalone responses. Mirror the load logic in a +server.ts GET handler and let the page import the same underlying function.
Versions supported?
Example targets SvelteKit 2. SvelteKit 1.x with the same +server.ts RequestHandler shape works identically.
Need this done for you?

Skip the wiring — we ship the OpenAPI + MCP for your SvelteKit app.

Audit your +server.ts routes, emit a typed spec, deploy MCP at mcp.yourbrand.com. Starter $499 one-time setup; Managed Retainer $999/mo for ongoing maintenance; Enterprise $4,999+/mo for SLA + private deploy.

See /managed → Submit (free)