Skip to main content
Glama

Finance MCP Server

by botextractai

Сервер и клиент MCP (Model Context Protocol) с использованием FastMCP и LangChain

В этом примере создается локальный сервер MCP с использованием FastMCP и агент искусственного интеллекта LangChain, который использует инструменты, определенные на сервере MCP.

Создание MCP-серверов обычно требует большого количества шаблонного кода и конфигурации. FastMCP значительно упрощает настройку MCP-серверов.

Адаптеры LangChain MCP могут легко подключаться к локальным или внешним серверам MCP.

В этом примере FastMCP используется для создания локального сервера MCP, а затем используются адаптеры LangChain MCP на стороне клиента. Поскольку в этом примере используется OpenAI Large Language Model (LLM), он также использует реализацию OpenAI LangChain для связи с LLM. Он создает агент LangGraph ReAct (Reasoning and Acting). Asyncio необходим для асинхронных функций.

Поскольку в этом примере используется локальный сервер MCP, соединение («транспорт») использует stdio (стандартные потоки ввода/вывода Python). Для внешнего сервера MCP вместо stdio потребуются Server-Sent Events (SSE) или транспорт WebSockets.

LLM можно спросить о чем угодно, касательно акций. Затем LLM вызовет инструменты, определенные на сервере MCP, соберет всю информацию и ответит собранной информацией.

В этом примере спрашивается:

What company uses the stock ticker META and how did this company's revenue develop over the last quarters and years?

YFinance предоставляет инструменты фондового рынка для сервера MCP. YFinance — это библиотека Python, используемая для доступа к финансовым данным Yahoo Finance. YFinance не требует ключа API.

Требуемый ключ API для этого примера

Для этого примера вам понадобится ключ API OpenAI. Получите свой ключ API OpenAI здесь . Вставьте ключ API OpenAI в файл .env.example , а затем переименуйте этот файл просто в .env (удалите окончание ".example").

Запустите этот пример

Запустите приложение из командной строки с помощью:

python mcp_client.py

Примеры результатов

Как видно из ответа, были использованы все 3 инструмента, определенные на сервере MCP:

Match 1: {"address1": "1 Meta Way", "city": "Menlo Park", "state": "CA", "zip": "94025", "country": "United States", "phone": "650 543 4800", "website": "https://investor.atmeta.com", "industry": "Internet Content & Information", "industryKey": "internet-content-information", "industryDisp": "Internet Content & Information", "sector": "Communication Services", "sectorKey": "communication-services", "sectorDisp": "Communication Services", "longBusinessSummary": "Meta Platforms, Inc. engages in the development of products that enable people to connect and share with friends and family through mobile devices, personal computers, virtual reality and mixed reality headsets, augmented reality, and wearables worldwide. It operates through two segments, Family of Apps (FoA) and Reality Labs (RL). The FoA segment offers Facebook, which enables people to build community through feed, reels, stories, groups, marketplace, and other; Instagram that brings people closer through instagram feed, stories, reels, live, and messaging; Messenger, a messaging application for people to connect with friends, family, communities, and businesses across platforms and devices through text, audio, and video calls; Threads, an application for text-based updates and public conversations; and WhatsApp, a messaging application that is used by people and businesses to communicate and transact in a private way. The RL segment provides virtual, augmented, and mixed reality related products comprising consumer hardware, software, and content that help people feel connected, anytime, and anywhere. The company was formerly known as Facebook, Inc. and changed its name to Meta Platforms, Inc. in October 2021. The company was incorporated in 2004 and is headquartered in Menlo Park, California.", "fullTimeEmployees": 76834, "companyOfficers": [{"maxAge": 1, "name": "Mr. Mark Elliot Zuckerberg", "age": 40, "title": "Founder, Chairman & CEO", "yearBorn": 1984, "fiscalYear": 2024, "totalPay": 27219874, "exercisedValue": 0, "unexercisedValue": 0}, {"maxAge": 1, "name": "Ms. Susan J. S. Li", "age": 38, "title": "Chief Financial Officer", "yearBorn": 1986, "fiscalYear": 2024, "totalPay": 1948846, "exercisedValue": 0, "unexercisedValue": 0}, {"maxAge": 1, "name": "Mr. Javier Olivan", "age": 47, "title": "Chief Operating Officer", "yearBorn": 1977, "fiscalYear": 2024, "totalPay": 3835042, "exercisedValue": 0, "unexercisedValue": 0}, {"maxAge": 1, "name": "Mr. Andrew Bosworth", "age": 42, "title": "Chief Technology Officer", "yearBorn": 1982, "fiscalYear": 2024, "totalPay": 1923184, "exercisedValue": 0, "unexercisedValue": 0}, {"maxAge": 1, "name": "Mr. Christopher K. Cox", "age": 41, "title": "Chief Product Officer", "yearBorn": 1983, "fiscalYear": 2024, "totalPay": 1937677, "exercisedValue": 0, "unexercisedValue": 0}, {"maxAge": 1, "name": "Mr. Dana White", "title": "Independent Director", "fiscalYear": 2024, "totalPay": 272, "exercisedValue": 0, "unexercisedValue": 0}, {"maxAge": 1, "name": "Mr. Aaron A. Anderson", "title": "Chief Accounting Officer", "fiscalYear": 2024, "exercisedValue": 0, "unexercisedValue": 0}, {"maxAge": 1, "name": "Mr. Atish Banerjea", "age": 58, "title": "Chief Information Officer", "yearBorn": 1966, "fiscalYear": 2024, "exercisedValue": 0, "unexercisedValue": 0}, {"maxAge": 1, "name": "Ms. Jennifer G. Newstead J.D.", "age": 53, "title": "Chief Legal Officer", "yearBorn": 1971, "fiscalYear": 2024, "totalPay": 3079624, "exercisedValue": 0, "unexercisedValue": 0}, {"maxAge": 1, "name": "Mr. Henry T. A. Moniz", "age": 59, "title": "Chief Compliance Officer", "yearBorn": 1965, "fiscalYear": 2024, "exercisedValue": 0, "unexercisedValue": 0}], "auditRisk": 10, "boardRisk": 10, "compensationRisk": 10, "shareHolderRightsRisk": 10, "overallRisk": 10, "governanceEpochDate": 1746057600, "compensationAsOfEpochDate": 1735603200, "executiveTeam": [], "maxAge": 86400, "priceHint": 2, "previousClose": 599.27, "open": 592.525, "dayLow": 586.58, "dayHigh": 596.0, "regularMarketPreviousClose": 599.27, "regularMarketOpen": 592.525, "regularMarketDayLow": 586.58, "regularMarketDayHigh": 596.0, "dividendRate": 2.1, "dividendYield": 0.36, "exDividendDate": 1741910400, "payoutRatio": 0.0792, "beta": 1.237, "trailingPE": 22.932838, "forwardPE": 23.213835, "volume": 10332250, "regularMarketVolume": 10332250, "averageVolume": 18515718, "averageVolume10days": 18570790, "averageDailyVolume10Day": 18570790, "bid": 586.18, "ask": 588.22, "bidSize": 1, "askSize": 1, "marketCap": 1506761506816, "fiftyTwoWeekLow": 442.65, "fiftyTwoWeekHigh": 740.91, "priceToSalesTrailing12Months": 8.844573, "fiftyDayAverage": 580.1932, "twoHundredDayAverage": 580.8713, "trailingAnnualDividendRate": 2.025, "trailingAnnualDividendYield": 0.0033791114, "currency": "USD", "tradeable": false, "enterpriseValue": 1455978577920, "profitMargins": 0.39113998, "floatShares": 2166796937, "sharesOutstanding": 2181270016, "sharesShort": 31512402, "sharesShortPriorMonth": 24545066, "sharesShortPreviousMonthDate": 1741910400, "dateShortInterest": 1744675200, "sharesPercentSharesOut": 0.0125, "heldPercentInsiders": 0.00089, "heldPercentInstitutions": 0.80194, "shortRatio": 1.45, "shortPercentOfFloat": 0.0145000005, "impliedSharesOutstanding": 2565530112, "bookValue": 73.337, "priceToBook": 8.008372, "lastFiscalYearEnd": 1735603200, "nextFiscalYearEnd": 1767139200, "mostRecentQuarter": 1743379200, "earningsQuarterlyGrowth": 0.346, "netIncomeToCommon": 66635001856, "trailingEps": 25.61, "forwardEps": 25.3, "enterpriseToRevenue": 8.546, "enterpriseToEbitda": 16.549, "52WeekChange": 0.24272108, "SandP52WeekChange": 0.08081472, "lastDividendValue": 0.525, "lastDividendDate": 1741910400, "quoteType": "EQUITY", "currentPrice": 587.31, "targetHighPrice": 935.0, "targetLowPrice": 466.0, "targetMeanPrice": 703.8915, "targetMedianPrice": 690.0, "recommendationMean": 1.45588, "recommendationKey": "strong_buy", "numberOfAnalystOpinions": 62, "totalCash": 70229999616, "totalCashPerShare": 27.932, "ebitda": 87979999232, "totalDebt": 49519001600, "quickRatio": 2.501, "currentRatio": 2.662, "totalRevenue": 170359996416, "debtToEquity": 26.763, "revenuePerShare": 67.349, "returnOnAssets": 0.17879999, "returnOnEquity": 0.39835, "grossProfits": 139297996800, "freeCashflow": 36658999296, "operatingCashflow": 96108003328, "earningsGrowth": 0.365, "revenueGrowth": 0.161, "grossMargins": 0.81767, "ebitdaMargins": 0.51644003, "operatingMargins": 0.41487, "financialCurrency": "USD", "symbol": "META", "language": "en-US", "region": "US", "typeDisp": "Equity", "quoteSourceName": "Nasdaq Real Time Price", "triggerable": true, "customPriceAlertConfidence": "HIGH", "longName": "Meta Platforms, Inc.", "exchange": "NMS", "messageBoardId": "finmb_20765463", "exchangeTimezoneName": "America/New_York", "exchangeTimezoneShortName": "EDT", "gmtOffSetMilliseconds": -14400000, "market": "us_market", "esgPopulated": false, "regularMarketChangePercent": -1.9957651, "regularMarketPrice": 587.31, "shortName": "Meta Platforms, Inc.", "hasPrePostMarketData": true, "firstTradeDateMilliseconds": 1337347800000, "postMarketChangePercent": 0.929666, "postMarketPrice": 592.77, "postMarketChange": 5.46002, "regularMarketChange": -11.960022, "regularMarketDayRange": "586.58 - 596.0", "fullExchangeName": "NasdaqGS", "averageDailyVolume3Month": 18515718, "fiftyTwoWeekLowChange": 144.66, "fiftyTwoWeekLowChangePercent": 0.3268045, "fiftyTwoWeekRange": "442.65 - 740.91", "fiftyTwoWeekHighChange": -153.59998, "fiftyTwoWeekHighChangePercent": -0.2073126, "fiftyTwoWeekChangePercent": 24.272108, "dividendDate": 1742947200, "earningsTimestamp": 1746043503, "earningsTimestampStart": 1753786740, "earningsTimestampEnd": 1754308800, "earningsCallTimestampStart": 1746046800, "earningsCallTimestampEnd": 1746046800, "isEarningsDateEstimate": true, "epsTrailingTwelveMonths": 25.61, "epsForward": 25.3, "epsCurrentYear": 25.53311, "priceEpsCurrentYear": 23.001898, "fiftyDayAverageChange": 7.1168213, "fiftyDayAverageChangePercent": 0.012266296, "twoHundredDayAverageChange": 6.4387207, "twoHundredDayAverageChangePercent": 0.011084591, "sourceInterval": 15, "exchangeDataDelayedBy": 0, "ipoExpectedDate": "2022-06-09", "averageAnalystRating": "1.5 - Strong Buy", "cryptoTradeable": false, "marketState": "PREPRE", "corporateActions": [], "postMarketTime": 1746575989, "regularMarketTime": 1746561600, "displayName": "Meta Platforms", "trailingPegRatio": 1.9916} Match 2: Tax Effect Of Unusual Items ... Operating Revenue 2025-03-31 21935371.559134 ... 41804000000.0 2024-12-31 -44365234.375 ... 47866000000.0 2024-09-30 1320000.0 ... 40155000000.0 2024-06-30 -18480000.0 ... 38682000000.0 2024-03-31 -18929140.520341 ... 36075000000.0 [5 rows x 45 columns] Match 3: Tax Effect Of Unusual Items ... Operating Revenue 2024-12-31 -81420000.0 ... 162779000000.0 2023-12-31 -64416000.0 ... 133844000000.0 2022-12-31 -15795000.0 ... 115801000000.0 2021-12-31 -23380000.0 ... 117208000000.0 2020-12-31 NaN ... NaN [5 rows x 48 columns]
-
security - not tested
F
license - not found
-
quality - not tested

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Сервер Model Context Protocol, созданный с помощью FastMCP, который предоставляет инструменты обработки финансовых данных для агентов ИИ, позволяя им получать доступ к информации о фондовом рынке от Yahoo Finance и анализировать ее с помощью запросов на естественном языке.

  1. Требуемый ключ API для этого примера
    1. Запустите этот пример
      1. Примеры результатов

        Related MCP Servers

        • -
          security
          A
          license
          -
          quality
          A Model Context Protocol server providing real-time stock data and options analysis through Yahoo Finance, enabling LLMs to access market data, analyze stocks, and evaluate options strategies.
          Last updated -
          4
          Python
          MIT License
        • A
          security
          A
          license
          A
          quality
          A Model Context Protocol server that enables interaction with Yahoo Finance to retrieve stock pricing, company information, and historical financial data through natural language queries.
          Last updated -
          9
          2
          Python
          MIT License
        • -
          security
          -
          license
          -
          quality
          A Model Context Protocol server that provides tools for interacting with Yahoo Finance, allowing users to retrieve stock prices, company information, and perform financial data comparisons.
          Last updated -
          Python
          MIT License
        • -
          security
          A
          license
          -
          quality
          A demonstration server for the Model Context Protocol (MCP) that exposes calculator and Yahoo Finance tools, allowing LLMs to interpret natural language requests and make tool calls via the MCP standard.
          Last updated -
          Python
          Apache 2.0
          • Linux

        View all related MCP servers

        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/botextractai/ai-mcp-server-client-fastmcp'

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