langchain-feedmcp 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,24 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+ workflow_dispatch:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ build-and-publish:
13
+ runs-on: ubuntu-latest
14
+ permissions:
15
+ id-token: write
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ - uses: astral-sh/setup-uv@v5
19
+ - name: Run unit tests
20
+ run: uv run --with "langchain-core>=0.3.0,<2.0.0" --with "httpx>=0.27,<1.0" python -m unittest discover -s tests -v
21
+ - name: Build distribution
22
+ run: uv build
23
+ - name: Publish to PyPI via Trusted Publishing
24
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,6 @@
1
+ __pycache__/
2
+ *.pyc
3
+ .venv/
4
+ dist/
5
+ *.egg-info/
6
+ .DS_Store
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 FeedMCP
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,95 @@
1
+ Metadata-Version: 2.5
2
+ Name: langchain-feedmcp
3
+ Version: 0.1.0
4
+ Summary: LangChain & LangGraph tools for FeedMCP: public social media, creator marketing, ad library, and search trend data across 21 global and Chinese platforms (193 endpoints).
5
+ Project-URL: Homepage, https://feedmcp.com/?utm_source=langchain
6
+ Project-URL: Documentation, https://feedmcp.com/docs/?utm_source=langchain
7
+ Project-URL: Repository, https://github.com/FeedMCP/langchain-feedmcp
8
+ Project-URL: Issues, https://github.com/FeedMCP/langchain-feedmcp/issues
9
+ Author-email: FeedMCP <support@feedmcp.com>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: ai-agents,bilibili,douyin,feedmcp,langchain,langgraph,reddit,rednote,social-media-api,tiktok,toolkit,tools,twitter,wechat,weibo,xiaohongshu,youtube,zhihu
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Software Development :: Libraries
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: <4.0,>=3.10
22
+ Requires-Dist: httpx<1.0,>=0.27
23
+ Requires-Dist: langchain-core<2.0.0,>=0.3.0
24
+ Description-Content-Type: text/markdown
25
+
26
+ # langchain-feedmcp
27
+
28
+ **LangChain 与 LangGraph 的 FeedMCP 官方工具包:让 Python Agent 用统一接口读取小红书(含蒲公英)、抖音(含星图与巨量算数)、微信公众号/视频号/搜一搜、微博、B站、知乎、快手及 TikTok、YouTube、X、Instagram、Reddit、LinkedIn 等 21 个平台 193 个公开数据接口。**
29
+
30
+ > [官网中文文档](https://feedmcp.com/zh/?utm_source=langchain) · [获取 API Key(送 $0.10 试用额度)](https://feedmcp.com/console/keys/?utm_source=langchain) · [FeedMCP 主仓库](https://github.com/FeedMCP/feedmcp)
31
+
32
+ ---
33
+
34
+ ## 安装
35
+
36
+ ```bash
37
+ pip install langchain-feedmcp
38
+ # 或从 GitHub 安装
39
+ pip install git+https://github.com/FeedMCP/langchain-feedmcp.git
40
+ ```
41
+
42
+ ---
43
+
44
+ ## 快速上手
45
+
46
+ ```python
47
+ import os
48
+ from langchain_feedmcp import FeedMCPToolkit
49
+
50
+ toolkit = FeedMCPToolkit(
51
+ api_key=os.environ.get("FEEDMCP_API_KEY"), # find / describe 免 Key 免费
52
+ default_max_price=0.05, # 可选:单次调用价格上限保护 (X-Max-Price)
53
+ )
54
+ tools = toolkit.get_tools()
55
+ # [FeedMCPFindTool, FeedMCPDescribeTool, FeedMCPCallTool, FeedMCPAccountTool]
56
+ ```
57
+
58
+ ### 配合 LangGraph / LangChain Agent 使用
59
+
60
+ ```python
61
+ from langchain_openai import ChatOpenAI
62
+ from langgraph.prebuilt import create_react_agent
63
+ from langchain_feedmcp import FeedMCPToolkit
64
+
65
+ llm = ChatOpenAI(model="gpt-4o-mini")
66
+ tools = FeedMCPToolkit(default_max_price=0.05).get_tools()
67
+ agent = create_react_agent(llm, tools)
68
+
69
+ result = agent.invoke({
70
+ "messages": [("user", "帮我找小红书上关于露营装备的高赞笔记,先查接口单价再拉取第一页")]
71
+ })
72
+ ```
73
+
74
+ ---
75
+
76
+ ## 内置工具
77
+
78
+ | 工具名 | 鉴权 | 费用 | 说明 |
79
+ | --- | --- | --- | --- |
80
+ | `feedmcp_find` | 免 Key | 免费 | 自然语言搜索匹配的 193 个接口与单价 |
81
+ | `feedmcp_describe` | 免 Key | 免费 | 查看指定接口的必填参数、枚举值与精确单价 |
82
+ | `feedmcp_call` | API Key | 按次计费($0.0003 起,失败免费) | 执行单页数据查询,内置 `X-Max-Price` 与 `Idempotency-Key` |
83
+ | `feedmcp_account` | API Key | 免费 | 查询当前账户 USD 余额与近 24 小时用量 |
84
+
85
+ ---
86
+
87
+ ## 测试
88
+
89
+ ```bash
90
+ uv run --with langchain-core --with httpx python -m unittest discover -s tests -v
91
+ ```
92
+
93
+ ## License
94
+
95
+ MIT
@@ -0,0 +1,70 @@
1
+ # langchain-feedmcp
2
+
3
+ **LangChain 与 LangGraph 的 FeedMCP 官方工具包:让 Python Agent 用统一接口读取小红书(含蒲公英)、抖音(含星图与巨量算数)、微信公众号/视频号/搜一搜、微博、B站、知乎、快手及 TikTok、YouTube、X、Instagram、Reddit、LinkedIn 等 21 个平台 193 个公开数据接口。**
4
+
5
+ > [官网中文文档](https://feedmcp.com/zh/?utm_source=langchain) · [获取 API Key(送 $0.10 试用额度)](https://feedmcp.com/console/keys/?utm_source=langchain) · [FeedMCP 主仓库](https://github.com/FeedMCP/feedmcp)
6
+
7
+ ---
8
+
9
+ ## 安装
10
+
11
+ ```bash
12
+ pip install langchain-feedmcp
13
+ # 或从 GitHub 安装
14
+ pip install git+https://github.com/FeedMCP/langchain-feedmcp.git
15
+ ```
16
+
17
+ ---
18
+
19
+ ## 快速上手
20
+
21
+ ```python
22
+ import os
23
+ from langchain_feedmcp import FeedMCPToolkit
24
+
25
+ toolkit = FeedMCPToolkit(
26
+ api_key=os.environ.get("FEEDMCP_API_KEY"), # find / describe 免 Key 免费
27
+ default_max_price=0.05, # 可选:单次调用价格上限保护 (X-Max-Price)
28
+ )
29
+ tools = toolkit.get_tools()
30
+ # [FeedMCPFindTool, FeedMCPDescribeTool, FeedMCPCallTool, FeedMCPAccountTool]
31
+ ```
32
+
33
+ ### 配合 LangGraph / LangChain Agent 使用
34
+
35
+ ```python
36
+ from langchain_openai import ChatOpenAI
37
+ from langgraph.prebuilt import create_react_agent
38
+ from langchain_feedmcp import FeedMCPToolkit
39
+
40
+ llm = ChatOpenAI(model="gpt-4o-mini")
41
+ tools = FeedMCPToolkit(default_max_price=0.05).get_tools()
42
+ agent = create_react_agent(llm, tools)
43
+
44
+ result = agent.invoke({
45
+ "messages": [("user", "帮我找小红书上关于露营装备的高赞笔记,先查接口单价再拉取第一页")]
46
+ })
47
+ ```
48
+
49
+ ---
50
+
51
+ ## 内置工具
52
+
53
+ | 工具名 | 鉴权 | 费用 | 说明 |
54
+ | --- | --- | --- | --- |
55
+ | `feedmcp_find` | 免 Key | 免费 | 自然语言搜索匹配的 193 个接口与单价 |
56
+ | `feedmcp_describe` | 免 Key | 免费 | 查看指定接口的必填参数、枚举值与精确单价 |
57
+ | `feedmcp_call` | API Key | 按次计费($0.0003 起,失败免费) | 执行单页数据查询,内置 `X-Max-Price` 与 `Idempotency-Key` |
58
+ | `feedmcp_account` | API Key | 免费 | 查询当前账户 USD 余额与近 24 小时用量 |
59
+
60
+ ---
61
+
62
+ ## 测试
63
+
64
+ ```bash
65
+ uv run --with langchain-core --with httpx python -m unittest discover -s tests -v
66
+ ```
67
+
68
+ ## License
69
+
70
+ MIT
@@ -0,0 +1,26 @@
1
+ """Example: attach FeedMCPToolkit to a LangChain / LangGraph agent."""
2
+
3
+ import json
4
+ import os
5
+ from langchain_feedmcp import FeedMCPToolkit
6
+
7
+
8
+ def main() -> None:
9
+ toolkit = FeedMCPToolkit(
10
+ api_key=os.environ.get("FEEDMCP_API_KEY"),
11
+ default_max_price=0.05, # safety cap per call (USD)
12
+ )
13
+ tools = toolkit.get_tools()
14
+ print("Loaded tools:", [t.name for t in tools])
15
+
16
+ # Free discovery (works without FEEDMCP_API_KEY)
17
+ find_tool = tools[0]
18
+ raw = find_tool.invoke({"query": "xiaohongshu notes"})
19
+ items = json.loads(raw).get("items", [])
20
+ print(f"Matched {len(items)} endpoints; top 3:")
21
+ for item in items[:3]:
22
+ print(f" - {item['id']} (${item['price']}) — {item.get('title_zh') or item.get('title_en')}")
23
+
24
+
25
+ if __name__ == "__main__":
26
+ main()
@@ -0,0 +1,23 @@
1
+ """LangChain & LangGraph integration for FeedMCP."""
2
+
3
+ from langchain_feedmcp._client import FeedMCPClient, FeedMCPError, endpoint_to_path
4
+ from langchain_feedmcp.toolkits import FeedMCPToolkit
5
+ from langchain_feedmcp.tools import (
6
+ FeedMCPAccountTool,
7
+ FeedMCPCallTool,
8
+ FeedMCPDescribeTool,
9
+ FeedMCPFindTool,
10
+ )
11
+
12
+ __all__ = [
13
+ "FeedMCPClient",
14
+ "FeedMCPError",
15
+ "FeedMCPToolkit",
16
+ "FeedMCPFindTool",
17
+ "FeedMCPDescribeTool",
18
+ "FeedMCPCallTool",
19
+ "FeedMCPAccountTool",
20
+ "endpoint_to_path",
21
+ ]
22
+
23
+ __version__ = "0.1.0"
@@ -0,0 +1,214 @@
1
+ """HTTP client for the FeedMCP REST API."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from typing import Any
7
+
8
+ import httpx
9
+
10
+ DEFAULT_BASE_URL = "https://api.feedmcp.com"
11
+ DEFAULT_TIMEOUT = 60.0
12
+
13
+
14
+ class FeedMCPError(RuntimeError):
15
+ """Raised when the FeedMCP API returns an error response."""
16
+
17
+ def __init__(
18
+ self,
19
+ message: str,
20
+ *,
21
+ status_code: int | None = None,
22
+ code: str | None = None,
23
+ details: Any = None,
24
+ ) -> None:
25
+ super().__init__(message)
26
+ self.status_code = status_code
27
+ self.code = code
28
+ self.details = details
29
+
30
+
31
+ def endpoint_to_path(endpoint: str) -> str:
32
+ """Convert a dot-separated FeedMCP endpoint ID into its /v1/... path."""
33
+ cleaned = endpoint.strip().strip("/")
34
+ if not cleaned:
35
+ raise ValueError("endpoint must be a non-empty FeedMCP endpoint ID")
36
+ if cleaned.startswith("v1/"):
37
+ return f"/{cleaned}"
38
+ return "/v1/" + cleaned.replace(".", "/")
39
+
40
+
41
+ class FeedMCPClient:
42
+ """Synchronous and asynchronous HTTP wrapper for FeedMCP."""
43
+
44
+ def __init__(
45
+ self,
46
+ api_key: str | None = None,
47
+ *,
48
+ base_url: str = DEFAULT_BASE_URL,
49
+ timeout: float = DEFAULT_TIMEOUT,
50
+ transport: httpx.BaseTransport | None = None,
51
+ async_transport: httpx.AsyncBaseTransport | None = None,
52
+ ) -> None:
53
+ self.api_key = api_key if api_key is not None else os.environ.get("FEEDMCP_API_KEY", "")
54
+ self.base_url = base_url.rstrip("/")
55
+ self.timeout = timeout
56
+ self._transport = transport
57
+ self._async_transport = async_transport
58
+
59
+ def _headers(
60
+ self,
61
+ *,
62
+ require_auth: bool = False,
63
+ max_price: float | None = None,
64
+ idempotency_key: str | None = None,
65
+ ) -> dict[str, str]:
66
+ headers: dict[str, str] = {
67
+ "Accept": "application/json",
68
+ "User-Agent": "langchain-feedmcp/0.1.0",
69
+ }
70
+ if self.api_key:
71
+ token = self.api_key if self.api_key.startswith("Bearer ") else f"Bearer {self.api_key}"
72
+ headers["Authorization"] = token
73
+ elif require_auth:
74
+ raise FeedMCPError(
75
+ "FEEDMCP_API_KEY is required for this endpoint. "
76
+ "Get a key ($0.10 free trial, no card) at https://feedmcp.com/console/keys/?utm_source=langchain",
77
+ status_code=401,
78
+ code="missing_api_key",
79
+ )
80
+ if max_price is not None:
81
+ headers["X-Max-Price"] = str(max_price)
82
+ if idempotency_key:
83
+ headers["Idempotency-Key"] = idempotency_key
84
+ return headers
85
+
86
+ @staticmethod
87
+ def _parse_response(resp: httpx.Response) -> dict[str, Any]:
88
+ try:
89
+ body = resp.json()
90
+ except Exception:
91
+ body = {"message": resp.text}
92
+
93
+ if resp.is_error:
94
+ err = body.get("error") if isinstance(body, dict) and isinstance(body.get("error"), dict) else body
95
+ code = err.get("code") if isinstance(err, dict) else None
96
+ msg = (
97
+ (err.get("message") if isinstance(err, dict) else None)
98
+ or f"FeedMCP HTTP {resp.status_code}"
99
+ )
100
+ raise FeedMCPError(msg, status_code=resp.status_code, code=code, details=body)
101
+
102
+ return body if isinstance(body, dict) else {"data": body}
103
+
104
+ def _request(
105
+ self,
106
+ path: str,
107
+ *,
108
+ params: dict[str, Any] | None = None,
109
+ require_auth: bool = False,
110
+ max_price: float | None = None,
111
+ idempotency_key: str | None = None,
112
+ ) -> dict[str, Any]:
113
+ clean_params = {k: v for k, v in (params or {}).items() if v is not None}
114
+ headers = self._headers(
115
+ require_auth=require_auth,
116
+ max_price=max_price,
117
+ idempotency_key=idempotency_key,
118
+ )
119
+ with httpx.Client(
120
+ base_url=self.base_url,
121
+ timeout=self.timeout,
122
+ transport=self._transport,
123
+ ) as client:
124
+ resp = client.get(path, params=clean_params, headers=headers)
125
+ return self._parse_response(resp)
126
+
127
+ async def _arequest(
128
+ self,
129
+ path: str,
130
+ *,
131
+ params: dict[str, Any] | None = None,
132
+ require_auth: bool = False,
133
+ max_price: float | None = None,
134
+ idempotency_key: str | None = None,
135
+ ) -> dict[str, Any]:
136
+ clean_params = {k: v for k, v in (params or {}).items() if v is not None}
137
+ headers = self._headers(
138
+ require_auth=require_auth,
139
+ max_price=max_price,
140
+ idempotency_key=idempotency_key,
141
+ )
142
+ async with httpx.AsyncClient(
143
+ base_url=self.base_url,
144
+ timeout=self.timeout,
145
+ transport=self._async_transport,
146
+ ) as client:
147
+ resp = await client.get(path, params=clean_params, headers=headers)
148
+ return self._parse_response(resp)
149
+
150
+ def find(self, query: str) -> dict[str, Any]:
151
+ """Search endpoints and prices by natural language query (free, no key)."""
152
+ return self._request("/v1/catalog/search", params={"q": query})
153
+
154
+ async def afind(self, query: str) -> dict[str, Any]:
155
+ return await self._arequest("/v1/catalog/search", params={"q": query})
156
+
157
+ def describe(self, endpoint: str) -> dict[str, Any]:
158
+ """Inspect parameters, schema, and price for a single endpoint (free, no key)."""
159
+ return self._request(f"/v1/catalog/endpoints/{endpoint.strip()}")
160
+
161
+ async def adescribe(self, endpoint: str) -> dict[str, Any]:
162
+ return await self._arequest(f"/v1/catalog/endpoints/{endpoint.strip()}")
163
+
164
+ def status(self) -> dict[str, Any]:
165
+ """Fetch live platform health status (free, no key)."""
166
+ return self._request("/v1/catalog/status")
167
+
168
+ def account(self) -> dict[str, Any]:
169
+ """Fetch account balance and 24h usage (free, API key required)."""
170
+ return self._request("/v1/me", require_auth=True)
171
+
172
+ async def aaccount(self) -> dict[str, Any]:
173
+ return await self._arequest("/v1/me", require_auth=True)
174
+
175
+ def call(
176
+ self,
177
+ endpoint: str,
178
+ params: dict[str, Any] | None = None,
179
+ *,
180
+ max_price: float | None = None,
181
+ idempotency_key: str | None = None,
182
+ view: str | None = None,
183
+ ) -> dict[str, Any]:
184
+ """Call a FeedMCP data endpoint (pay per call from $0.0003; failed calls free)."""
185
+ query = dict(params or {})
186
+ if view:
187
+ query["view"] = view
188
+ return self._request(
189
+ endpoint_to_path(endpoint),
190
+ params=query,
191
+ require_auth=True,
192
+ max_price=max_price,
193
+ idempotency_key=idempotency_key,
194
+ )
195
+
196
+ async def acall(
197
+ self,
198
+ endpoint: str,
199
+ params: dict[str, Any] | None = None,
200
+ *,
201
+ max_price: float | None = None,
202
+ idempotency_key: str | None = None,
203
+ view: str | None = None,
204
+ ) -> dict[str, Any]:
205
+ query = dict(params or {})
206
+ if view:
207
+ query["view"] = view
208
+ return await self._arequest(
209
+ endpoint_to_path(endpoint),
210
+ params=query,
211
+ require_auth=True,
212
+ max_price=max_price,
213
+ idempotency_key=idempotency_key,
214
+ )
File without changes
@@ -0,0 +1,36 @@
1
+ """LangChain BaseToolkit wrapper for FeedMCP."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from langchain_core.tools import BaseTool, BaseToolkit
6
+ from pydantic import ConfigDict, Field
7
+
8
+ from langchain_feedmcp._client import DEFAULT_BASE_URL, FeedMCPClient
9
+ from langchain_feedmcp.tools import (
10
+ FeedMCPAccountTool,
11
+ FeedMCPCallTool,
12
+ FeedMCPDescribeTool,
13
+ FeedMCPFindTool,
14
+ )
15
+
16
+
17
+ class FeedMCPToolkit(BaseToolkit):
18
+ """Toolkit bundling FeedMCP discovery, schema inspection, execution, and balance tools."""
19
+
20
+ model_config = ConfigDict(arbitrary_types_allowed=True)
21
+
22
+ api_key: str | None = Field(default=None)
23
+ base_url: str = Field(default=DEFAULT_BASE_URL)
24
+ default_max_price: float | None = Field(default=None)
25
+ include_paid: bool = Field(default=True)
26
+
27
+ def get_tools(self) -> list[BaseTool]:
28
+ client = FeedMCPClient(api_key=self.api_key, base_url=self.base_url)
29
+ tools: list[BaseTool] = [
30
+ FeedMCPFindTool(client=client),
31
+ FeedMCPDescribeTool(client=client),
32
+ ]
33
+ if self.include_paid:
34
+ tools.append(FeedMCPCallTool(client=client, default_max_price=self.default_max_price))
35
+ tools.append(FeedMCPAccountTool(client=client))
36
+ return tools