Edit on val.town ↗

How to build an MCP server

This guide walks you through creating an MCP server in 1 minute on a Free account. Feel free to jump to Step 1 (i.e. “I already trust Val Town and know what an MCP server is, just show me how to do it”).


Looking for the Val Town MCP server? Here you go.

We have it on good authority that Val Town is a great—maybe the best—place to build an MCP server: the MCP Core Maintainer team themselves use Val Town to create and test MCP servers. Here are a couple quotes from Paul Carleton, Technical Staff at Anthropic and MCP Core Maintainer:

“The way I build MCP servers most of the time is in Val Town. It’s great. A GET request returns some JSON that renders here [on the frontend], and I can also just query the MCP server directly to see what that example server does.”

“With Val Town I can just get an HTTPS URL that has an MCP, and I can tweak that really quickly, and then I can put that MCP into claude.ai and have our real production backend hit it and test a whole bunch of stuff, which is really nice.”

Paul said lots of other nice stuff and shared neat things about the new MCP 2.0 (the 2026-07-28 specification). Read the full case study if you’re interested.

All that said, there are reasonable alternatives that we list below where you can host your MCP server, like Cloudflare.

The Model Context Protocol, MCP, is a standard way for LLMs and agents to connect to data sources and tools.

An MCP client is whatever LLM/agent you already use—Claude, ChatGPT, etc. The client connects to an MCP server, which provides the data and/or tools. For example, we have a Val Town MCP server that lets your agent do pretty much everything you can do by hand on Val Town (edit and run code, schedule crons, read and write to SQLite and blob storage, etc.).

MCP servers can either use STDIO as the transport layer for passing data, or streamable HTTP. We’ll be creating an HTTP server, which is what most remote MCP servers use (i.e. not on your local computer).

Many software companies with APIs now also ship MCP servers: GitHub, Slack, Notion, Sentry, Vercel, Cloudflare, Resend, Figma, Linear, and many more. MCP is becoming a more and more popular pattern as people increasingly ask AI agents to answer questions and complete tasks on their behalf.

It’s also possible to build your own MCP server on top of an API, even if you aren’t the API owner. You could build an MCP server for your favorite movie or book tracking tool for example to easily rate and review what movies/books you’ve watched/read.

You may also want to connect to your own data source or internal tools, for your company or personal use.

To build and host your own MCP server:

  1. Remix our mcp-server template

What about step 2? For a bare bones MCP server that works, there isn’t a step 2! You now have a working MCP server that you can connect to whichever MCP client you like (ChatGPT, Claude, Cursor, Gemini, et al.).

An easy way to test your MCP server is by copy-pasting its URL (from main.ts in your val) into Cloudflare’s AI playground and ask for the current time somewhere in the world. You’ll be able to see the model call the MCP server then answer your question.

example chat "what time is it in madrid"

To customize your MCP server:

  1. Replace the server.registerTool call on line 10 with your own tool
  2. Add more tools!

It’s just JavaScript, so you can import npm libraries, call APIs, do math, or whatever you’d like for your server. The template uses the official TypeScript SDK. You could even use our MCP server to build your MCP server.

You may also want to add a custom subdomain, like my-mcp-server.val.run, for convenience.

To protect your MCP server or restrict access, you can add an authentication mechanism. For reference, see Paul Carleton’s example vals mcp-oauth-ex1, mcp-oauth-ex2, and mcp-oauth-ex3.

As mentioned the Cloudflare AI playground is a quick and easy way to test an MCP server.

In “Model mode,” select “MCP Servers” and copy-paste your URL. You can add a header with a Bearer token if your server includes authentication. You should see a green "Ready" marker next to your MCP server once it’s connected.

Try sending a message related to your server’s tools. You’ll be able to see the tool calls in the chat.

Val Town’s architecture prioritizes development speed. You do not have to clone a repo, install dependencies, push changes, and wait for a build step. Your MCP server is live after every edit the moment you save, which is the primary advantage to building an MCP server on Val Town. That’s why it takes literally one step and one minute to deploy a simple MCP server.

That said, there are other reasonable alternatives to consider.

Vercel published their own guide to Deploy MCP servers to Vercel. If you’d like to stay in the Vercel ecosystem, that’s probably a good choice. If you want to prioritize a faster iteration feedback loop, Val Town is probably the better choice.

Cloudflare published their own guide to Build a Remote MCP server. Like Vercel, hosting an MCP server on Cloudflare requires a build step, so the iteration feedback loop would take a bit longer than Val Town, but it’s definitely a reasonable choice.

Really any hosting provider that can host a regular web server can host an MCP server. Railway, Render, Fly.io, Netlify, et al.

If you’d like a hand setting up your MCP server, we are responsive on email and discord. And we’d love to see your MCP server built in Val Town!

Last updated