mcp-surveys-cli 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,20 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mcp-surveys-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Tiny CLI for the hosted mcp-surveys API.
|
|
5
|
+
Author: mcp-surveys contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
|
|
10
|
+
# mcp-surveys-cli
|
|
11
|
+
|
|
12
|
+
Tiny stdlib-only CLI for the hosted mcp-surveys API.
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
uvx mcp-surveys-cli schema
|
|
16
|
+
uvx mcp-surveys-cli create survey.json
|
|
17
|
+
uvx mcp-surveys-cli answers <survey_id> <result_token>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Use `MCP_SURVEYS_BASE_URL` or `--base-url` to point at a different instance.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# mcp-surveys-cli
|
|
2
|
+
|
|
3
|
+
Tiny stdlib-only CLI for the hosted mcp-surveys API.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
uvx mcp-surveys-cli schema
|
|
7
|
+
uvx mcp-surveys-cli create survey.json
|
|
8
|
+
uvx mcp-surveys-cli answers <survey_id> <result_token>
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Use `MCP_SURVEYS_BASE_URL` or `--base-url` to point at a different instance.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "mcp-surveys-cli"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Tiny CLI for the hosted mcp-surveys API."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.11"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
authors = [{ name = "mcp-surveys contributors" }]
|
|
9
|
+
dependencies = []
|
|
10
|
+
|
|
11
|
+
[project.scripts]
|
|
12
|
+
mcp-surveys-cli = "mcp_surveys_cli.main:entrypoint"
|
|
13
|
+
|
|
14
|
+
[build-system]
|
|
15
|
+
requires = ["hatchling"]
|
|
16
|
+
build-backend = "hatchling.build"
|
|
17
|
+
|
|
18
|
+
[tool.hatch.build.targets.wheel]
|
|
19
|
+
packages = ["src/mcp_surveys_cli"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
import urllib.error
|
|
8
|
+
import urllib.request
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
DEFAULT_BASE_URL = "https://mcp.voevoda-sailing.ru"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class CliError(Exception):
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def read_json(path: str) -> dict[str, Any]:
|
|
21
|
+
try:
|
|
22
|
+
text = sys.stdin.read() if path == "-" else Path(path).read_text(encoding="utf-8")
|
|
23
|
+
value = json.loads(text)
|
|
24
|
+
except OSError as error:
|
|
25
|
+
raise CliError(f"cannot read {path}: {error}") from error
|
|
26
|
+
except json.JSONDecodeError as error:
|
|
27
|
+
raise CliError(f"invalid JSON in {path}: {error}") from error
|
|
28
|
+
if not isinstance(value, dict):
|
|
29
|
+
raise CliError(f"{path} must contain a JSON object")
|
|
30
|
+
return value
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def request(method: str, url: str, body: dict[str, Any] | None = None, raw: bool = False) -> Any:
|
|
34
|
+
data = json.dumps(body).encode("utf-8") if body is not None else None
|
|
35
|
+
headers = {"accept": "text/plain" if raw else "application/json"}
|
|
36
|
+
if body is not None:
|
|
37
|
+
headers["content-type"] = "application/json"
|
|
38
|
+
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
|
39
|
+
try:
|
|
40
|
+
with urllib.request.urlopen(req, timeout=30) as response:
|
|
41
|
+
text = response.read().decode("utf-8")
|
|
42
|
+
except urllib.error.HTTPError as error:
|
|
43
|
+
detail = error.read().decode("utf-8", errors="replace")
|
|
44
|
+
try:
|
|
45
|
+
detail = json.loads(detail).get("detail", detail)
|
|
46
|
+
except json.JSONDecodeError:
|
|
47
|
+
pass
|
|
48
|
+
raise CliError(f"HTTP {error.code}: {detail}") from error
|
|
49
|
+
except urllib.error.URLError as error:
|
|
50
|
+
raise CliError(f"request failed: {error.reason}") from error
|
|
51
|
+
return text if raw else json.loads(text)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def print_json(value: Any) -> None:
|
|
55
|
+
print(json.dumps(value, ensure_ascii=False, separators=(",", ":")))
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def endpoint(base_url: str, path: str) -> str:
|
|
59
|
+
return f"{base_url.rstrip('/')}{path}"
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
63
|
+
parser = argparse.ArgumentParser(prog="mcp-surveys-cli")
|
|
64
|
+
parser.add_argument("--base-url", default=os.environ.get("MCP_SURVEYS_BASE_URL", DEFAULT_BASE_URL))
|
|
65
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
66
|
+
|
|
67
|
+
create = sub.add_parser("create")
|
|
68
|
+
create.add_argument("payload", help="JSON file, or '-' for stdin")
|
|
69
|
+
|
|
70
|
+
edit = sub.add_parser("edit")
|
|
71
|
+
edit.add_argument("survey_id")
|
|
72
|
+
edit.add_argument("result_token")
|
|
73
|
+
edit.add_argument("patch", help="JSON file, or '-' for stdin")
|
|
74
|
+
|
|
75
|
+
for name in ("get", "summary", "answers"):
|
|
76
|
+
command = sub.add_parser(name)
|
|
77
|
+
command.add_argument("survey_id")
|
|
78
|
+
command.add_argument("result_token")
|
|
79
|
+
|
|
80
|
+
question = sub.add_parser("question")
|
|
81
|
+
question.add_argument("survey_id")
|
|
82
|
+
question.add_argument("result_token")
|
|
83
|
+
question.add_argument("question_id")
|
|
84
|
+
|
|
85
|
+
export = sub.add_parser("export")
|
|
86
|
+
export.add_argument("survey_id")
|
|
87
|
+
export.add_argument("result_token")
|
|
88
|
+
export.add_argument("--format", choices=("markdown", "json"), default="markdown")
|
|
89
|
+
|
|
90
|
+
sub.add_parser("schema")
|
|
91
|
+
return parser
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def main(argv: list[str] | None = None) -> int:
|
|
95
|
+
args = build_parser().parse_args(argv)
|
|
96
|
+
base = args.base_url
|
|
97
|
+
try:
|
|
98
|
+
if args.command == "create":
|
|
99
|
+
print_json(request("POST", endpoint(base, "/api/agent/surveys"), read_json(args.payload)))
|
|
100
|
+
elif args.command == "edit":
|
|
101
|
+
body = {"result_token": args.result_token, **read_json(args.patch)}
|
|
102
|
+
print_json(request("PATCH", endpoint(base, f"/api/agent/surveys/{args.survey_id}"), body))
|
|
103
|
+
elif args.command == "get":
|
|
104
|
+
print_json(
|
|
105
|
+
request("POST", endpoint(base, f"/api/agent/surveys/{args.survey_id}/state"), {"result_token": args.result_token})
|
|
106
|
+
)
|
|
107
|
+
elif args.command == "summary":
|
|
108
|
+
print_json(
|
|
109
|
+
request("POST", endpoint(base, f"/api/agent/surveys/{args.survey_id}/summary"), {"result_token": args.result_token})
|
|
110
|
+
)
|
|
111
|
+
elif args.command == "answers":
|
|
112
|
+
print_json(
|
|
113
|
+
request("POST", endpoint(base, f"/api/agent/surveys/{args.survey_id}/answers"), {"result_token": args.result_token})
|
|
114
|
+
)
|
|
115
|
+
elif args.command == "question":
|
|
116
|
+
print_json(
|
|
117
|
+
request(
|
|
118
|
+
"POST",
|
|
119
|
+
endpoint(base, f"/api/agent/surveys/{args.survey_id}/answers/{args.question_id}"),
|
|
120
|
+
{"result_token": args.result_token},
|
|
121
|
+
)
|
|
122
|
+
)
|
|
123
|
+
elif args.command == "export":
|
|
124
|
+
print(
|
|
125
|
+
request(
|
|
126
|
+
"POST",
|
|
127
|
+
endpoint(base, f"/api/agent/surveys/{args.survey_id}/export"),
|
|
128
|
+
{"result_token": args.result_token, "format": args.format},
|
|
129
|
+
raw=True,
|
|
130
|
+
),
|
|
131
|
+
end="",
|
|
132
|
+
)
|
|
133
|
+
elif args.command == "schema":
|
|
134
|
+
print_json(request("GET", endpoint(base, "/api/agent/question-schema")))
|
|
135
|
+
except CliError as error:
|
|
136
|
+
print(error, file=sys.stderr)
|
|
137
|
+
return 1
|
|
138
|
+
return 0
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def entrypoint() -> None:
|
|
142
|
+
raise SystemExit(main())
|