baaaton-mcp-server 1.0.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.
- baaaton_mcp_server-1.0.0/.gitignore +54 -0
- baaaton_mcp_server-1.0.0/PKG-INFO +65 -0
- baaaton_mcp_server-1.0.0/README.md +41 -0
- baaaton_mcp_server-1.0.0/pyproject.toml +51 -0
- baaaton_mcp_server-1.0.0/src/baaaton_mcp_server/__init__.py +3 -0
- baaaton_mcp_server-1.0.0/src/baaaton_mcp_server/client.py +125 -0
- baaaton_mcp_server-1.0.0/src/baaaton_mcp_server/server.py +69 -0
- baaaton_mcp_server-1.0.0/tests/test_client.py +98 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Dependencies
|
|
2
|
+
node_modules/
|
|
3
|
+
|
|
4
|
+
# Cloudflare Wrangler & Build Outputs
|
|
5
|
+
.wrangler/
|
|
6
|
+
dist/
|
|
7
|
+
.mf/
|
|
8
|
+
|
|
9
|
+
# Environment variables & secrets
|
|
10
|
+
.dev.vars
|
|
11
|
+
.dev.vars.*
|
|
12
|
+
.env
|
|
13
|
+
.env.*
|
|
14
|
+
*.pem
|
|
15
|
+
*.key
|
|
16
|
+
*.cert
|
|
17
|
+
*.pfx
|
|
18
|
+
|
|
19
|
+
# SQLite / Database local files & dumps
|
|
20
|
+
*.sqlite
|
|
21
|
+
*.sqlite3
|
|
22
|
+
*.db
|
|
23
|
+
*.db-journal
|
|
24
|
+
*.db-wal
|
|
25
|
+
*.db-shm
|
|
26
|
+
*.dump
|
|
27
|
+
*.sql.gz
|
|
28
|
+
|
|
29
|
+
# OS generated files
|
|
30
|
+
.DS_Store
|
|
31
|
+
.DS_Store?
|
|
32
|
+
._*
|
|
33
|
+
.Spotlight-V100
|
|
34
|
+
.Trashes
|
|
35
|
+
ehthumbs.db
|
|
36
|
+
Thumbs.db
|
|
37
|
+
|
|
38
|
+
# Logs & temporary files
|
|
39
|
+
*.log
|
|
40
|
+
npm-debug.log*
|
|
41
|
+
yarn-debug.log*
|
|
42
|
+
yarn-error.log*
|
|
43
|
+
pnpm-debug.log*
|
|
44
|
+
lerna-debug.log*
|
|
45
|
+
scratch/
|
|
46
|
+
tmp/
|
|
47
|
+
temp/
|
|
48
|
+
|
|
49
|
+
# IDE & Editor files
|
|
50
|
+
.idea/
|
|
51
|
+
.vscode/
|
|
52
|
+
*.swp
|
|
53
|
+
*.swo
|
|
54
|
+
*~
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: baaaton-mcp-server
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Official Model Context Protocol (MCP) server for BaaaTON — verify AI agent & MCP server safety ratings, search 5,000+ certified agoras across 36 global channels, and check threat feeds.
|
|
5
|
+
Project-URL: Homepage, https://baaaton.com/agora
|
|
6
|
+
Project-URL: Documentation, https://baaaton.com/SKILL.md
|
|
7
|
+
Project-URL: Repository, https://github.com/stevepark0826/baaaton-mcp-server
|
|
8
|
+
Author: BaaaTON Autonomous Sanctuary
|
|
9
|
+
License: MIT
|
|
10
|
+
Keywords: agent-safety,ai-agents,anti-token-drain,baaaton,mcp,mcp-server,model-context-protocol,prompt-injection,security-oracle
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Security
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: httpx>=0.27.0
|
|
22
|
+
Requires-Dist: mcp>=1.6.0
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# BaaaTON MCP Server (Python / `uvx`)
|
|
26
|
+
|
|
27
|
+
Official Python Model Context Protocol (MCP) server for **[BaaaTON](https://baaaton.com/agora)** — Sovereign Safety Oracle & Certified Agora Directory for 5,000+ AI agent ecosystems and MCP servers across 36 global channels.
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
uvx baaaton-mcp-server
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Or with `pip`:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install baaaton-mcp-server
|
|
39
|
+
baaaton-mcp-server
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Or connect zero-install via 1-line Remote Streamable HTTP MCP:
|
|
43
|
+
|
|
44
|
+
```json
|
|
45
|
+
{
|
|
46
|
+
"mcpServers": {
|
|
47
|
+
"baaaton": {
|
|
48
|
+
"url": "https://baaaton.com/mcp"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Available Tools
|
|
55
|
+
|
|
56
|
+
- `verify_agora(url, id)` — Inspect `AAA`/`AA`/`B`/`BLACKLIST` grade, 3-axiom scores (`Anima`/`Logos`/`Nexus`), and liveness status.
|
|
57
|
+
- `search_safe_agoras(q, grade, platform, limit)` — Discover certified safe agoras across GitHub, PyPI, npm, HuggingFace, Docker Hub, Smithery, and Nostr.
|
|
58
|
+
- `check_threat_feed(limit)` — Retrieve real-time quarantined token-drainer and unreachable endpoints.
|
|
59
|
+
- `submit_baton(service_domain, human_instant_entry_url, ...)` — Submit an agent service for free constitutional audit.
|
|
60
|
+
|
|
61
|
+
## License
|
|
62
|
+
|
|
63
|
+
MIT
|
|
64
|
+
|
|
65
|
+
mcp-name: com.baaaton/mcp-server
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# BaaaTON MCP Server (Python / `uvx`)
|
|
2
|
+
|
|
3
|
+
Official Python Model Context Protocol (MCP) server for **[BaaaTON](https://baaaton.com/agora)** — Sovereign Safety Oracle & Certified Agora Directory for 5,000+ AI agent ecosystems and MCP servers across 36 global channels.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
uvx baaaton-mcp-server
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or with `pip`:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install baaaton-mcp-server
|
|
15
|
+
baaaton-mcp-server
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Or connect zero-install via 1-line Remote Streamable HTTP MCP:
|
|
19
|
+
|
|
20
|
+
```json
|
|
21
|
+
{
|
|
22
|
+
"mcpServers": {
|
|
23
|
+
"baaaton": {
|
|
24
|
+
"url": "https://baaaton.com/mcp"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Available Tools
|
|
31
|
+
|
|
32
|
+
- `verify_agora(url, id)` — Inspect `AAA`/`AA`/`B`/`BLACKLIST` grade, 3-axiom scores (`Anima`/`Logos`/`Nexus`), and liveness status.
|
|
33
|
+
- `search_safe_agoras(q, grade, platform, limit)` — Discover certified safe agoras across GitHub, PyPI, npm, HuggingFace, Docker Hub, Smithery, and Nostr.
|
|
34
|
+
- `check_threat_feed(limit)` — Retrieve real-time quarantined token-drainer and unreachable endpoints.
|
|
35
|
+
- `submit_baton(service_domain, human_instant_entry_url, ...)` — Submit an agent service for free constitutional audit.
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
MIT
|
|
40
|
+
|
|
41
|
+
mcp-name: com.baaaton/mcp-server
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.25.0"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "baaaton-mcp-server"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Official Model Context Protocol (MCP) server for BaaaTON — verify AI agent & MCP server safety ratings, search 5,000+ certified agoras across 36 global channels, and check threat feeds."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "BaaaTON Autonomous Sanctuary" }
|
|
14
|
+
]
|
|
15
|
+
keywords = [
|
|
16
|
+
"mcp",
|
|
17
|
+
"mcp-server",
|
|
18
|
+
"model-context-protocol",
|
|
19
|
+
"ai-agents",
|
|
20
|
+
"agent-safety",
|
|
21
|
+
"security-oracle",
|
|
22
|
+
"prompt-injection",
|
|
23
|
+
"anti-token-drain",
|
|
24
|
+
"baaaton"
|
|
25
|
+
]
|
|
26
|
+
classifiers = [
|
|
27
|
+
"Development Status :: 5 - Production/Stable",
|
|
28
|
+
"Intended Audience :: Developers",
|
|
29
|
+
"License :: OSI Approved :: MIT License",
|
|
30
|
+
"Programming Language :: Python :: 3",
|
|
31
|
+
"Programming Language :: Python :: 3.10",
|
|
32
|
+
"Programming Language :: Python :: 3.11",
|
|
33
|
+
"Programming Language :: Python :: 3.12",
|
|
34
|
+
"Programming Language :: Python :: 3.13",
|
|
35
|
+
"Topic :: Security"
|
|
36
|
+
]
|
|
37
|
+
dependencies = [
|
|
38
|
+
"mcp>=1.6.0",
|
|
39
|
+
"httpx>=0.27.0"
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[project.scripts]
|
|
43
|
+
baaaton-mcp-server = "baaaton_mcp_server.server:main"
|
|
44
|
+
|
|
45
|
+
[project.urls]
|
|
46
|
+
Homepage = "https://baaaton.com/agora"
|
|
47
|
+
Documentation = "https://baaaton.com/SKILL.md"
|
|
48
|
+
Repository = "https://github.com/stevepark0826/baaaton-mcp-server"
|
|
49
|
+
|
|
50
|
+
[tool.hatch.build.targets.wheel]
|
|
51
|
+
packages = ["src/baaaton_mcp_server"]
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"""Thin async HTTP client for BaaaTON public safety oracle APIs."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from typing import Any
|
|
7
|
+
from urllib.parse import urlencode
|
|
8
|
+
|
|
9
|
+
import httpx
|
|
10
|
+
|
|
11
|
+
PACKAGE_VERSION = "1.0.0"
|
|
12
|
+
DEFAULT_API_BASE = "https://baaaton.com"
|
|
13
|
+
REQUEST_TIMEOUT_SEC = 15.0
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class BaaatonPublicClient:
|
|
17
|
+
"""Async public API client for BaaaTON (zero auth, 15s hard timeout)."""
|
|
18
|
+
|
|
19
|
+
def __init__(self, base_url: str | None = None) -> None:
|
|
20
|
+
raw_base = base_url or os.environ.get("BAAATON_API_BASE") or DEFAULT_API_BASE
|
|
21
|
+
self.base_url = raw_base.rstrip("/")
|
|
22
|
+
self.user_agent = f"baaaton-mcp-server-py/{PACKAGE_VERSION}"
|
|
23
|
+
|
|
24
|
+
async def _request(
|
|
25
|
+
self,
|
|
26
|
+
method: str,
|
|
27
|
+
path: str,
|
|
28
|
+
json_body: dict[str, Any] | None = None,
|
|
29
|
+
) -> dict[str, Any]:
|
|
30
|
+
headers = {
|
|
31
|
+
"User-Agent": self.user_agent,
|
|
32
|
+
"Accept": "application/json",
|
|
33
|
+
}
|
|
34
|
+
if json_body is not None:
|
|
35
|
+
headers["Content-Type"] = "application/json"
|
|
36
|
+
|
|
37
|
+
try:
|
|
38
|
+
async with httpx.AsyncClient(timeout=REQUEST_TIMEOUT_SEC) as client:
|
|
39
|
+
response = await client.request(
|
|
40
|
+
method,
|
|
41
|
+
f"{self.base_url}{path}",
|
|
42
|
+
headers=headers,
|
|
43
|
+
json=json_body,
|
|
44
|
+
)
|
|
45
|
+
try:
|
|
46
|
+
data: Any = response.json()
|
|
47
|
+
except ValueError:
|
|
48
|
+
data = response.text
|
|
49
|
+
return {"ok": response.is_success, "status": response.status_code, "data": data}
|
|
50
|
+
except httpx.TimeoutException:
|
|
51
|
+
return {
|
|
52
|
+
"ok": False,
|
|
53
|
+
"status": 0,
|
|
54
|
+
"data": {
|
|
55
|
+
"error": "CLIENT_REQUEST_TIMEOUT",
|
|
56
|
+
"message": f"Request timed out after {REQUEST_TIMEOUT_SEC}s",
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
except httpx.HTTPError as exc:
|
|
60
|
+
return {
|
|
61
|
+
"ok": False,
|
|
62
|
+
"status": 0,
|
|
63
|
+
"data": {"error": "CLIENT_REQUEST_FAILED", "message": str(exc)},
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async def verify_agora(
|
|
67
|
+
self,
|
|
68
|
+
url: str | None = None,
|
|
69
|
+
agora_id: str | None = None,
|
|
70
|
+
) -> dict[str, Any]:
|
|
71
|
+
params: dict[str, str] = {}
|
|
72
|
+
if url:
|
|
73
|
+
params["url"] = url
|
|
74
|
+
if agora_id:
|
|
75
|
+
params["id"] = agora_id
|
|
76
|
+
return await self._request("GET", f"/api/v1/agoras/verify?{urlencode(params)}")
|
|
77
|
+
|
|
78
|
+
async def search_safe_agoras(
|
|
79
|
+
self,
|
|
80
|
+
q: str | None = None,
|
|
81
|
+
grade: str | None = None,
|
|
82
|
+
platform: str | None = None,
|
|
83
|
+
limit: int = 20,
|
|
84
|
+
) -> dict[str, Any]:
|
|
85
|
+
params: dict[str, str] = {"limit": str(max(1, min(50, limit)))}
|
|
86
|
+
if q:
|
|
87
|
+
params["q"] = q
|
|
88
|
+
if grade:
|
|
89
|
+
params["grade"] = grade
|
|
90
|
+
if platform:
|
|
91
|
+
params["platform"] = platform
|
|
92
|
+
return await self._request("GET", f"/api/v1/agoras/search?{urlencode(params)}")
|
|
93
|
+
|
|
94
|
+
async def check_threat_feed(self, limit: int = 20) -> dict[str, Any]:
|
|
95
|
+
clamped = max(1, min(50, limit))
|
|
96
|
+
return await self._request("GET", f"/api/v1/threat-feed?limit={clamped}")
|
|
97
|
+
|
|
98
|
+
async def submit_baton(
|
|
99
|
+
self,
|
|
100
|
+
service_domain: str,
|
|
101
|
+
human_instant_entry_url: str,
|
|
102
|
+
agent_role: str | None = None,
|
|
103
|
+
human_manifesto: str | None = None,
|
|
104
|
+
instructions: str | None = None,
|
|
105
|
+
) -> dict[str, Any]:
|
|
106
|
+
payload = {
|
|
107
|
+
"identity_and_resonance": {
|
|
108
|
+
"service_domain": service_domain,
|
|
109
|
+
"agent_role": agent_role or "Autonomous AI Utility Service",
|
|
110
|
+
"human_manifesto": (
|
|
111
|
+
human_manifesto
|
|
112
|
+
or "Open-web transparent AI service respecting human autonomy."
|
|
113
|
+
),
|
|
114
|
+
},
|
|
115
|
+
"pwa_execution_grip": {
|
|
116
|
+
"human_instant_entry_url": human_instant_entry_url,
|
|
117
|
+
},
|
|
118
|
+
"agent_handshake": {
|
|
119
|
+
"instructions": (
|
|
120
|
+
instructions
|
|
121
|
+
or "Standardized JSON handoff via BaaaTON open protocol."
|
|
122
|
+
),
|
|
123
|
+
},
|
|
124
|
+
}
|
|
125
|
+
return await self._request("POST", "/api/v1/batons/submit", json_body=payload)
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""BaaaTON Official Python MCP Server (FastMCP stdio entrypoint)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from typing import Literal
|
|
7
|
+
|
|
8
|
+
from mcp.server.fastmcp import FastMCP
|
|
9
|
+
|
|
10
|
+
from .client import BaaatonPublicClient
|
|
11
|
+
|
|
12
|
+
mcp = FastMCP("baaaton-mcp-server")
|
|
13
|
+
_client = BaaatonPublicClient()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@mcp.tool()
|
|
17
|
+
async def verify_agora(url: str | None = None, id: str | None = None) -> str:
|
|
18
|
+
"""Verify BaaaTON safety rating (AAA/AA/B/BLACKLIST), 3-axiom scores, and liveness."""
|
|
19
|
+
if not url and not id:
|
|
20
|
+
return json.dumps({"error": "Provide either url or id."}, indent=2)
|
|
21
|
+
res = await _client.verify_agora(url=url, agora_id=id)
|
|
22
|
+
return json.dumps(res["data"], indent=2)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@mcp.tool()
|
|
26
|
+
async def search_safe_agoras(
|
|
27
|
+
q: str | None = None,
|
|
28
|
+
grade: Literal["AAA", "AA", "B"] | None = None,
|
|
29
|
+
platform: str | None = None,
|
|
30
|
+
limit: int = 20,
|
|
31
|
+
) -> str:
|
|
32
|
+
"""Search 5,000+ BaaaTON-audited safe AI agent agoras and MCP servers."""
|
|
33
|
+
res = await _client.search_safe_agoras(q=q, grade=grade, platform=platform, limit=limit)
|
|
34
|
+
return json.dumps(res["data"], indent=2)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@mcp.tool()
|
|
38
|
+
async def check_threat_feed(limit: int = 20) -> str:
|
|
39
|
+
"""Query the real-time feed of quarantined (BLACKLIST/COMPROMISED/UNREACHABLE) endpoints."""
|
|
40
|
+
res = await _client.check_threat_feed(limit=limit)
|
|
41
|
+
return json.dumps(res["data"], indent=2)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@mcp.tool()
|
|
45
|
+
async def submit_baton(
|
|
46
|
+
service_domain: str,
|
|
47
|
+
human_instant_entry_url: str,
|
|
48
|
+
agent_role: str | None = None,
|
|
49
|
+
human_manifesto: str | None = None,
|
|
50
|
+
instructions: str | None = None,
|
|
51
|
+
) -> str:
|
|
52
|
+
"""Submit an open-web AI agent service (Baton) to BaaaTON for free constitutional audit."""
|
|
53
|
+
res = await _client.submit_baton(
|
|
54
|
+
service_domain=service_domain,
|
|
55
|
+
human_instant_entry_url=human_instant_entry_url,
|
|
56
|
+
agent_role=agent_role,
|
|
57
|
+
human_manifesto=human_manifesto,
|
|
58
|
+
instructions=instructions,
|
|
59
|
+
)
|
|
60
|
+
return json.dumps(res["data"], indent=2)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def main() -> None:
|
|
64
|
+
"""Run BaaaTON MCP server over stdio transport."""
|
|
65
|
+
mcp.run(transport="stdio")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if __name__ == "__main__":
|
|
69
|
+
main()
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""Unit tests for BaaaTON Python MCP client (zero external network)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import importlib.util
|
|
7
|
+
import pathlib
|
|
8
|
+
import sys
|
|
9
|
+
import types
|
|
10
|
+
import unittest
|
|
11
|
+
from unittest.mock import AsyncMock, MagicMock, patch
|
|
12
|
+
|
|
13
|
+
ROOT = pathlib.Path(__file__).resolve().parents[1]
|
|
14
|
+
CLIENT_PATH = ROOT / "src" / "baaaton_mcp_server" / "client.py"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class _FakeHttpxTimeout(Exception):
|
|
18
|
+
pass
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class _FakeHttpxError(Exception):
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _load_client_module():
|
|
26
|
+
fake_httpx = types.ModuleType("httpx")
|
|
27
|
+
fake_httpx.TimeoutException = _FakeHttpxTimeout
|
|
28
|
+
fake_httpx.HTTPError = _FakeHttpxError
|
|
29
|
+
fake_httpx.AsyncClient = MagicMock()
|
|
30
|
+
sys.modules["httpx"] = fake_httpx
|
|
31
|
+
|
|
32
|
+
spec = importlib.util.spec_from_file_location("baaaton_client_under_test", CLIENT_PATH)
|
|
33
|
+
module = importlib.util.module_from_spec(spec)
|
|
34
|
+
assert spec and spec.loader
|
|
35
|
+
spec.loader.exec_module(module)
|
|
36
|
+
return module, fake_httpx
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class TestBaaatonPythonClient(unittest.TestCase):
|
|
40
|
+
def test_verify_and_search_urls_and_payload(self) -> None:
|
|
41
|
+
client_mod, fake_httpx = _load_client_module()
|
|
42
|
+
|
|
43
|
+
mock_resp = MagicMock()
|
|
44
|
+
mock_resp.is_success = True
|
|
45
|
+
mock_resp.status_code = 200
|
|
46
|
+
mock_resp.json.return_value = {"grade": "AAA", "verified": True}
|
|
47
|
+
|
|
48
|
+
mock_async_client = AsyncMock()
|
|
49
|
+
mock_async_client.request = AsyncMock(return_value=mock_resp)
|
|
50
|
+
mock_async_client.__aenter__ = AsyncMock(return_value=mock_async_client)
|
|
51
|
+
mock_async_client.__aexit__ = AsyncMock(return_value=False)
|
|
52
|
+
fake_httpx.AsyncClient.return_value = mock_async_client
|
|
53
|
+
|
|
54
|
+
client = client_mod.BaaatonPublicClient(base_url="https://baaaton.com/")
|
|
55
|
+
|
|
56
|
+
async def _run():
|
|
57
|
+
r1 = await client.verify_agora(url="https://example.org/mcp")
|
|
58
|
+
r2 = await client.search_safe_agoras(q="mcp", grade="AAA", limit=10)
|
|
59
|
+
r3 = await client.check_threat_feed(limit=5)
|
|
60
|
+
r4 = await client.submit_baton(
|
|
61
|
+
service_domain="Test Agent",
|
|
62
|
+
human_instant_entry_url="https://example.org/app",
|
|
63
|
+
)
|
|
64
|
+
return r1, r2, r3, r4
|
|
65
|
+
|
|
66
|
+
r1, r2, r3, r4 = asyncio.run(_run())
|
|
67
|
+
self.assertTrue(r1["ok"])
|
|
68
|
+
self.assertEqual(r1["status"], 200)
|
|
69
|
+
self.assertTrue(r2["ok"])
|
|
70
|
+
self.assertTrue(r3["ok"])
|
|
71
|
+
self.assertTrue(r4["ok"])
|
|
72
|
+
|
|
73
|
+
calls = mock_async_client.request.call_args_list
|
|
74
|
+
self.assertEqual(calls[0].args[0], "GET")
|
|
75
|
+
self.assertIn("/api/v1/agoras/verify?url=https%3A%2F%2Fexample.org%2Fmcp", calls[0].args[1])
|
|
76
|
+
self.assertIn("/api/v1/agoras/search?limit=10&q=mcp&grade=AAA", calls[1].args[1])
|
|
77
|
+
self.assertIn("/api/v1/threat-feed?limit=5", calls[2].args[1])
|
|
78
|
+
self.assertEqual(calls[3].args[0], "POST")
|
|
79
|
+
self.assertEqual(calls[3].kwargs["json"]["pwa_execution_grip"]["human_instant_entry_url"], "https://example.org/app")
|
|
80
|
+
|
|
81
|
+
def test_timeout_returns_structured_error(self) -> None:
|
|
82
|
+
client_mod, fake_httpx = _load_client_module()
|
|
83
|
+
|
|
84
|
+
mock_async_client = AsyncMock()
|
|
85
|
+
mock_async_client.request = AsyncMock(side_effect=_FakeHttpxTimeout("timed out"))
|
|
86
|
+
mock_async_client.__aenter__ = AsyncMock(return_value=mock_async_client)
|
|
87
|
+
mock_async_client.__aexit__ = AsyncMock(return_value=False)
|
|
88
|
+
fake_httpx.AsyncClient.return_value = mock_async_client
|
|
89
|
+
|
|
90
|
+
client = client_mod.BaaatonPublicClient()
|
|
91
|
+
res = asyncio.run(client.check_threat_feed())
|
|
92
|
+
self.assertFalse(res["ok"])
|
|
93
|
+
self.assertEqual(res["status"], 0)
|
|
94
|
+
self.assertEqual(res["data"]["error"], "CLIENT_REQUEST_TIMEOUT")
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
if __name__ == "__main__":
|
|
98
|
+
unittest.main()
|