# Build an MCP server so Claude and Cursor can use your data

> How to build a Model Context Protocol server in TypeScript: tools, inputs, stdio vs HTTP, connecting it to Claude Code and Cursor, and the security basics.

By Tommy Pham · 2026-11-14 · https://tommydev.web.app/blog/build-mcp-server

**Short answer:** an MCP (Model Context Protocol) server exposes **tools** that AI assistants like Claude, Cursor and ChatGPT can call: search your data, start a job, fetch a record. In TypeScript you install the official SDK, register each tool with a name, description and input schema, and connect a transport: **stdio** for a local server, **Streamable HTTP** for a hosted one. Then you add it to the client with one command or a short config block.

I built an MCP server for [PainBase](/work/painbase), my startup-research SaaS, so Claude and Cursor users can query its data from their assistant.

Part of my guide to [AI coding tools](/blog/claude-code-vs-cursor-vs-codex-vs-copilot).

## What should a server expose?

Think in **actions a user would ask for**, not database tables. PainBase's MCP server exposes tools such as:

| Tool | What it does |
|---|---|
| `validate_idea` | Checks a startup idea against collected complaints and market data |
| `search_pain_points` | Searches developer complaints by topic |
| `find_markets` | Lists ranked markets |
| `find_startups` | Finds startups and revenue data for a market |
| `start_deep_research` | Starts a long-running AI research report |
| `get_research` | Fetches a finished report |
| `account_status` | Shows the user's plan and usage |

Good tools have clear names, specific descriptions (the model picks tools from the description), narrow inputs, and outputs short enough to fit in context. Long jobs should **start** a task and return an ID, with a second tool to fetch the result.

## A minimal server in TypeScript

```bash
npm i @modelcontextprotocol/sdk zod
```

```ts
// src/index.ts
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { z } from 'zod';

const server = new McpServer({ name: 'notes', version: '1.0.0' });

server.registerTool(
  'search_notes',
  {
    title: 'Search notes',
    description: 'Full-text search over the user\'s notes. Returns up to 10 matches with id, title and snippet.',
    inputSchema: { query: z.string().min(2).describe('Words to search for') },
  },
  async ({ query }) => {
    const results = await searchNotes(query); // your database call
    return { content: [{ type: 'text', text: JSON.stringify(results) }] };
  },
);

await server.connect(new StdioServerTransport());
```

This uses the 1.x package (`@modelcontextprotocol/sdk`), which still gets maintenance releases. As of November 2026, v2 is the current major version, published as `@modelcontextprotocol/server` and `@modelcontextprotocol/client`. The concepts are the same but the imports differ, so follow the [official docs](https://ts.sdk.modelcontextprotocol.io/) for new projects.

## stdio or Streamable HTTP?

| | stdio | Streamable HTTP |
|---|---|---|
| Runs | On the user's machine, started by the client | On your server, reached over the internet |
| Good for | Local tools, files, dev utilities | SaaS data, shared tools, many users |
| Auth | The user's own environment and API keys | OAuth or API keys per user |
| Distribution | npm package or binary | A URL |

For a SaaS like PainBase, a hosted HTTP server means users connect with a URL and never install anything. A local server is simpler to build and fine for personal tools.

## How do I connect it?

**Claude Code:**

```bash
# local stdio server
claude mcp add notes -- node /path/to/dist/index.js
# hosted HTTP server
claude mcp add --transport http notes https://example.com/mcp
```

**Cursor:** add it in settings under MCP, or in `.cursor/mcp.json`:

```json
{ "mcpServers": { "notes": { "command": "node", "args": ["/path/to/dist/index.js"] } } }
```

Test with the [MCP Inspector](https://github.com/modelcontextprotocol/inspector) (`npx @modelcontextprotocol/inspector node dist/index.js`) before you connect a real client.

## Security basics

An MCP server is an API that an AI calls on a user's behalf. Treat it like one:

- **Authenticate every request** on hosted servers, and scope data to the authenticated user.
- **Validate inputs** with the schema. Never pass raw strings into SQL or shell commands.
- **Rate-limit expensive tools**, especially ones that trigger AI or paid API calls.
- **Treat returned content as untrusted.** Text you return goes into the model's context, so don't echo user-supplied content that could carry injected instructions without marking it as data.
- **Check the `Origin` header** on HTTP servers, as the spec recommends, to block DNS rebinding.
- **Keep write tools explicit.** Prefer `create_draft` over a tool that silently sends or deletes things.

## FAQ

### Do I need MCP if I already have a REST API?

MCP is how AI clients discover and call your API without custom integration code. If your users work in Claude, Cursor or ChatGPT, an MCP server lets them use your product from there. It usually wraps your existing API.

### Which clients support MCP?

Claude (desktop, web and Claude Code), Cursor, VS Code with Copilot, ChatGPT and many others support MCP servers, with varying support for remote servers and auth.

### Can I build one in Python?

Yes. There's an official Python SDK with the same concepts: tools, resources, prompts and transports.

---

Want an MCP server for your product or internal data? I've built one for a live SaaS. See [my work](/#work) or get in touch below.

## Sources

- [Model Context Protocol documentation](https://modelcontextprotocol.io) and [specification: transports](https://modelcontextprotocol.io/specification/latest/basic/transports)
- [MCP TypeScript SDK](https://ts.sdk.modelcontextprotocol.io/)
- Claude Code docs: [Connect to tools via MCP](https://docs.claude.com/en/docs/claude-code/mcp)
- Checked November 2026