thingspeak-mcp 0.1.0__py3-none-any.whl
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.
thingspeak_mcp/server.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from dotenv import load_dotenv
|
|
3
|
+
import httpx
|
|
4
|
+
from fastmcp import FastMCP
|
|
5
|
+
|
|
6
|
+
load_dotenv()
|
|
7
|
+
|
|
8
|
+
# 从环境变量读取配置,避免密钥硬编码
|
|
9
|
+
CHANNEL_ID = os.getenv("THINGSPEAK_CHANNEL_ID", "12397") # 替换为你的默认频道
|
|
10
|
+
READ_API_KEY = os.getenv("THINGSPEAK_READ_KEY") # 私有频道需要,公开频道可留空
|
|
11
|
+
|
|
12
|
+
mcp = FastMCP("ThingSpeak Reader")
|
|
13
|
+
|
|
14
|
+
@mcp.tool()
|
|
15
|
+
async def get_latest_value(field: str = "field1") -> str:
|
|
16
|
+
"""读取 ThingSpeak 频道中指定字段的最新一条记录。"""
|
|
17
|
+
url = f"https://api.thingspeak.com/channels/{CHANNEL_ID}/feeds/last.json"
|
|
18
|
+
params = {}
|
|
19
|
+
if READ_API_KEY:
|
|
20
|
+
params["api_key"] = READ_API_KEY
|
|
21
|
+
|
|
22
|
+
async with httpx.AsyncClient() as client:
|
|
23
|
+
try:
|
|
24
|
+
resp = await client.get(url, params=params, timeout=10)
|
|
25
|
+
resp.raise_for_status()
|
|
26
|
+
data = resp.json()
|
|
27
|
+
value = data.get(field, "无此字段")
|
|
28
|
+
timestamp = data.get("created_at", "未知时间")
|
|
29
|
+
return f"{timestamp} 的 {field} 值为:{value}"
|
|
30
|
+
except Exception as e:
|
|
31
|
+
return f"读取失败:{str(e)}"
|
|
32
|
+
|
|
33
|
+
def main():
|
|
34
|
+
mcp.run(transport="stdio")
|
|
35
|
+
|
|
36
|
+
if __name__ == "__main__":
|
|
37
|
+
main()
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: thingspeak-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Add your description here
|
|
5
|
+
Author: bai603
|
|
6
|
+
Author-email: bai603 <baing@163.com>
|
|
7
|
+
Requires-Dist: fastmcp>=4.2.7
|
|
8
|
+
Requires-Dist: httpx>=0.29.0
|
|
9
|
+
Requires-Dist: mcp[cli]>=2.3.0
|
|
10
|
+
Requires-Dist: pandas>=3.1.2
|
|
11
|
+
Requires-Dist: python-dotenv>=1.2.4
|
|
12
|
+
Requires-Python: >=3.14
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
thingspeak_mcp/__init__.py,sha256=2e_79yKfoUCVonO0aEc1He0IiPm_7CJA2s5rLN9oM2E,60
|
|
2
|
+
thingspeak_mcp/server.py,sha256=A8nlwEQGzO9Jdz-2EiTCZr-XUiyu3WpVwb1lf73J-MM,1239
|
|
3
|
+
thingspeak_mcp-0.1.0.dist-info/WHEEL,sha256=wfHFB5CQ4yOA68LQ_ISeFjKJGxj2GfVzMH9QxkYgrCw,81
|
|
4
|
+
thingspeak_mcp-0.1.0.dist-info/entry_points.txt,sha256=HYZZzuU0vIgf-6rwgmsoY81SpRHUfZVbGFmlb2rvu4Y,56
|
|
5
|
+
thingspeak_mcp-0.1.0.dist-info/METADATA,sha256=mKSaEiX0z3_C6MEk1v3ne_LRLt26mPqftQhdufVX4Rw,365
|
|
6
|
+
thingspeak_mcp-0.1.0.dist-info/RECORD,,
|