Skip to main content
The @mcp-ts/sdk/server package provides handlers for standard Node.js and Express applications.

Server-Side Setup

Step 1: Install Dependencies

npm install express @mcp-ts/sdk

Step 2: Create SSE Handler

Create a file named mcp-handler.ts:
import express from 'express';
import { createSSEHandler } from '@mcp-ts/sdk/server';

const router = express.Router();

router.get('/sse', (req, res) => {
  const identity = req.query.identity as string;

  if (!identity) {
    return res.status(400).json({ error: 'identity required' });
  }

  const sseHandler = createSSEHandler({
    identity,
    heartbeatInterval: 30000,
  });

  return sseHandler(req, res);
});

export default router;

Step 3: Mount the Router

In your main app.ts or index.ts:
import express from 'express';
import mcpRouter from './mcp-handler';

const app = express();

app.use('/api/mcp', mcpRouter);

app.listen(3000, () => {
  console.log('Server running on http://localhost:3000');
});

Client-Side Setup

You can use the @mcp-ts/sdk/client in any frontend application.

Using with React

import { useMcp } from '@mcp-ts/sdk/client';

export function McpApp() {
  const { connections, connect, status } = useMcp({
    url: 'http://localhost:3000/api/mcp/sse?identity=user-123',
    identity: 'user-123',
  });

  const handleConnect = () => {
    connect({
      serverId: 'my-server',
      serverName: 'Local Server',
      serverUrl: 'http://localhost:8080',
    });
  };

  return (
    <div>
      <h2>Status: {status}</h2>
      <button onClick={handleConnect}>Connect</button>
      {/* Render connections and tools */}
    </div>
  );
}

Environment Configuration

Ensure your Express server has access to Redis or another storage backend:
REDIS_URL=redis://localhost:6379

Next Steps