Skip to content

Commit 866c8fd

Browse files
Merge pull request #132 from modelcontextprotocol/justin/readme-improvements
Add instructions for starting the server transport
2 parents cf4c592 + 33654e1 commit 866c8fd

File tree

1 file changed

+58
-3
lines changed

1 file changed

+58
-3
lines changed

Diff for: README.md

+58-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
- [Tools](#tools)
1212
- [Prompts](#prompts)
1313
- [Running Your Server](#running-your-server)
14-
- [Development Mode](#development-mode)
15-
- [Claude Desktop Integration](#claude-desktop-integration)
16-
- [Direct Execution](#direct-execution)
14+
- [stdio](#stdio)
15+
- [HTTP with SSE](#http-with-sse)
16+
- [Testing and Debugging](#testing-and-debugging)
1717
- [Examples](#examples)
1818
- [Echo Server](#echo-server)
1919
- [SQLite Explorer](#sqlite-explorer)
@@ -178,6 +178,61 @@ server.prompt(
178178
);
179179
```
180180

181+
## Running Your Server
182+
183+
MCP servers in TypeScript need to be connected to a transport to communicate with clients. How you start the server depends on the choice of transport:
184+
185+
### stdio
186+
187+
For command-line tools and direct integrations:
188+
189+
```typescript
190+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
191+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
192+
193+
const server = new McpServer({
194+
name: "example-server",
195+
version: "1.0.0"
196+
});
197+
198+
const transport = new StdioServerTransport();
199+
await server.connect(transport);
200+
```
201+
202+
### HTTP with SSE
203+
204+
For remote servers, start a web server with a Server-Sent Events (SSE) endpoint, and a separate endpoint for the client to send its messages to:
205+
206+
```typescript
207+
import express from "express";
208+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
209+
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
210+
211+
const app = express();
212+
const server = new McpServer({
213+
name: "example-server",
214+
version: "1.0.0"
215+
});
216+
217+
app.get("/mcp", async (req, res) => {
218+
const transport = new SSEServerTransport("/messages", res);
219+
await server.connect(transport);
220+
});
221+
222+
app.post("/messages", async (req, res) => {
223+
// Note: to support multiple simultaneous connections, these messages will
224+
// need to be routed to a specific matching transport. (This logic isn't
225+
// implemented here, for simplicity.)
226+
await transport.handlePostMessage(req, res);
227+
});
228+
229+
app.listen(3000);
230+
```
231+
232+
### Testing and Debugging
233+
234+
To test your server, you can use the [MCP Inspector](https://github.com/modelcontextprotocol/inspector). See its README for more information.
235+
181236
## Examples
182237

183238
### Echo Server

0 commit comments

Comments
 (0)