MCP server starter
Give an AI assistant new tools: a Model Context Protocol server over HTTP.
Open in editor Free. Runs in your browser, no sign-up.
- @modelcontextprotocol/sdk
- express
- zod
MCP
The code
Two files, exactly what you get in the editor.
import express from 'express'
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js'
import { z } from 'zod'
// Each request gets a fresh, stateless server. Add your own tools below.
function tools() {
const server = new McpServer({ name: 'jsdrop-tools', version: '1.0.0' })
server.registerTool(
'roll_dice',
{
title: 'Roll dice',
description: 'Roll a number of dice with the given number of sides.',
inputSchema: { count: z.number().int().min(1).max(20), sides: z.number().int().min(2).max(100) },
},
async ({ count, sides }) => {
const rolls = Array.from({ length: count }, () => 1 + Math.floor(Math.random() * sides))
return { content: [{ type: 'text', text: `Rolled ${rolls.join(', ')} (total ${rolls.reduce((a, b) => a + b, 0)})` }] }
},
)
server.registerTool(
'word_count',
{
title: 'Count words',
description: 'Count the words and characters in a text.',
inputSchema: { text: z.string() },
},
async ({ text }) => ({
content: [{ type: 'text', text: JSON.stringify({ words: text.split(/\s+/).filter(Boolean).length, characters: text.length }) }],
}),
)
return server
}
const app = express()
app.use(express.json())
app.get('/', (req, res) => {
const endpoint = `${req.protocol}://${req.get('host')}/mcp`
res.type('html').send(`<h1>MCP tool server</h1>
<p>Point your MCP client at <code>${endpoint}</code> (Streamable HTTP).</p>`)
})
app.post('/mcp', async (req, res) => {
const server = tools()
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined })
res.on('close', () => {
transport.close()
server.close()
})
await server.connect(transport)
await transport.handleRequest(req, res, req.body)
})
const port = Number(process.env.PORT) || 3000
app.listen(port, () => console.log(`MCP server on port ${port}, endpoint /mcp`))
Questions
Can I run MCP server in the browser?
Yes. Press Run and the program runs in a Node.js-compatible runtime, compiled to WebAssembly, right in your browser tab. npm packages install in the browser too.
How do I start a MCP server project online?
Click Open in editor. jsdrop copies this starter into a new drop with index.ts and package.json. Press Run to start it, and edit as you go.
Can other people reach my server?
Yes. When the program calls listen(), the preview shows the server and a public tunnel URL that works while your tab runs it. With Pro, deploy the drop to run around the clock at its own address.
Is it free?
Yes. Public drops, running in the browser, live collaboration, versions, and embeds are free, and you do not need an account to start.