@@ -4,6 +4,8 @@ import test from "node:test";
44
55import { startMcpServer } from "../src/mcp-server.js" ;
66
7+ const TUNNEL_CONNECTION_ID = "64574786-7a08-4074-ab67-8078a40b7ba2" ;
8+
79function request ( { port, method = "GET" , path = "/" , headers = { } , body } ) {
810 return new Promise ( ( resolve , reject ) => {
911 const req = http . request ( { hostname : "127.0.0.1" , port, method, path, headers } , ( res ) => {
@@ -68,3 +70,63 @@ test("MCP GET supports event stream transport", async () => {
6870 httpServer . close ( ) ;
6971 }
7072} ) ;
73+
74+ test ( "MCP POST accepts Poke tunnel connection-id prefix" , async ( ) => {
75+ const { httpServer, port } = await startMcpServer ( ) ;
76+ try {
77+ const { res, body } = await request ( {
78+ port,
79+ method : "POST" ,
80+ path : `/${ TUNNEL_CONNECTION_ID } /mcp` ,
81+ headers : {
82+ "Content-Type" : "application/json" ,
83+ "Mcp-Session-Id" : "session-prefixed-post" ,
84+ } ,
85+ body : JSON . stringify ( { jsonrpc : "2.0" , id : 1 , method : "tools/list" , params : { } } ) ,
86+ } ) ;
87+
88+ assert . equal ( res . statusCode , 200 ) ;
89+ assert . equal ( res . headers [ "mcp-session-id" ] , "session-prefixed-post" ) ;
90+ assert . equal ( JSON . parse ( body ) . result . tools . length > 0 , true ) ;
91+ } finally {
92+ httpServer . close ( ) ;
93+ }
94+ } ) ;
95+
96+ test ( "MCP GET accepts Poke tunnel connection-id prefix" , async ( ) => {
97+ const { httpServer, port } = await startMcpServer ( ) ;
98+ try {
99+ const { res, body } = await request ( {
100+ port,
101+ path : `/${ TUNNEL_CONNECTION_ID } /mcp` ,
102+ headers : {
103+ Accept : "text/event-stream" ,
104+ "Mcp-Session-Id" : "session-prefixed-get" ,
105+ } ,
106+ } ) ;
107+
108+ assert . equal ( res . statusCode , 200 ) ;
109+ assert . equal ( res . headers [ "content-type" ] , "text/event-stream" ) ;
110+ assert . equal ( res . headers [ "mcp-session-id" ] , "session-prefixed-get" ) ;
111+ assert . match ( body , / : c o n n e c t e d / ) ;
112+ } finally {
113+ httpServer . close ( ) ;
114+ }
115+ } ) ;
116+
117+ test ( "MCP route rejects non-connection-id prefixes" , async ( ) => {
118+ const { httpServer, port } = await startMcpServer ( ) ;
119+ try {
120+ const { res } = await request ( {
121+ port,
122+ method : "POST" ,
123+ path : "/not-a-connection/mcp" ,
124+ headers : { "Content-Type" : "application/json" } ,
125+ body : JSON . stringify ( { jsonrpc : "2.0" , id : 1 , method : "tools/list" , params : { } } ) ,
126+ } ) ;
127+
128+ assert . equal ( res . statusCode , 404 ) ;
129+ } finally {
130+ httpServer . close ( ) ;
131+ }
132+ } ) ;
0 commit comments