dragon-py-mcp 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.
- dragon_py_mcp-0.1.0/PKG-INFO +13 -0
- dragon_py_mcp-0.1.0/README.md +4 -0
- dragon_py_mcp-0.1.0/pyproject.toml +15 -0
- dragon_py_mcp-0.1.0/setup.cfg +4 -0
- dragon_py_mcp-0.1.0/src/dragon_py_mcp/__init__.py +7 -0
- dragon_py_mcp-0.1.0/src/dragon_py_mcp/client.py +26 -0
- dragon_py_mcp-0.1.0/src/dragon_py_mcp.egg-info/PKG-INFO +13 -0
- dragon_py_mcp-0.1.0/src/dragon_py_mcp.egg-info/SOURCES.txt +10 -0
- dragon_py_mcp-0.1.0/src/dragon_py_mcp.egg-info/dependency_links.txt +1 -0
- dragon_py_mcp-0.1.0/src/dragon_py_mcp.egg-info/requires.txt +1 -0
- dragon_py_mcp-0.1.0/src/dragon_py_mcp.egg-info/top_level.txt +1 -0
- dragon_py_mcp-0.1.0/tests/test_client.py +57 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dragon-py-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: DRAGON MCP 资源客户端(Python):resources/list + resources/read(stdlib 传输)
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: dragon-py-core
|
|
9
|
+
|
|
10
|
+
# dragon-py-mcp
|
|
11
|
+
|
|
12
|
+
DRAGON 领域框架 Python SDK 组件(mcp 面)。用法与多语言一致性门禁见
|
|
13
|
+
[python/README.md](../README.md);框架主仓:DRAGON 领域框架(Apache-2.0)。
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dragon-py-mcp"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "DRAGON MCP 资源客户端(Python):resources/list + resources/read(stdlib 传输)"
|
|
9
|
+
requires-python = ">=3.10"
|
|
10
|
+
license = {text = "Apache-2.0"}
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
dependencies = ["dragon-py-core"]
|
|
13
|
+
|
|
14
|
+
[tool.setuptools.packages.find]
|
|
15
|
+
where = ["src"]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""MCP 资源客户端(JSON-RPC over HTTP;资源 URI 形如 mcp://<domain>/<name>)。"""
|
|
2
|
+
import json
|
|
3
|
+
import urllib.request
|
|
4
|
+
from typing import Any, Dict, List
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class McpResourceClient:
|
|
8
|
+
def __init__(self, endpoint: str, timeout: float = 30.0):
|
|
9
|
+
self.endpoint = endpoint.rstrip("/")
|
|
10
|
+
self.timeout = timeout
|
|
11
|
+
|
|
12
|
+
def _call(self, method: str, params: Dict[str, Any]) -> Dict[str, Any]:
|
|
13
|
+
payload = json.dumps(
|
|
14
|
+
{"jsonrpc": "2.0", "id": 1, "method": method, "params": params}
|
|
15
|
+
).encode("utf-8")
|
|
16
|
+
req = urllib.request.Request( # noqa: S310
|
|
17
|
+
self.endpoint, data=payload, headers={"content-type": "application/json"}
|
|
18
|
+
)
|
|
19
|
+
with urllib.request.urlopen(req, timeout=self.timeout) as resp: # noqa: S310
|
|
20
|
+
return json.loads(resp.read().decode("utf-8"))
|
|
21
|
+
|
|
22
|
+
def list_resources(self) -> List[Dict[str, Any]]:
|
|
23
|
+
return self._call("resources/list", {}).get("result", {}).get("resources", [])
|
|
24
|
+
|
|
25
|
+
def read_resource(self, uri: str) -> Dict[str, Any]:
|
|
26
|
+
return self._call("resources/read", {"uri": uri}).get("result", {})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dragon-py-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: DRAGON MCP 资源客户端(Python):resources/list + resources/read(stdlib 传输)
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: dragon-py-core
|
|
9
|
+
|
|
10
|
+
# dragon-py-mcp
|
|
11
|
+
|
|
12
|
+
DRAGON 领域框架 Python SDK 组件(mcp 面)。用法与多语言一致性门禁见
|
|
13
|
+
[python/README.md](../README.md);框架主仓:DRAGON 领域框架(Apache-2.0)。
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
src/dragon_py_mcp/__init__.py
|
|
4
|
+
src/dragon_py_mcp/client.py
|
|
5
|
+
src/dragon_py_mcp.egg-info/PKG-INFO
|
|
6
|
+
src/dragon_py_mcp.egg-info/SOURCES.txt
|
|
7
|
+
src/dragon_py_mcp.egg-info/dependency_links.txt
|
|
8
|
+
src/dragon_py_mcp.egg-info/requires.txt
|
|
9
|
+
src/dragon_py_mcp.egg-info/top_level.txt
|
|
10
|
+
tests/test_client.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dragon-py-core
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dragon_py_mcp
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""MCP 客户端测试:请求形状与 URI 约定(无网络——本地 mock handler)。"""
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
from dragon_py_mcp import McpResourceClient
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def test_list_resources_builds_jsonrpc_request(monkeypatch):
|
|
8
|
+
captured = {}
|
|
9
|
+
|
|
10
|
+
def fake_urlopen(req, timeout=None): # noqa: ANN001
|
|
11
|
+
captured["body"] = json.loads(req.data.decode("utf-8"))
|
|
12
|
+
captured["url"] = req.full_url
|
|
13
|
+
captured["content_type"] = req.headers.get("Content-type")
|
|
14
|
+
|
|
15
|
+
class R:
|
|
16
|
+
def read(self):
|
|
17
|
+
return b'{"jsonrpc":"2.0","id":1,"result":{"resources":[{"uri":"mcp://academic/rag"}]}}'
|
|
18
|
+
|
|
19
|
+
def __enter__(self):
|
|
20
|
+
return self
|
|
21
|
+
|
|
22
|
+
def __exit__(self, *a):
|
|
23
|
+
return False
|
|
24
|
+
|
|
25
|
+
return R()
|
|
26
|
+
|
|
27
|
+
monkeypatch.setattr("urllib.request.urlopen", fake_urlopen)
|
|
28
|
+
client = McpResourceClient("http://127.0.0.1:8888")
|
|
29
|
+
rows = client.list_resources()
|
|
30
|
+
assert captured["body"]["method"] == "resources/list"
|
|
31
|
+
assert captured["url"] == "http://127.0.0.1:8888"
|
|
32
|
+
assert rows[0]["uri"] == "mcp://academic/rag"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_read_resource_passes_uri(monkeypatch):
|
|
36
|
+
captured = {}
|
|
37
|
+
|
|
38
|
+
def fake_urlopen(req, timeout=None): # noqa: ANN001
|
|
39
|
+
captured["body"] = json.loads(req.data.decode("utf-8"))
|
|
40
|
+
|
|
41
|
+
class R:
|
|
42
|
+
def read(self):
|
|
43
|
+
return b'{"jsonrpc":"2.0","id":1,"result":{"contents":[]}}'
|
|
44
|
+
|
|
45
|
+
def __enter__(self):
|
|
46
|
+
return self
|
|
47
|
+
|
|
48
|
+
def __exit__(self, *a):
|
|
49
|
+
return False
|
|
50
|
+
|
|
51
|
+
return R()
|
|
52
|
+
|
|
53
|
+
monkeypatch.setattr("urllib.request.urlopen", fake_urlopen)
|
|
54
|
+
client = McpResourceClient("http://127.0.0.1:8888")
|
|
55
|
+
client.read_resource("mcp://academic/rag")
|
|
56
|
+
assert captured["body"]["method"] == "resources/read"
|
|
57
|
+
assert captured["body"]["params"]["uri"] == "mcp://academic/rag"
|