1717 */
1818
1919import { randomUUID } from 'node:crypto' ;
20- import { McpAuth , protectedRoute } from '@asgardeo/mcp-express' ;
20+ import { McpAuthServer } from '@asgardeo/mcp-express' ;
2121import { McpServer } from '@modelcontextprotocol/sdk/server/mcp' ;
2222import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp' ;
2323import { isInitializeRequest } from '@modelcontextprotocol/sdk/types' ;
@@ -28,12 +28,13 @@ import {z} from 'zod';
2828config ( ) ;
2929
3030const app : Express = express ( ) ;
31+
32+ const mcpAuthServer = new McpAuthServer ( {
33+ baseUrl : process . env . BASE_URL as string ,
34+ } ) ;
35+
3136app . use ( express . json ( ) ) ;
32- app . use (
33- McpAuth ( {
34- baseUrl : process . env . BASE_URL as string ,
35- } ) ,
36- ) ;
37+ app . use ( mcpAuthServer . router ( ) ) ;
3738
3839interface TransportMap {
3940 [ sessionId : string ] : {
@@ -49,10 +50,7 @@ const isSessionExpired = (lastAccessTime: number): boolean => Date.now() - lastA
4950
5051app . post (
5152 '/mcp' ,
52- protectedRoute ( {
53- baseUrl : process . env . BASE_URL as string ,
54- } ) ,
55- async ( req : Request , res : Response ) : Promise < void > => {
53+ mcpAuthServer . protect ( async ( req : Request , res : Response ) : Promise < void > => {
5654 try {
5755 const sessionId : string | undefined = req . headers [ 'mcp-session-id' ] as string | undefined ;
5856 let transport : StreamableHTTPServerTransport ;
@@ -212,7 +210,7 @@ app.post(
212210 jsonrpc : '2.0' ,
213211 } ) ;
214212 }
215- } ,
213+ } ) ,
216214) ;
217215
218216const handleSessionRequest = async ( expressReq : Request , expressRes : Response ) : Promise < void > => {
0 commit comments