Skip to main content
Glama
nonnname

T-Invest MCP Server

by nonnname

get_consensus_forecasts

Retrieve analyst consensus forecasts for stock tickers from T-Invest to inform investment decisions with aggregated market predictions.

Instructions

Получить консенсус-прогнозы аналитиков по тикерам из Т-Инвестиций

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tickersYesМассив тикеров

Implementation Reference

  • The registration function contains the handler logic for the 'get_consensus_forecasts' tool, which fetches analyst consensus forecasts from the T-Invest API and formats the response.
    export function registerGetConsensusForecasts(server: McpServer, client: TInvestClient): void {
      server.tool(
        'get_consensus_forecasts',
        'Получить консенсус-прогнозы аналитиков по тикерам из Т-Инвестиций',
        {
          tickers: z.array(z.string()).min(1).max(50).describe('Массив тикеров'),
        },
        READ_ONLY,
        async ({ tickers }) => {
          try {
            const instrumentMap = await resolveTickersToInstruments(client, tickers);
    
            if (instrumentMap.size === 0) {
              return { content: [{ type: 'text' as const, text: 'Инструменты не найдены.' }] };
            }
    
            const uidToTicker = new Map(
              Array.from(instrumentMap.entries()).map(([ticker, inst]) => [inst.uid, ticker]),
            );
    
            const response = await client.post<GetConsensusForecastsResponse>(
              API_PATHS.INSTRUMENTS.GET_CONSENSUS_FORECASTS,
              {
                instrumentIds: Array.from(uidToTicker.keys()),
                paging: { pageNumber: 0, pageSize: 100 },
              },
            );
    
            if (!response.items || response.items.length === 0) {
              return { content: [{ type: 'text' as const, text: 'Прогнозы не найдены.' }] };
            }
    
            const lines = response.items.map((f) => {
              const ticker = uidToTicker.get(f.assetUid) ?? f.assetUid;
              const parts = [`${ticker}:`];
              if (f.consensus) parts.push(`  Консенсус: ${CONSENSUS_LABELS[f.consensus] ?? f.consensus}`);
              if (f.bestTargetPrice) parts.push(`  Целевая цена: ${quotationToNumber(f.bestTargetPrice).toFixed(2)} ${f.currency ?? ''}`);
              if (f.bestTargetLow) parts.push(`  Диапазон: ${quotationToNumber(f.bestTargetLow).toFixed(2)} – ${quotationToNumber(f.bestTargetHigh).toFixed(2)}`);
              const total = (f.totalBuyRecommendations ?? 0) + (f.totalHoldRecommendations ?? 0) + (f.totalSellRecommendations ?? 0);
              if (total > 0) {
                parts.push(`  Рекомендации: покупать ${f.totalBuyRecommendations ?? 0}, держать ${f.totalHoldRecommendations ?? 0}, продавать ${f.totalSellRecommendations ?? 0}`);
              }
              if (f.prognozDateEnd) parts.push(`  Горизонт: до ${formatDate(f.prognozDateEnd)}`);
              return parts.join('\n');
            });
    
            return { content: [{ type: 'text' as const, text: lines.join(SEPARATOR) }] };
          } catch (error) {
            return {
              content: [{ type: 'text' as const, text: `Ошибка: ${error instanceof Error ? error.message : String(error)}` }],
              isError: true,
            };
          }
        },
      );
    }
  • Tool registration using the MCP server instance.
    export function registerGetConsensusForecasts(server: McpServer, client: TInvestClient): void {
      server.tool(
        'get_consensus_forecasts',
        'Получить консенсус-прогнозы аналитиков по тикерам из Т-Инвестиций',
        {
          tickers: z.array(z.string()).min(1).max(50).describe('Массив тикеров'),
        },
        READ_ONLY,
        async ({ tickers }) => {
          try {
            const instrumentMap = await resolveTickersToInstruments(client, tickers);
    
            if (instrumentMap.size === 0) {
              return { content: [{ type: 'text' as const, text: 'Инструменты не найдены.' }] };
            }
    
            const uidToTicker = new Map(
              Array.from(instrumentMap.entries()).map(([ticker, inst]) => [inst.uid, ticker]),
            );
    
            const response = await client.post<GetConsensusForecastsResponse>(
              API_PATHS.INSTRUMENTS.GET_CONSENSUS_FORECASTS,
              {
                instrumentIds: Array.from(uidToTicker.keys()),
                paging: { pageNumber: 0, pageSize: 100 },
              },
            );
    
            if (!response.items || response.items.length === 0) {
              return { content: [{ type: 'text' as const, text: 'Прогнозы не найдены.' }] };
            }
    
            const lines = response.items.map((f) => {
              const ticker = uidToTicker.get(f.assetUid) ?? f.assetUid;
              const parts = [`${ticker}:`];
              if (f.consensus) parts.push(`  Консенсус: ${CONSENSUS_LABELS[f.consensus] ?? f.consensus}`);
              if (f.bestTargetPrice) parts.push(`  Целевая цена: ${quotationToNumber(f.bestTargetPrice).toFixed(2)} ${f.currency ?? ''}`);
              if (f.bestTargetLow) parts.push(`  Диапазон: ${quotationToNumber(f.bestTargetLow).toFixed(2)} – ${quotationToNumber(f.bestTargetHigh).toFixed(2)}`);
              const total = (f.totalBuyRecommendations ?? 0) + (f.totalHoldRecommendations ?? 0) + (f.totalSellRecommendations ?? 0);
              if (total > 0) {
                parts.push(`  Рекомендации: покупать ${f.totalBuyRecommendations ?? 0}, держать ${f.totalHoldRecommendations ?? 0}, продавать ${f.totalSellRecommendations ?? 0}`);
              }
              if (f.prognozDateEnd) parts.push(`  Горизонт: до ${formatDate(f.prognozDateEnd)}`);
              return parts.join('\n');
            });
    
            return { content: [{ type: 'text' as const, text: lines.join(SEPARATOR) }] };
          } catch (error) {
            return {
              content: [{ type: 'text' as const, text: `Ошибка: ${error instanceof Error ? error.message : String(error)}` }],
              isError: true,
            };
          }
        },
      );
    }
  • Type definition for the GetConsensusForecastsResponse object.
    export interface GetConsensusForecastsResponse {

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