A starter project for building Model Context Protocol (MCP) servers in TypeScript. This project provides a simple echo server implementation that demonstrates the core features of MCP.
git clone https://github.com/ralf-boltshauser/mcp-typescript-server-starter.git
cd mcp-typescript-server-starter
pnpm install
pnpm dev
src/index.ts
to add your own:
src/index.html
with your server's description and documentationhttps://subdomain.yourdomain.com:3001
:3001
is crucial - it tells traefik to bind to your internal portsubdomain.yourdomain.com
to see your index.htmlhttps://subdomain.yourdomain.com/sse
Use this command to connect to your server:
npx -y mcp-remote https://subdomain.yourdomain.com/sse
Example configuration for Cursor/Claude Desktop:
{
"mcpServers": {
"your-server-name": {
"command": "npx",
"args": ["-y", "mcp-remote", "https://subdomain.yourdomain.com/sse"]
},
}
}
This server supports two main communication modes:
STDIO Mode
SSE Mode
Choose STDIO for local development and SSE when you need to deploy your server for remote access.
This mode is ideal for direct integration with tools like Cursor or Claude Desktop.
Configure the Server
src/index.ts
:
Build and Run
pnpm build
node dist/index.cjs
or
pnpm dev # starts the server and the inspector
Integration with Claude Desktop
pnpm add-claude
⚠️ Note: This will overwrite your existing Claude Desktop configuration.
This way of configuring claude desktop is standard. The json that is generated can also be used in cursor and so on!
Manual Integration For other tools, use the command:
node /path/to/your/project/dist/index.cjs
or
pnpm cmd # this gives you the node .../dist/index.cjs command directly with pwd
This mode is ideal for web-based tools and remote deployments.
Configure the Server
src/index.ts
:
Local Development
pnpm dev
The server will be available at:
Local Docker Testing The docker compose override is needed to actually expose the ports. When deploying to stuff like coolify you don't want it because traefik will handle it.
docker compose -f docker-compose.yaml -f docker-compose.local.yaml up
Production Deployment (e.g., Coolify)
Using the Remote Server Once deployed, you can connect to the server using:
npx -y mcp-remote https://your-domain.com/sse
You can paste this as command and replace the "node .../dist/index.cjs" with this.
src/index.ts
- Main server implementationsrc/low-level-index.ts
- Alternative implementation using the low-level APIdist/
- Compiled output directoryA simple tool that echoes back the input message:
server.tool("echo", { message: z.string() }, async ({ message }) => ({
content: [{ type: "text", text: `Tool echo: ${message}` }],
}));
A resource that can be accessed via URI:
server.resource(
"echo",
new ResourceTemplate("echo://{message}", { list: undefined }),
async (uri, { message }) => ({
contents: [
{
uri: uri.href,
text: `Resource echo: ${message}`,
},
],
})
);
A prompt template for processing messages:
server.prompt("echo", { message: z.string() }, ({ message }) => ({
messages: [
{
role: "user",
content: {
type: "text",
text: `Please process this message: ${message}`,
},
},
],
}));
Debug messages can be sent using the server.server.sendLoggingMessage
method to provide visibility into server operations.
server.server.sendLoggingMessage({
level: "info",
data: "Starting server...",
});
This allows you to:
You can see them in the inspector on the bottom right!
For server-side environment variables (developer-provided, not user-specific):
Using Docker Compose
# docker-compose.yaml
services:
mmcp-server:
environment:
- API_KEY=${API_KEY}
- DATABASE_URL=${DATABASE_URL}
This allows you to:
export API_KEY=your-key
.env
file that Docker Compose will automatically loadAccessing in Code
const apiKey = process.env.API_KEY;
const dbUrl = process.env.DATABASE_URL;
Local Development
.env
file in your project root:
API_KEY=sk-123
.env
to .gitignore
to keep secrets securepnpm dev
Production Deployment
Error Handling
Type Safety
zod
for runtime checksSecurity
{
"mcpServers": {
"your-server-name": {
"env": {},
"args": [
"-y",
"mcp-remote",
"https://subdomain.yourdomain.com/sse"
],
"command": "npx"
}
}
}
Seamless access to top MCP servers powering the future of AI integration.