hhc-openstd-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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""hhc-openstd-mcp: MCP server for Chinese national standards (国家标准全文公开系统)."""
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"""MCP server wrapping the OpenSTD_Spider CLI for national standard search, info, and download."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import subprocess
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Optional
|
|
8
|
+
|
|
9
|
+
from fastmcp import FastMCP
|
|
10
|
+
|
|
11
|
+
mcp = FastMCP(
|
|
12
|
+
name="tiantian-openstd-mcp",
|
|
13
|
+
instructions="Search, query metadata, and download PDFs from the Chinese National Standard Full-Text Public System (国家标准全文公开系统, openstd.samr.gov.cn).",
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _run_openstd(*args: str) -> str:
|
|
18
|
+
"""Run openstd_spider CLI and return stdout."""
|
|
19
|
+
cmd = ["openstd_spider", *args]
|
|
20
|
+
result = subprocess.run(
|
|
21
|
+
cmd,
|
|
22
|
+
capture_output=True,
|
|
23
|
+
text=True,
|
|
24
|
+
timeout=120,
|
|
25
|
+
)
|
|
26
|
+
if result.returncode != 0:
|
|
27
|
+
raise RuntimeError(f"openstd_spider {args[0]} failed (exit {result.returncode}): {result.stderr.strip()}")
|
|
28
|
+
return result.stdout
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@mcp.tool()
|
|
32
|
+
def search_standards(
|
|
33
|
+
keyword: str = "",
|
|
34
|
+
status: Optional[str] = None,
|
|
35
|
+
std_type: Optional[str] = None,
|
|
36
|
+
page: int = 1,
|
|
37
|
+
page_size: int = 20,
|
|
38
|
+
) -> str:
|
|
39
|
+
"""Search the Chinese National Standard Full-Text Public System (国家标准全文公开系统).
|
|
40
|
+
|
|
41
|
+
Args:
|
|
42
|
+
keyword: Search keyword (e.g., "通信管道", "综合布线", "GB 50374"). Can be a standard number or topic.
|
|
43
|
+
status: Filter by status: "现行" (current), "即将实施" (upcoming), "废止" (abolished). None for all.
|
|
44
|
+
std_type: Filter by standard type: "GB" (mandatory), "GBT" (recommended), "GBZ" (guiding). None for all.
|
|
45
|
+
page: Page number (1-based).
|
|
46
|
+
page_size: Results per page (10-50, default 20).
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
JSON string with matched standards list (standard number, name, status, type, date, classification).
|
|
50
|
+
"""
|
|
51
|
+
args = ["search", "--json", "-p", str(page), "--ps", str(page_size)]
|
|
52
|
+
if keyword:
|
|
53
|
+
args.append(keyword)
|
|
54
|
+
if status:
|
|
55
|
+
args += ["--status", status]
|
|
56
|
+
if std_type:
|
|
57
|
+
args += ["--type", std_type]
|
|
58
|
+
|
|
59
|
+
output = _run_openstd(*args)
|
|
60
|
+
return output
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@mcp.tool()
|
|
64
|
+
def get_standard_info(target: str) -> str:
|
|
65
|
+
"""Query detailed metadata for a specific national standard.
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
target: Standard number (e.g., "GB 18030-2022") or the full URL of the standard page.
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
JSON string with standard metadata: number, Chinese/English names, classification,
|
|
72
|
+
publication date, implementation date, responsible body, etc.
|
|
73
|
+
"""
|
|
74
|
+
args = ["info", "--json", target]
|
|
75
|
+
output = _run_openstd(*args)
|
|
76
|
+
return output
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@mcp.tool()
|
|
80
|
+
def download_standard_pdf(target: str, output_dir: Optional[str] = None, preview: bool = False) -> str:
|
|
81
|
+
"""Download a national standard as PDF file.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
target: Standard number (e.g., "GB 18030-2022") or the full URL of the standard page.
|
|
85
|
+
output_dir: Directory to save the PDF (defaults to current working directory).
|
|
86
|
+
preview: If True, force preview-mode download (for standards that only allow preview).
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
Path to the downloaded PDF file.
|
|
90
|
+
"""
|
|
91
|
+
args = ["download", target]
|
|
92
|
+
if output_dir:
|
|
93
|
+
os.makedirs(output_dir, exist_ok=True)
|
|
94
|
+
args += ["-o", output_dir]
|
|
95
|
+
if preview:
|
|
96
|
+
args.append("--preview")
|
|
97
|
+
|
|
98
|
+
result = subprocess.run(
|
|
99
|
+
["openstd_spider"] + args,
|
|
100
|
+
capture_output=True,
|
|
101
|
+
text=True,
|
|
102
|
+
timeout=300,
|
|
103
|
+
)
|
|
104
|
+
if result.returncode != 0:
|
|
105
|
+
raise RuntimeError(f"Download failed: {result.stderr.strip()[:500]}")
|
|
106
|
+
return result.stdout.strip()
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def main():
|
|
110
|
+
mcp.run()
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
if __name__ == "__main__":
|
|
114
|
+
main()
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: hhc-openstd-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP server for searching and downloading Chinese national standards (国家标准全文公开系统)
|
|
5
|
+
License-Expression: GPL-3.0-or-later
|
|
6
|
+
Requires-Python: <3.13,>=3.10
|
|
7
|
+
Requires-Dist: fastmcp>=2.0
|
|
8
|
+
Requires-Dist: openstd-spider
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
# hhc-openstd-mcp
|
|
12
|
+
|
|
13
|
+
MCP server for searching, querying, and downloading Chinese national standards from the [国家标准全文公开系统](https://openstd.samr.gov.cn).
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- **search_standards** — Search by keyword, filter by status (现行/即将实施/废止) and type (GB/GBT/GBZ)
|
|
18
|
+
- **get_standard_info** — Query full metadata for a standard number or URL
|
|
19
|
+
- **download_standard_pdf** — Download standard as PDF (handles both direct download and preview mode)
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Using uvx (recommended, no install needed)
|
|
25
|
+
uvx hhc-openstd-mcp
|
|
26
|
+
|
|
27
|
+
# Using pip
|
|
28
|
+
pip install hhc-openstd-mcp
|
|
29
|
+
hhc-openstd-mcp
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## MCP Client Configuration
|
|
33
|
+
|
|
34
|
+
### Claude Desktop / Claude Code
|
|
35
|
+
|
|
36
|
+
```json
|
|
37
|
+
{
|
|
38
|
+
"mcpServers": {
|
|
39
|
+
"hhc-openstd": {
|
|
40
|
+
"command": "uvx",
|
|
41
|
+
"args": ["hhc-openstd-mcp"]
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Cursor / VS Code
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{
|
|
51
|
+
"mcp": {
|
|
52
|
+
"hhc-openstd": {
|
|
53
|
+
"type": "local",
|
|
54
|
+
"command": ["npx", "-y", "hhc-openstd-mcp"]
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
(Or use `uvx` directly if available on PATH.)
|
|
61
|
+
|
|
62
|
+
### Cline
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"mcpServers": {
|
|
67
|
+
"hhc-openstd": {
|
|
68
|
+
"command": "uvx",
|
|
69
|
+
"args": ["hhc-openstd-mcp"]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Example Tools
|
|
76
|
+
|
|
77
|
+
| Tool | Purpose |
|
|
78
|
+
|------|---------|
|
|
79
|
+
| `search_standards(keyword="通信管道", status="现行")` | Find current standards about communication ducts |
|
|
80
|
+
| `get_standard_info("GB 50374-2018")` | Get metadata for a specific standard |
|
|
81
|
+
| `download_standard_pdf("GB 50374-2018")` | Download the standard as PDF |
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
GPL-3.0-or-later (same as upstream [OpenSTD_Spider](https://github.com/SocialSisterYi/OpenSTD_Spider)).
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
hhc_openstd_mcp/__init__.py,sha256=QGIrS7Sjw9gxFgcJRKiF4LkYdm2Pmb4n7qF3RSxbMmA,99
|
|
2
|
+
hhc_openstd_mcp/server.py,sha256=_jROdVqLt4CRb6q2jBZ7vFabOguaAD80AQzhECswezo,3558
|
|
3
|
+
hhc_openstd_mcp-0.1.0.dist-info/METADATA,sha256=ADUDZFDKxSI6BcYqLlI_QuIN6F3uhrkieN2OL9tARO0,1935
|
|
4
|
+
hhc_openstd_mcp-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
5
|
+
hhc_openstd_mcp-0.1.0.dist-info/entry_points.txt,sha256=iKjapCo0LAG7CTZt5mCkZceJez2SNrTQKPW4cfZKqNk,64
|
|
6
|
+
hhc_openstd_mcp-0.1.0.dist-info/RECORD,,
|