Skip to content

Commit c91c504

Browse files
committed
sample:update express sample to use new class
1 parent b6594d7 commit c91c504

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

examples/express-mcp-server/src/index.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import express from 'express';
22
import {config} from 'dotenv';
3-
import {McpAuth, protectedRoute} from '@asgardeo/mcp-express';
3+
import {McpAuthServer} from '@asgardeo/mcp-express';
44
import {protectedRoutes} from './routes/protected';
55
import {publicRoutes} from './routes/public';
66

@@ -9,25 +9,18 @@ config();
99
const app = express();
1010
const port = process.env.PORT || 3000;
1111

12-
app.use(express.json());
12+
const mcpAuthServer = new McpAuthServer({
13+
baseUrl: process.env.BASE_URL as string,
14+
});
1315

14-
app.use(
15-
McpAuth({
16-
baseUrl: process.env.BASE_URL as string,
17-
}),
18-
);
16+
app.use(express.json());
17+
app.use(mcpAuthServer.router());
1918

2019
// Public routes
2120
app.use('/api', publicRoutes);
2221

2322
// Protected routes with MCP authentication
24-
app.use(
25-
'/api/protected',
26-
protectedRoute({
27-
baseUrl: process.env.BASE_URL as string,
28-
}),
29-
protectedRoutes,
30-
);
23+
app.use('/api/protected', mcpAuthServer.protect(protectedRoutes));
3124

3225
// Error handling middleware
3326
app.use((err: Error, req: express.Request, res: express.Response, next: express.NextFunction) => {

0 commit comments

Comments
 (0)