Skip to content

Commit 6c610ba

Browse files
Merge pull request modelcontextprotocol#112 from tadasant/tadas/update-sse-ts-example
Fix example for implementing SSE Server in TypeScript
2 parents 78b6c2a + b1f4f72 commit 6c610ba

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

docs/concepts/transports.mdx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,31 @@ Use SSE when:
126126
<Tabs>
127127
<Tab title="TypeScript (Server)">
128128
```typescript
129+
import express from "express";
130+
131+
const app = express();
132+
129133
const server = new Server({
130134
name: "example-server",
131135
version: "1.0.0"
132136
}, {
133137
capabilities: {}
134138
});
139+
140+
let transport: SSEServerTransport | null = null;
135141

136-
const transport = new SSEServerTransport("/message", response);
137-
await server.connect(transport);
142+
app.get("/sse", (req, res) => {
143+
transport = new SSEServerTransport("/messages", res);
144+
server.connect(transport);
145+
});
146+
147+
app.post("/messages", (req, res) => {
148+
if (transport) {
149+
transport.handlePostMessage(req, res);
150+
}
151+
});
152+
153+
app.listen(3000);
138154
```
139155
</Tab>
140156
<Tab title="TypeScript (Client)">

0 commit comments

Comments
 (0)