You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

83 lines
3.6 KiB

import { environment } from '@ghostfolio/api/environments/environment';
import {
getMcpUserOfBearerToken,
hasLimitsOfBasicSubscriptionOfBearerToken
} from '@ghostfolio/api/helper/bearer-token.helper';
import { AccountBalanceModule } from '@ghostfolio/api/services/account-balance/account-balance.module';
import { AccountModule } from '@ghostfolio/api/services/account/account.module';
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 { 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 { SymbolProfileModule } from '@ghostfolio/api/services/symbol-profile/symbol-profile.module';
import { SymbolModule } from '@ghostfolio/api/services/symbol/symbol.module';
import { UserModule } from '@ghostfolio/api/services/user/user.module';
import { MCP_ENDPOINT } from '@ghostfolio/common/config';
import { Module } from '@nestjs/common';
import {
MCP_STRATEGY,
McpStrategy,
StreamableHttpTransport
} from '@rekog/mcp-nest';
import { GhostfolioMcpController } from './mcp.controller';
import { McpService } from './mcp.service';
@Module({
controllers: [GhostfolioMcpController],
exports: [McpService],
imports: [
AccountBalanceModule,
AccountModule,
ApiModule,
ConfigurationModule,
ImportModule,
PortfolioTableModule,
SymbolModule,
SymbolProfileModule,
UserModule
],
providers: [
McpService,
{
inject: [ConfigurationService],
provide: MCP_STRATEGY,
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 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(
', '
)}.`;
return new McpStrategy({
instructions: ({ request }) => {
return hasLimitsOfBasicSubscriptionOfBearerToken(request)
? instructionsOfBasicSubscription
: instructions;
},
name: 'ghostfolio',
resolveUser: getMcpUserOfBearerToken,
title: 'Ghostfolio',
transports: [
new StreamableHttpTransport({
endpoint: MCP_ENDPOINT,
security: {
allowedHosts: [hostname],
allowedOrigins: [hostname]
}
})
],
version: environment.version,
websiteUrl: 'https://ghostfol.io'
});
}
}
]
})
export class McpModule {}