> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fcontext.com/llms.txt
> Use this file to discover all available pages before exploring further.

# MCP Server

> 透過 OAuth 2.1 將 AI assistant 連接到 fcontext 市場資料

存取官方遠端 MCP server，使用 fcontext 市場資料。

## 概覽

你的 AI assistant 可以透過 fcontext MCP server，使用你的 fcontext 帳戶存取已認證、按量計費的市場資料。第一個版本提供即時行情、證券靜態資料、計算指標、K 線、市場新聞、財務日曆和熱門異動等工具。

遠端 MCP endpoint：

```text theme={null}
https://mcp.fcontext.com/mcp
```

## 認證

MCP server 使用 OAuth 2.1。互動式 MCP 用戶端首次連線時，它會重新導向你登入並核准市場資料存取。MCP 用戶端不需要 API key。

授權伺服器：

```text theme={null}
https://openapi.fcontext.com/api/auth
```

MCP access token 是綁定到 MCP resource audience 的 JWT：

```text theme={null}
https://mcp.fcontext.com/mcp
```

Token 必須包含 `market_data` scope。

<Note>
  API key 用於 `https://openapi.fcontext.com/api/market-data` 的 HTTP Market Data API。MCP 用戶端應使用 OAuth，除非你正在建構自己的伺服器端整合。
</Note>

## 開始使用

選擇支援遠端 MCP server 的用戶端，並新增 fcontext endpoint：

<Tabs>
  <Tab title="Codex Desktop">
    新增一個遠端 MCP server，URL 為：

    ```text theme={null}
    https://mcp.fcontext.com/mcp
    ```

    當 Codex 提示時完成 OAuth 登入，然後在需要市場資料的聊天中啟用該 server。
  </Tab>

  <Tab title="Claude / Claude Code">
    新增一個自訂遠端 MCP connector，URL 為：

    ```text theme={null}
    https://mcp.fcontext.com/mcp
    ```

    在用戶端開啟的瀏覽器視窗中完成 OAuth 認證。
  </Tab>

  <Tab title="Cursor">
    新增一個遠端 MCP server，URL 為：

    ```text theme={null}
    https://mcp.fcontext.com/mcp
    ```

    當 Cursor 要求授權時，使用你的 fcontext 帳戶登入，並核准市場資料存取。
  </Tab>
</Tabs>

## MCP 工具

連線後，你的 AI assistant 可以呼叫這些工具：

| 工具                          | 描述                                                         |
| --------------------------- | ---------------------------------------------------------- |
| `fcontext_get`              | 在 `/api/market-data` 之後透過相對路徑呼叫允許的 fcontext 市場資料 `GET` 介面。 |
| `fcontext_quote`            | 取得一個或多個標的的即時行情。                                            |
| `fcontext_static_info`      | 取得證券靜態資訊。                                                  |
| `fcontext_calc_index`       | 取得計算類行情指標。                                                 |
| `fcontext_candlestick`      | 取得某個標的的歷史 K 線資料。                                           |
| `fcontext_news`             | 取得市場新聞。                                                    |
| `fcontext_finance_calendar` | 取得財務日曆事件。                                                  |
| `fcontext_top_movers`       | 取得熱門市場異動。                                                  |

工具呼叫會使用你的 fcontext 帳戶完成存取、計費和用量分析，與 HTTP Market Data API 保持一致。

## 使用範例

連線後，可以試著向 AI assistant 提問：

* “What is Apple’s latest quote?”
* “Show me one month of daily candlesticks for Nvidia.”
* “What are today’s top US market movers?”
* “Find recent news for Tesla.”
* “Check upcoming finance calendar events for this week.”
* “Compare static information for AAPL.US and MSFT.US.”

## 疑難排解

| 問題             | 檢查項目                                                                                                                                                                     |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 用戶端無法發現授權中繼資料  | 確認它可以存取 `https://openapi.fcontext.com/api/auth/.well-known/oauth-authorization-server` 或 `https://openapi.fcontext.com/.well-known/oauth-authorization-server/api/auth`。 |
| MCP 請求回傳 `401` | 重新連接 MCP server，並再次完成 OAuth。回應會包含帶有 protected resource metadata URL 的 `WWW-Authenticate`。                                                                                |
| MCP 請求回傳 `403` | Token 有效，但不包含 `market_data` scope。請重新授權用戶端。                                                                                                                              |
| 工具呼叫因路徑錯誤失敗    | 使用 `fcontext_get` 時請使用相對路徑，例如 `quote` 或 `content/news`；絕對 URL 和路徑穿越會被拒絕。                                                                                                 |
