Skip to content

Commit 9e962ab

Browse files
committed
feat: create McpAuthServer class
1 parent 4e43145 commit 9e962ab

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import express, {Router, RequestHandler} from 'express';
2+
import {McpAuthOptions} from '@asgardeo/mcp-node';
3+
import protectedRoute from './middlewares/protected-route';
4+
import AuthRouter from './routes/auth';
5+
6+
export class McpAuthServer {
7+
private options: McpAuthOptions;
8+
private routerInstance: Router;
9+
10+
constructor(options: McpAuthOptions) {
11+
if (!options.baseUrl) {
12+
throw new Error('baseUrl must be provided');
13+
}
14+
this.options = options;
15+
this.routerInstance = AuthRouter(this.options);
16+
}
17+
18+
public router(): Router {
19+
return this.routerInstance;
20+
}
21+
22+
public protect(handler: RequestHandler): Router {
23+
const protectedRouter = express.Router();
24+
protectedRouter.use(protectedRoute(this.options), handler);
25+
return protectedRouter;
26+
}
27+
}

packages/mcp-express/src/public-api.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@
1616
* under the License.
1717
*/
1818

19-
export {default as McpAuth} from './routes/auth';
20-
export {default as protectedRoute} from './middlewares/protected-route';
19+
export {McpAuthServer} from './McpAuthServer';

0 commit comments

Comments
 (0)