Sponsored by Deepsite.site

SvelteKit & Vercel MCP Starter

Created By
axel-rock7 months ago
Content

SvelteKit & Vercel MCP Starter

Welcome to this example project demonstrating how to set up and deploy a Model Context Protocol (MCP) server and client using SvelteKit, running on Vercel.

This starter aims to provide a clear, minimal foundation for SvelteKit enthusiasts looking to integrate powerful AI tool-calling capabilities into their applications.

✨ Why This Project?

This project was born out of a personal interest in exploring MCP integration with SvelteKit. The recent release of the @vercel/mcp-adapter by Vercel significantly lowered the barrier to entry, making this exploration much more approachable – a big thanks to the Vercel team for this!

One of the exciting aspects of this implementation is demonstrating that MCP can be successfully integrated with SvelteKit, even though much of the initial documentation and examples leaned towards Next.js. The adaptation for SvelteKit is quite minimal, showcasing the flexibility of the underlying technologies.

While this example utilizes Vercel's adapter and deployment platform for convenience, it's important to note that the core concepts rely on standard web technologies (HTTP, Server-Sent Events). This means that with some adjustments, similar setups should be achievable on other hosting platforms that support Node.js environments.

This starter aims to be a non-intimidating, minimal example to get you started.

🌟 Features

  • SvelteKit: The fast, modern, and enjoyable full-stack framework.
  • Vercel Deployment: Optimized for Vercel's infrastructure, including support for serverless functions.
  • @vercel/mcp-adapter: Leveraging Vercel's package for simplified MCP server creation.
  • MCP Server Example: Demonstrates a basic MCP tool within a SvelteKit route.
  • MCP Client Example: Shows how to call an MCP server from a SvelteKit frontend (initially in +page.svelte, to be minimized).
  • TypeScript: For robust and maintainable code.

🛠️ Getting Started

Follow these steps to get the project up and running on your local machine.

Prerequisites

  1. Node.js and pnpm: Ensure you have Node.js (v18 or later recommended) and pnpm installed.
  2. Vercel Account: For deployment (optional for local development, especially if you adapt it for other platforms).
  3. API Keys:
    • You'll need an Anthropic API key (or an alternative LLM provider key if you adapt the client).
    • A Redis URL is required by the @vercel/mcp-adapter for certain transports (like SSE) that manage state. Services like Upstash offer free tiers.
    • Copy the .env.example file to .env and fill in your keys:
      cp .env.example .env
      

Installation

Clone the repository and install the dependencies:

git clone <your-repo-url> sveltekit-mcp-starter
cd sveltekit-mcp-starter
pnpm install

Running Locally

Start the development server:

pnpm run dev

Your application should now be running on http://localhost:5173 (or the next available port).

🧠 Understanding MCP

Model Context Protocol (MCP) is designed to enable AI models to interact with external tools and services. Think of it not just as another API, but as a tailored toolkit that an AI can use to perform specific tasks. A single MCP tool might internally use multiple APIs or complex business logic.

Vercel has introduced support for deploying MCP servers, utilizing the @vercel/mcp-adapter package. This adapter supports both the older stateful SSE (Server-Sent Events) transport and the newer stateless HTTP transport.

From Vercel's Changelog: "Rather than thinking about MCP like a REST API, you can instead think about it like a tailored toolkit that helps an AI achieve a particular task. There may be multiple APIs and other business logic used behind the scenes for a single MCP tool."

📝 Key Considerations & Caveats

  • Edge Functions: As of the initial creation of this example, deploying the MCP server to Vercel Edge Functions might have limitations with the current adapter or SvelteKit integration nuances. Standard serverless functions are the recommended path on Vercel for now.
  • Transport Protocol: This example primarily demonstrates the StreamableHTTPClientTransport. The @vercel/mcp-adapter also supports SSE. If you explore SSE, ensure your Redis setup is correctly configured as it's used for state management by the adapter.
  • MCP SDK Version: The MCP TypeScript SDK is an evolving library. This example uses "@modelcontextprotocol/sdk": "1.10.2" due to a previous issue with tool arguments in later versions (see Issue #467). Always check for the latest stable versions and adapt as needed.

🚀 Deploying to Vercel

Deploying this SvelteKit application to Vercel is straightforward:

  1. Connect your Git repository to Vercel.
  2. Configure your environment variables (like ANTHROPIC_API_KEY and REDIS_URL) in the Vercel project settings.
  3. Vercel will automatically detect it's a SvelteKit project and build and deploy it.

Ensure your vercel.json is configured appropriately if you have specific needs for function regions or memory.

🤝 Contributing and Future

This project is intended as a minimal starting point. There are several ways it could be improved or expanded:

  • Flexible Routing for Transports: Implementing more dynamic routing to easily switch between or support multiple MCP transports (e.g., SSE alongside HTTP) within the SvelteKit structure.
  • Expanded Tool Examples: Adding more diverse and complex tool examples.
  • Error Handling and Robustness: Enhancing error handling on both client and server sides.

Maintenance Status: This repository was created to share a working example. While I'll do my best to address critical issues if they arise, I may not be actively maintaining or developing it long-term.

Contributions are highly welcome! If you have improvements, bug fixes, or new features, please feel free to open an issue or submit a pull request.

📚 Further Reading

🧹 Minimal Example Focus

The src/routes/+page.svelte file initially contains a client-side example of interacting with the MCP server. This will eventually be streamlined or moved to a more dedicated example section to keep the core project structure as close as possible to a default SvelteKit setup, focusing primarily on the MCP server integration within SvelteKit routes.


Happy coding, and we hope this starter helps you build amazing AI-powered SvelteKit applications!

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Tavily Mcp
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
DeepChatYour AI Partner on Desktop
Playwright McpPlaywright MCP server
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
ChatWiseThe second fastest AI chatbot™
Serper MCP ServerA Serper MCP Server
WindsurfThe new purpose-built IDE to harness magic
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Amap Maps高德地图官方 MCP Server
CursorThe AI Code Editor
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.