File tree Expand file tree Collapse file tree
shared/src/lib/authentication/model Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import fs from 'fs/promises';
1111import { OpenAPI } from 'openapi-types' ;
1212import os from 'os' ;
1313import path from 'path' ;
14+ import { accessTokenManager } from '../../authentication/context/access-token-manager' ;
1415import { MCPTool } from './types' ;
1516
1617const INCLUDED_PATHS : Record < string , string [ ] > = {
@@ -68,7 +69,7 @@ async function getOpenApiSchemaPath(app: FastifyInstance): Promise<string> {
6869
6970export async function getOpenOpsTools (
7071 app : FastifyInstance ,
71- authToken : string ,
72+ userAuthToken : string ,
7273) : Promise < MCPTool > {
7374 const basePath = system . getOrThrow < string > (
7475 AppSystemProp . OPENOPS_MCP_SERVER_PATH ,
@@ -79,13 +80,15 @@ export async function getOpenOpsTools(
7980
8081 const tempSchemaPath = await getOpenApiSchemaPath ( app ) ;
8182
83+ const mcpToken = await accessTokenManager . generateMCPToken ( userAuthToken ) ;
84+
8285 const openopsClient = await experimental_createMCPClient ( {
8386 transport : new Experimental_StdioMCPTransport ( {
8487 command : pythonPath ,
8588 args : [ serverPath ] ,
8689 env : {
8790 OPENAPI_SCHEMA_PATH : tempSchemaPath ,
88- AUTH_TOKEN : authToken ,
91+ AUTH_TOKEN : mcpToken ,
8992 API_BASE_URL : networkUtls . getInternalApiUrl ( ) ,
9093 OPENOPS_MCP_SERVER_PATH : basePath ,
9194 LOGZIO_TOKEN : system . get < string > ( SharedSystemProp . LOGZIO_TOKEN ) ?? '' ,
Original file line number Diff line number Diff line change @@ -31,6 +31,24 @@ export const accessTokenManager = {
3131 } ) ;
3232 } ,
3333
34+ async generateMCPToken (
35+ userToken : string ,
36+ expiresInSeconds : number = openOpsRefreshTokenLifetimeSeconds ,
37+ ) : Promise < string > {
38+ const principal = await this . extractPrincipal ( userToken ) ;
39+
40+ const secret = await jwtUtils . getJwtSecret ( ) ;
41+
42+ return jwtUtils . sign ( {
43+ payload : {
44+ ...principal ,
45+ token : PrincipalType . MCP ,
46+ } ,
47+ key : secret ,
48+ expiresInSeconds,
49+ } ) ;
50+ } ,
51+
3452 async generateEngineToken ( {
3553 executionCorrelationId,
3654 projectId,
Original file line number Diff line number Diff line change 11export enum PrincipalType {
2+ MCP = 'MCP' ,
23 USER = 'USER' ,
34 ENGINE = 'ENGINE' ,
45 SERVICE = 'SERVICE' ,
You can’t perform that action at this time.
0 commit comments