@@ -164,6 +164,7 @@ function createMockDependencies() {
164164 getPluginPath : vi . fn ( ( ) => "/mock/plugin" ) ,
165165 } ,
166166 agentAuthAdapter : {
167+ getCurrentCredentials : vi . fn ( ) . mockResolvedValue ( null ) ,
167168 ensureGatewayProxy : vi . fn ( ) . mockResolvedValue ( "http://127.0.0.1:9999" ) ,
168169 configureProcessEnv : vi . fn ( ) . mockResolvedValue ( undefined ) ,
169170 createPosthogConfig : vi . fn ( ( credentials ) => ( {
@@ -277,6 +278,62 @@ describe("AgentService", () => {
277278 vi . unstubAllGlobals ( ) ;
278279 } ) ;
279280
281+ describe ( "mcp-apps config resolver" , ( ) => {
282+ function registeredResolver ( ) : ( serverName : string ) => Promise < void > {
283+ const call = deps . mcpAppsService . setConfigResolver . mock . calls [ 0 ] ;
284+ expect ( call ) . toBeDefined ( ) ;
285+ return call [ 0 ] ;
286+ }
287+
288+ it ( "registers server configs from the current credentials" , async ( ) => {
289+ deps . agentAuthAdapter . getCurrentCredentials . mockResolvedValue ( {
290+ apiHost : "https://app.posthog.com" ,
291+ projectId : 1 ,
292+ } ) ;
293+ deps . agentAuthAdapter . buildMcpServers . mockResolvedValue ( {
294+ servers : [
295+ {
296+ name : "posthog" ,
297+ type : "http" ,
298+ url : "https://mcp.posthog.com/mcp" ,
299+ headers : [
300+ { name : "Authorization" , value : "Bearer token" } ,
301+ { name : "x-posthog-mcp-consumer" , value : "posthog-code" } ,
302+ ] ,
303+ } ,
304+ ] ,
305+ toolApprovals : { } ,
306+ toolInstallations : { } ,
307+ } ) ;
308+
309+ await registeredResolver ( ) ( "posthog" ) ;
310+
311+ expect ( deps . agentAuthAdapter . buildMcpServers ) . toHaveBeenCalledWith ( {
312+ apiHost : "https://app.posthog.com" ,
313+ projectId : 1 ,
314+ } ) ;
315+ expect ( deps . mcpAppsService . addServerConfigs ) . toHaveBeenCalledWith ( [
316+ {
317+ name : "posthog" ,
318+ url : "https://mcp.posthog.com/mcp" ,
319+ headers : {
320+ Authorization : "Bearer token" ,
321+ "x-posthog-mcp-consumer" : "posthog-code" ,
322+ } ,
323+ } ,
324+ ] ) ;
325+ } ) ;
326+
327+ it ( "no-ops when there are no current credentials" , async ( ) => {
328+ deps . agentAuthAdapter . getCurrentCredentials . mockResolvedValue ( null ) ;
329+
330+ await registeredResolver ( ) ( "posthog" ) ;
331+
332+ expect ( deps . agentAuthAdapter . buildMcpServers ) . not . toHaveBeenCalled ( ) ;
333+ expect ( deps . mcpAppsService . addServerConfigs ) . not . toHaveBeenCalled ( ) ;
334+ } ) ;
335+ } ) ;
336+
280337 describe ( "MCP servers" , ( ) => {
281338 it ( "marks desktop sessions as local even though they have a taskRunId" , async ( ) => {
282339 await service . startSession ( {
0 commit comments