@@ -4,7 +4,6 @@ import './polyfill.ts'
44import http from 'node:http'
55import { randomUUID } from 'node:crypto'
66import { parseArgs } from '@std/cli/parse-args'
7- import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js'
87import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
98import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js'
109import { isInitializeRequest } from '@modelcontextprotocol/sdk/types.js'
@@ -28,24 +27,17 @@ export async function main() {
2827 } )
2928 const port = parseInt ( flags . port )
3029 runStreamableHttp ( port )
31- } else if ( args . length >= 1 && args [ 0 ] === 'sse' ) {
32- const flags = parseArgs ( Deno . args , {
33- string : [ 'port' ] ,
34- default : { port : '3001' } ,
35- } )
36- const port = parseInt ( flags . port )
37- runSse ( port )
3830 } else if ( args . length === 1 && args [ 0 ] === 'warmup' ) {
3931 await warmup ( )
4032 } else {
4133 console . error (
4234 `\
4335Invalid arguments.
4436
45- Usage: deno task run [stdio|streamable_http|sse| warmup]
37+ Usage: deno task run [stdio|streamable_http|warmup]
4638
4739options:
48- --port <port> Port to run the SSE server on (default: 3001)` ,
40+ --port <port> Port to run the HTTP server on (default: 3001)` ,
4941 )
5042 Deno . exit ( 1 )
5143 }
@@ -115,7 +107,7 @@ print('python code here')
115107}
116108
117109/*
118- * Define some QOL functions for both the SSE and Streamable HTTP server implementation
110+ * Define some QOL functions for both the Streamable HTTP server implementation
119111 */
120112function httpGetUrl ( req : http . IncomingMessage ) : URL {
121113 return new URL (
@@ -227,7 +219,7 @@ function runStreamableHttp(port: number) {
227219 // Handle the request
228220 await transport . handleRequest ( req , res , body )
229221 } else if ( match ( 'GET' , '/mcp' ) ) {
230- // Handle server-to-client notifications via SSE
222+ // Handle server-to-client notifications
231223 await handleSessionRequest ( )
232224 } else if ( match ( 'DELETE' , '/mcp' ) ) {
233225 // Handle requests for session termination
@@ -246,53 +238,6 @@ function runStreamableHttp(port: number) {
246238 } )
247239}
248240
249- /*
250- * Run the MCP server using the SSE transport, e.g. over HTTP.
251- */
252- function runSse ( port : number ) {
253- const mcpServer = createServer ( )
254- const transports : { [ sessionId : string ] : SSEServerTransport } = { }
255-
256- const server = http . createServer ( async ( req , res ) => {
257- const url = httpGetUrl ( req )
258- let pathMatch = false
259- function match ( method : string , path : string ) : boolean {
260- if ( url . pathname === path ) {
261- pathMatch = true
262- return req . method === method
263- }
264- return false
265- }
266-
267- if ( match ( 'GET' , '/sse' ) ) {
268- const transport = new SSEServerTransport ( '/messages' , res )
269- transports [ transport . sessionId ] = transport
270- res . on ( 'close' , ( ) => {
271- delete transports [ transport . sessionId ]
272- } )
273- await mcpServer . connect ( transport )
274- } else if ( match ( 'POST' , '/messages' ) ) {
275- const sessionId = url . searchParams . get ( 'sessionId' ) ?? ''
276- const transport = transports [ sessionId ]
277- if ( transport ) {
278- await transport . handlePostMessage ( req , res )
279- } else {
280- httpSetTextResponse ( res , 400 , `No transport found for sessionId '${ sessionId } '` )
281- }
282- } else if ( pathMatch ) {
283- httpSetTextResponse ( res , 405 , 'Method not allowed' )
284- } else {
285- httpSetTextResponse ( res , 404 , 'Page not found' )
286- }
287- } )
288-
289- server . listen ( port , ( ) => {
290- console . log (
291- `Running MCP Run Python version ${ VERSION } with SSE transport on port ${ port } ` ,
292- )
293- } )
294- }
295-
296241/*
297242 * Run the MCP server using the Stdio transport.
298243 */
0 commit comments