Browse Source

Improve instructions of MCP server

pull/8263/head
Thomas Kaul 3 days ago
parent
commit
63f0ab61ae
  1. 36
      apps/api/src/app/endpoints/mcp/mcp.module.ts

36
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 { SymbolModule } from '@ghostfolio/api/app/symbol/symbol.module';
import { UserModule } from '@ghostfolio/api/app/user/user.module'; import { UserModule } from '@ghostfolio/api/app/user/user.module';
import { environment } from '@ghostfolio/api/environments/environment'; 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 { ApiModule } from '@ghostfolio/api/services/api/api.module';
import { ConfigurationModule } from '@ghostfolio/api/services/configuration/configuration.module'; import { ConfigurationModule } from '@ghostfolio/api/services/configuration/configuration.module';
import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service';
import { PortfolioTableModule } from '@ghostfolio/api/services/portfolio-table/portfolio-table.module'; import { PortfolioTableModule } from '@ghostfolio/api/services/portfolio-table/portfolio-table.module';
import { PortfolioTableService } from '@ghostfolio/api/services/portfolio-table/portfolio-table.service'; import { PortfolioTableService } from '@ghostfolio/api/services/portfolio-table/portfolio-table.service';
import { MCP_ENDPOINT } from '@ghostfolio/common/config'; import { MCP_ENDPOINT } from '@ghostfolio/common/config';
import { SubscriptionType } from '@ghostfolio/common/enums';
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { import {
@ -43,20 +47,28 @@ import { McpService } from './mcp.service';
useFactory: (configurationService: ConfigurationService) => { useFactory: (configurationService: ConfigurationService) => {
const { hostname } = new URL(configurationService.get('ROOT_URL')); const { hostname } = new URL(configurationService.get('ROOT_URL'));
const instructions = [ 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".' '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')) { const instructionsOfBasicSubscription = [
instructions.push( instructions,
`With the Basic subscription, the tool get-performance does not give these columns: ${PortfolioTableService.getAssetPerformanceInBaseCurrencyColumnNames().join( `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({ 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', name: 'ghostfolio',
resolveUser: getMcpUserOfBearerToken, resolveUser: getMcpUserOfBearerToken,
title: 'Ghostfolio', title: 'Ghostfolio',

Loading…
Cancel
Save