diff --git a/CHANGELOG.md b/CHANGELOG.md index 297677b966..275dbb9b2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Improved the market price in the benchmark detail dialog by adding the currency and reducing the precision on mobile - Improved the style of the close button in the dialog footer component - Improved the style of the close button in the dialog header component +- Improved the instructions of the server of the Model Context Protocol (MCP) to give the limits of the Basic subscription only to a user with the Basic subscription (experimental) - Improved the language localization for German (`de`) - Upgraded `prettier` from version `3.9.9` to `3.9.10` diff --git a/apps/api/src/app/endpoints/mcp/mcp.module.ts b/apps/api/src/app/endpoints/mcp/mcp.module.ts index efa8917404..b98bb6bdf4 100644 --- a/apps/api/src/app/endpoints/mcp/mcp.module.ts +++ b/apps/api/src/app/endpoints/mcp/mcp.module.ts @@ -3,7 +3,10 @@ import { AccountModule } from '@ghostfolio/api/app/account/account.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'; @@ -11,6 +14,7 @@ import { ImportModule } from '@ghostfolio/api/services/import/import.module'; 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',