From 63f0ab61ae044147a1422930ff1c62d8699d29a3 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Wed, 21 Oct 2026 08:05:39 +0200 Subject: [PATCH] Improve instructions of MCP server --- apps/api/src/app/endpoints/mcp/mcp.module.ts | 36 +++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/apps/api/src/app/endpoints/mcp/mcp.module.ts b/apps/api/src/app/endpoints/mcp/mcp.module.ts index c1e2885b7f..5c7d50baa7 100644 --- a/apps/api/src/app/endpoints/mcp/mcp.module.ts +++ b/apps/api/src/app/endpoints/mcp/mcp.module.ts @@ -4,13 +4,17 @@ import { ImportModule } from '@ghostfolio/api/app/import/import.module'; import { SymbolModule } from '@ghostfolio/api/app/symbol/symbol.module'; import { UserModule } from '@ghostfolio/api/app/user/user.module'; import { environment } from '@ghostfolio/api/environments/environment'; -import { getMcpUserOfBearerToken } from '@ghostfolio/api/helper/bearer-token.helper'; +import { + getActiveImpersonationOfBearerToken, + getMcpUserOfBearerToken +} from '@ghostfolio/api/helper/bearer-token.helper'; import { ApiModule } from '@ghostfolio/api/services/api/api.module'; import { ConfigurationModule } from '@ghostfolio/api/services/configuration/configuration.module'; import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; import { PortfolioTableModule } from '@ghostfolio/api/services/portfolio-table/portfolio-table.module'; import { PortfolioTableService } from '@ghostfolio/api/services/portfolio-table/portfolio-table.service'; import { MCP_ENDPOINT } from '@ghostfolio/common/config'; +import { SubscriptionType } from '@ghostfolio/common/enums'; import { Module } from '@nestjs/common'; import { @@ -43,20 +47,28 @@ import { McpService } from './mcp.service'; useFactory: (configurationService: ConfigurationService) => { const { hostname } = new URL(configurationService.get('ROOT_URL')); - const instructions = [ - 'Ghostfolio is a wealth management application. The tools read the portfolio and the watchlist of the user who granted the access, import activities into the portfolio and update the cash balances of the accounts. They give the quantities and the monetary values only if the access has the permission "View" or "View and manage", otherwise no quantity and no monetary value (except the unit price of an activity). Only the tools which the permission of the access covers are listed. To import activities or to update a cash balance, the access needs the permission "Restricted view and manage" or "View and manage".' - ]; + const instructions = + 'Ghostfolio is a wealth management application. The tools read the portfolio and the watchlist of the user who granted the access, import activities into the portfolio and update the cash balances of the accounts. They give the quantities and the monetary values only if the access has the permission "View" or "View and manage", otherwise no quantity and no monetary value (except the unit price of an activity). Only the tools which the permission of the access covers are listed. To import activities or to update a cash balance, the access needs the permission "Restricted view and manage" or "View and manage".'; - if (configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) { - instructions.push( - `With the Basic subscription, the tool get-performance does not give these columns: ${PortfolioTableService.getAssetPerformanceInBaseCurrencyColumnNames().join( - ', ' - )}.` - ); - } + const instructionsOfBasicSubscription = [ + instructions, + `The user who granted the access has the Basic subscription, hence the tool get-performance does not give these columns: ${PortfolioTableService.getAssetPerformanceInBaseCurrencyColumnNames().join( + ', ' + )}.` + ].join(' '); return new McpStrategy({ - instructions: instructions.join(' '), + // The instructions are resolved for each request, hence only a user + // with the Basic subscription gets the note on its limits + instructions: ({ request }) => { + const isBasicSubscription = + getActiveImpersonationOfBearerToken(request)?.userSubscription + ?.type === SubscriptionType.Basic; + + return isBasicSubscription + ? instructionsOfBasicSubscription + : instructions; + }, name: 'ghostfolio', resolveUser: getMcpUserOfBearerToken, title: 'Ghostfolio',