本页面为机器翻译。英文版本为原文,可能更准确或更及时。 查看英文版

MCP 服务器:开发者集成

本指南介绍如何在您自己的代码中调用 finlight MCP 服务器。您可以用它构建 AI 应用、自动获取新闻,或把金融新闻接入自己的系统。


INFO端点

服务器信息

环境URL
生产环境https://mcp.finlight.me

该服务器实现了 MCP(模型上下文协议),通过 HTTP 使用 JSON-RPC 2.0。


AUTHAPI 密钥

认证

发往 MCP 端点的每个请求都需要您的 API 密钥,initialize 和 tools/list 也不例外。请以 Bearer 令牌的形式发送:

Authorization: Bearer YOUR_API_KEY

您也可以在 x-api-key 请求头中发送它,例如从没有浏览器的服务器或容器中发送:

x-api-key: YOUR_API_KEY

对于使用 OAuth 的客户端(例如 Claude Desktop),服务器实现了带 PKCE 的 OAuth 2.0。请参阅 OAuth 流程。


QUICKSTART示例

快速开始

使用 cURL

列出可用的工具:

curl -X POST https://mcp.finlight.me \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/list"
  }'

搜索 NVIDIA 的财报新闻:

curl -X POST https://mcp.finlight.me \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/call",
    "params": {
      "name": "search_articles",
      "arguments": {
        "tickers": ["NVDA"],
        "eventTypes": ["earnings"],
        "limit": 10
      }
    }
  }'

使用 TypeScript

import { Client } from '@modelcontextprotocol/sdk/client/index.js'
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'

const transport = new StreamableHTTPClientTransport(new URL('https://mcp.finlight.me'), {
  requestInit: {
    headers: {
      Authorization: `Bearer ${process.env.FINLIGHT_API_KEY}`,
    },
  },
})

const client = new Client({
  name: 'my-app',
  version: '1.0.0',
})

await client.connect(transport)

// List the available tools
const tools = await client.listTools()
console.log('Available tools:', tools)

// Search articles
const result = await client.callTool({
  name: 'search_articles',
  arguments: {
    query: 'Federal Reserve interest rates',
    from: '2026-11-01',
    limit: 5,
  },
})

// The tool answers with one text item that holds JSON
const [item] = result.content as { type: 'text'; text: string }[]
const page = JSON.parse(item.text)
console.log('Articles:', page.articles)

使用 Python

import json
import os

import requests

API_KEY = os.environ["FINLIGHT_API_KEY"]
MCP_URL = "https://mcp.finlight.me"


def mcp_request(method: str, params: dict | None = None):
    response = requests.post(
        MCP_URL,
        headers={
            "Content-Type": "application/json",
            "Authorization": f"Bearer {API_KEY}",
        },
        json={
            "jsonrpc": "2.0",
            "id": 1,
            "method": method,
            "params": params or {},
        },
    )
    return response.json()


# List the available tools
tools = mcp_request("tools/list")
print("Available tools:", json.dumps(tools, indent=2))

# Search articles
answer = mcp_request("tools/call", {
    "name": "search_articles",
    "arguments": {
        "tickers": ["TSLA"],
        "from": "2026-11-01",
        "include": ["companies", "events"],
        "limit": 10,
    },
})
page = json.loads(answer["result"]["content"][0]["text"])
for article in page["articles"]:
    print(article["publishedAt"], article["title"])

TOOLS参考

可用工具

服务器有五个工具。每个工具都会用您的密钥向 finlight API 发送一个请求。

工具作用API 请求
search_articles用查询和过滤条件搜索文章POST /v3/articles/search
get_article按 finlight id 获取一篇文章GET /v3/articles/{id}
get_article_by_link按 URL 获取一篇文章GET /v3/articles/by-link
search_companies按股票代码、名称或 ISIN 查找公司GET /v3/companies
list_sources列出所有新闻来源GET /v3/sources

每个工具都用一个文本项作答。文本是包含 API 请求数据的 JSON。下面各节展示每个工具的返回结构。

search_articles

搜索金融新闻文章。字段与搜索文章相同,该页面也说明了过滤条件如何组合。所有字段都是可选的。

参数:

参数类型说明
querystring使用查询语法的查询:AND、OR、NOT、括号、短语,以及 {ticker:NVDA AND eventType:earnings} 这样的字段。花括号把条件绑定到同一家公司或同一个事件,例如 {ticker:TSLA AND role:defendant}。
tickersstring[]关于这些公司的文章,例如 ["AAPL", "NVDA"]。000660.KS 这样的数据商写法也可以使用。请参阅股票代码与交易所。
sourcesstring[]只使用这些来源域名,例如 ["www.reuters.com"]
optInSourcesstring[]把这些来源加入您的默认来源
excludeSourcesstring[]排除这些来源
sourceTypesstring[]只使用这些来源类型,例如 newswire 或 press_release
excludeSourceTypesstring[]排除这些来源类型
fromstring日期范围的起点(YYYY-MM-DD 或 ISO 8601)。作用于 orderBy 的时间戳。
tostring日期范围的终点(YYYY-MM-DD 或 ISO 8601)
languagesstring[]ISO 639-1 代码。默认 ["en"]。
countriesstring[]报道所涉及的国家,大写的 ISO 3166-1 alpha-2(US)
categoriesstring[]文章分类,例如 markets 或 technology
rolesstring[]被标记公司的角色,例如 acquirer、target 或 defendant
minRelevancenumber被标记公司的最低相关度,范围为 0 到 1
eventTypesstring[]事件类型,例如 earnings、mna 或 guidance
eventDirectionsstring[]positive、negative、neutral、unclear
minImportancestringlow、medium、high 或 critical
sectorsstring[]被标记公司的行业板块,例如 Technology
companyCountriesstring[]被标记公司所在的国家,ISO 3166-1 alpha-2
exchangesstring[]被标记公司主要上市地所在的交易所,使用 MIC(XNAS)
orderBystringpublishedAt(默认)、firstSeenAt、revisedAt 或 availableAt
orderstringdesc(默认,最新的在前)或 asc
limitnumber每页文章数,1 到 100。默认 20。
cursorstring上一个结果中的 pagination.nextCursor,用于获取下一页
includestring[]每篇文章的额外数据块:companies、events

请求示例: AMD 作为收购方的并购新闻。

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "search_articles",
    "arguments": {
      "tickers": ["AMD"],
      "roles": ["acquirer"],
      "eventTypes": ["mna"],
      "from": "2026-09-01",
      "include": ["companies", "events"],
      "limit": 5
    }
  }
}

响应示例: 工具返回一个包含 JSON 的文本项:

{
  "jsonrpc": "2.0",
  "result": {
    "content": [{
      "type": "text",
      "text": "{\"articles\":[{\"id\":\"pXhK9f2aQ1mZ0bT7cY3rLw\",\"title\":\"AMD to buy ZT Systems\", ...}],\"pagination\":{...}}"
    }]
  },
  "id": 1
}

文本经过格式化和缩短后如下:

{
  "articles": [
    {
      "id": "pXhK9f2aQ1mZ0bT7cY3rLw",
      "link": "https://www.reuters.com/markets/amd-zt-systems",
      "source": { "domain": "www.reuters.com", "type": "newswire" },
      "title": "AMD to buy ZT Systems",
      "summary": "AMD agreed to buy server maker ZT Systems ...",
      "language": "en",
      "publishedAt": "2026-09-18T12:01:03.000Z",
      "firstSeenAt": "2026-09-18T12:01:41.000Z",
      "availableAt": "2026-09-18T12:03:05.000Z",
      "countries": ["US"],
      "categories": ["markets"],
      "sentiment": { "label": "positive", "confidence": 0.98 },
      "companies": [
        {
          "companyId": 13,
          "name": "Advanced Micro Devices, Inc.",
          "primaryListing": { "ticker": "AMD", "mic": "XNAS", "country": "US" },
          "role": "acquirer",
          "relevance": 0.95
        },
        {
          "companyId": 90412,
          "name": "ZT Systems",
          "primaryListing": null,
          "role": "target",
          "relevance": 0.9
        }
      ],
      "events": [
        { "type": "mna", "direction": "positive", "importance": "high", "confidence": 0.9, "companyIds": [13, 90412] }
      ]
    }
  ],
  "pagination": { "limit": 5, "returned": 1, "hasMore": false, "nextCursor": null }
}

文章的每个字段都在文章对象中有说明。sentiment、companies 和 events 取决于您的套餐,请参阅套餐与权益。

下一页: 用相同的参数再次调用 search_articles,并把 cursor 设为 pagination.nextCursor。在最后一页,nextCursor 为 null。请参阅分页。


get_article

按 finlight id 获取一篇文章,即搜索结果中的 id 字段。可用它为某条搜索结果加载更多数据块。

对于较早的文章,按 id 查询可能返回 not_found。这时请用该搜索结果的 link 调用 get_article_by_link。按链接查询可以找到每一篇文章。

参数:

参数类型必填说明
idstring是文章 id,22 个字符
includestring[]否额外数据块:companies、events

请求示例:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "get_article",
    "arguments": {
      "id": "pXhK9f2aQ1mZ0bT7cY3rLw",
      "include": ["events", "companies"]
    }
  }
}

响应的文本就是文章对象。


get_article_by_link

按 URL 获取一篇文章。

参数:

参数类型必填说明
linkstring是文章的完整 URL
includestring[]否额外数据块:companies、events

请求示例:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "get_article_by_link",
    "arguments": {
      "link": "https://www.reuters.com/technology/example-article",
      "include": ["companies"]
    }
  }
}

响应的文本就是文章对象。


search_companies

按股票代码、名称、ISIN 或数据商写法在 finlight 的公司数据中查找公司,例如 NVDA、Samsung Electronics、US0079031078、000660.KS 或 XNAS:AMD。之后助手可以在查询中使用 companyId:<id> 搜索文章。需要包含公司数据的套餐。

参数:

参数类型必填说明
qstring是股票代码、名称、ISIN 或数据商写法,最多 200 个字符
micstring否只保留在该交易所上市的公司,使用 MIC(XNAS)或别名(NASDAQ)

请求示例:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "search_companies",
    "arguments": {
      "q": "000660.KS"
    }
  }
}

响应的文本是 {"companies": [...]},最多包含 10 家公司,最匹配的排在最前。每家公司都有 companyId、name、country、sector、industry、isins、primaryListing、listings 和 updatedAt。请参阅公司记录。


list_sources

获取您可以使用的所有新闻来源。

参数: 无

请求示例:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "list_sources",
    "arguments": {}
  }
}

响应的文本是一个来源的 JSON 数组。每个来源包含:

  • domain:来源的域名,是 sources、optInSources 和 excludeSources 使用的值
  • name:显示名称
  • type:来源类型,是 sourceTypes 和 excludeSourceTypes 使用的值
  • isDefault:不指定名称时是否也会搜索该来源
  • isCustom:是否为向您开放的自定义来源
  • country 和 languages

isDefault: false 的来源可通过 optInSources 加入搜索。请参阅来源。


PROTOCOLJSON-RPC

MCP 协议方法

服务器实现了以下 MCP 方法:

方法说明
initialize开始 MCP 会话
notifications/initialized确认初始化已完成
tools/list列出可用工具及其 schema
tools/call带参数运行一个工具
ping健康检查

初始化示例:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "initialize",
  "params": {
    "protocolVersion": "2024-11-05",
    "capabilities": {},
    "clientInfo": {
      "name": "my-client",
      "version": "1.0.0"
    }
  }
}

响应:

{
  "jsonrpc": "2.0",
  "result": {
    "protocolVersion": "2024-11-05",
    "capabilities": {
      "tools": {}
    },
    "serverInfo": {
      "name": "finlight-news-api",
      "version": "2.0.0"
    }
  },
  "id": 1
}

OAUTH认证

OAuth 流程

对于支持 OAuth 的客户端(例如 Claude Desktop),服务器实现了带 PKCE 的 OAuth 2.0。

端点

端点方法说明
/.well-known/oauth-protected-resourceGET受保护资源的元数据
/.well-known/oauth-authorization-serverGET授权服务器的元数据
/registerPOST动态客户端注册
/authorizeGET授权页面
/authorize/submitPOST处理授权
/tokenPOST用授权码换取令牌

流程概览

1. The client finds the OAuth endpoints through .well-known
2. The client can register through /register
3. The client sends the user to /authorize with a PKCE challenge
4. The user enters an API key and submits
5. The server redirects back with an authorization code
6. The client exchanges code + verifier for an access token
7. The client uses the access token as Bearer token for tool calls

安全特性

  • 必须使用 PKCE: 防止授权码被截获
  • 加密的授权码: 授权码经过加密(AES-256-GCM),因此服务器不保存状态
  • 短时有效的授权码: 授权码在 120 秒后过期
  • 重定向 URI 检查: 授权码只能配合签发时的重定向 URI 使用

ERRORS故障排除

错误处理

工具错误

当工具调用因助手可以修正的原因失败时,响应是带有 isError: true 的普通工具结果。其文本是 JSON,并且总是包含 error。来自 API 的错误还会加上 status 和 message,如果个别字段有误,还会加上 issues。助手会读取原因并调整调用,例如修正参数或去掉某个过滤条件。

{
  "jsonrpc": "2.0",
  "result": {
    "isError": true,
    "content": [{
      "type": "text",
      "text": "{\"error\":\"forbidden\",\"status\":403,\"message\":\"Company master data requires the entityAccess entitlement.\"}"
    }]
  },
  "id": 1
}
errorstatus何时出现
invalid_arguments无工具不认识的参数、类型错误的值,或超出范围的值(limit 1 到 100,minRelevance 0 到 1,空的 id、link 或 q,超过 200 个字符的 q)。只包含 error 和 issues;issues 会指出是哪个参数。服务器在调用 API 之前就会作答,因此不消耗额度。
validation无在发送请求之前检查的值,例如空的 languages 列表、空的 cursor 或超过 3 个 include 值。在调用 API 之前作答。
validation_failed400API 拒绝了某个值,例如 query 中的未知字段。issues 会指出是哪个字段。
cursor_invalid400cursor 不是本 API 的游标
cursor_mismatch400翻页之间排序或过滤条件发生了变化。limit 和 include 可以改变。
unauthorized401API 密钥错误或已被删除
forbidden403您的套餐不包含此项,例如在没有公司数据的情况下调用 search_companies
not_found404没有该 id 或链接对应的文章,或文章不在您套餐的日期范围内。对于较早的文章,请使用 get_article_by_link。
rate_limited429达到突发限制或每月额度
internal_error500我们这边出了问题
timeout、network无API 未能及时响应。请再次调用。

status 的取值及其原因与 REST API 相同,请参阅错误。

您的套餐不包含的数据块(例如 companies 或 events)会从文章中省略,不会报错。请参阅套餐与权益。

JSON-RPC 错误代码

代码何时出现
-32700请求体不是有效的 JSON
-32600jsonrpc 不是 "2.0",或缺少 method
-32601未知方法
-32602tools/call 没有工具名称,或工具名称未知
-32001没有 API 密钥。没有密钥时,服务器以 HTTP 401 响应,并指向 OAuth 元数据。
-32603意外故障。message 说明原因。

空的请求体会得到 HTTP 400 和 {"error":"Request body is required"},而不是 JSON-RPC 错误。

{
  "jsonrpc": "2.0",
  "error": {
    "code": -32602,
    "message": "Unknown tool: search_news"
  },
  "id": 1
}

LIMITS配额

速率限制

每次工具调用都是一次使用您密钥的 API 请求,因此适用与 API 相同的限制。search_articles、get_article、get_article_by_link、search_companies 和 list_sources 每次调用消耗 1 个额度。搜索的每个后续页面也消耗 1 个额度。如果助手在搜索前先查找公司,这个问题就会消耗 2 个额度。

以 API 错误结束的调用同样消耗 1 个额度,与 API 一致。例外情况(例如密钥错误)列在速率限制与额度中。达到限制时,工具会以 rate_limited 和状态 429 作答。

请在 app.finlight.me 查看您的用量和限制。


SUPPORT帮助

支持