Skip to main content
Glama
nonnname

T-Invest MCP Server

by nonnname

get_portfolio

Retrieve a client's investment portfolio from T-Invest, including positions and balances, with optional filtering by specific tickers.

Instructions

Получить портфель клиента в Т-Инвестициях

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
accountIdYesИдентификатор счёта (можно получить через get_accounts)
tickersNoФильтр по тикерам

Implementation Reference

  • The function `registerGetPortfolio` registers the 'get_portfolio' MCP tool and contains the main handler logic, including API interaction and response formatting.
    export function registerGetPortfolio(server: McpServer, client: TInvestClient): void {
      server.tool(
        'get_portfolio',
        'Получить портфель клиента в Т-Инвестициях',
        {
          accountId: z.string().describe('Идентификатор счёта (можно получить через get_accounts)'),
          tickers: z.array(z.string()).optional().describe('Фильтр по тикерам'),
        },
        READ_ONLY,
        async ({ accountId, tickers }) => {
          try {
            const response = await client.post<GetPortfolioResponse>(
              API_PATHS.OPERATIONS.GET_PORTFOLIO,
              { accountId, currency: 'RUB' },
            );
    
            if (!response.positions || response.positions.length === 0) {
              return { content: [{ type: 'text' as const, text: 'Портфель пуст.' }] };
            }
    
            const settled = await inBatches(
              response.positions,
              (pos) => resolveInstrumentByFigi(client, pos.figi),
            );
    
            const tickerFilter = tickers?.map((t) => t.toUpperCase());
            const results: string[] = [];
    
            for (let i = 0; i < response.positions.length; i++) {
              const pos = response.positions[i];
              const result = settled[i];
              const ticker = (result.status === 'fulfilled' && result.value) ? result.value : pos.figi;
    
              if (tickerFilter && tickerFilter.length > 0 && !tickerFilter.includes(ticker.toUpperCase())) {
                continue;
              }
              results.push(formatPosition(ticker, pos));
            }
    
            if (results.length === 0) {
              return { content: [{ type: 'text' as const, text: 'Позиции по указанным тикерам не найдены.' }] };
            }
    
            return { content: [{ type: 'text' as const, text: results.join(SEPARATOR) }] };
          } catch (error) {
            return {
              content: [{ type: 'text' as const, text: `Ошибка: ${error instanceof Error ? error.message : String(error)}` }],
              isError: true,
            };
          }
        },
      );
  • src/index.ts:69-69 (registration)
    Registration of the get_portfolio tool in the main server entry point.
    registerGetPortfolio(server, client);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nonnname/t-invest-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server