Browse Source

Feature/add MCP tool to get performance (part 2) (#8001)

Add MCP tool to get performance
pull/8002/head
Thomas Kaul 7 days ago
committed by GitHub
parent
commit
347cd06a40
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 16
      apps/api/src/app/endpoints/mcp/mcp.schemas.spec.ts
  2. 30
      apps/api/src/app/endpoints/mcp/mcp.service.spec.ts
  3. 5
      apps/api/src/app/endpoints/mcp/mcp.service.ts

16
apps/api/src/app/endpoints/mcp/mcp.schemas.spec.ts

@ -68,6 +68,22 @@ describe('GET_PERFORMANCE_PARAMETERS', () => {
false false
); );
}); });
it('Refuses an empty symbol of the holding', () => {
expect(
GET_PERFORMANCE_PARAMETERS.safeParse({
holding: { dataSource: DataSource.YAHOO, symbol: '' }
}).success
).toBe(false);
});
it('Refuses a symbol of the holding that contains only spaces', () => {
expect(
GET_PERFORMANCE_PARAMETERS.safeParse({
holding: { dataSource: DataSource.YAHOO, symbol: ' ' }
}).success
).toBe(false);
});
}); });
describe('IMPORT_ACTIVITIES_PARAMETERS', () => { describe('IMPORT_ACTIVITIES_PARAMETERS', () => {

30
apps/api/src/app/endpoints/mcp/mcp.service.spec.ts

@ -260,6 +260,36 @@ describe('McpService', () => {
}); });
}); });
it('Resolves the mask of the data source of the Ghostfolio data provider', async () => {
configuration.DATA_SOURCES_GHOSTFOLIO_DATA_PROVIDER = [DataSource.YAHOO];
configuration.ENABLE_FEATURE_SUBSCRIPTION = true;
await mcpService.getPerformance({
userId,
holding: { dataSource: DataSource.GHOSTFOLIO, symbol: 'AAPL' },
range: 'max'
});
expect(apiService.buildFiltersFromQueryParams).toHaveBeenCalledWith(
expect.objectContaining({ filterByDataSource: DataSource.YAHOO })
);
});
it('Keeps the data source if the subscription is not enabled', async () => {
configuration.DATA_SOURCES_GHOSTFOLIO_DATA_PROVIDER = [DataSource.YAHOO];
configuration.ENABLE_FEATURE_SUBSCRIPTION = false;
await mcpService.getPerformance({
userId,
holding: { dataSource: DataSource.GHOSTFOLIO, symbol: 'AAPL' },
range: 'max'
});
expect(apiService.buildFiltersFromQueryParams).toHaveBeenCalledWith(
expect.objectContaining({ filterByDataSource: DataSource.GHOSTFOLIO })
);
});
it('Gives the table of the performance of the filters in the range', async () => { it('Gives the table of the performance of the filters in the range', async () => {
expect( expect(
await mcpService.getPerformance({ userId, range: '2024' }) await mcpService.getPerformance({ userId, range: '2024' })

5
apps/api/src/app/endpoints/mcp/mcp.service.ts

@ -104,10 +104,9 @@ export class McpService {
userId userId
}: z.infer<typeof GET_PERFORMANCE_PARAMETERS> & { userId: string }) { }: z.infer<typeof GET_PERFORMANCE_PARAMETERS> & { userId: string }) {
const filters = this.apiService.buildFiltersFromQueryParams({ const filters = this.apiService.buildFiltersFromQueryParams({
...this.getHoldingFilterParameters({ holding }),
filterByAccounts: accountIds, filterByAccounts: accountIds,
filterByAssetClasses: assetClasses, filterByAssetClasses: assetClasses
filterByDataSource: holding?.dataSource,
filterBySymbol: holding?.symbol
}); });
const table = await this.portfolioTableService.getPerformanceTable({ const table = await this.portfolioTableService.getPerformanceTable({

Loading…
Cancel
Save