archscan-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,66 @@
1
+ Metadata-Version: 2.4
2
+ Name: archscan-mcp
3
+ Version: 0.1.0
4
+ Summary: MCP server for NeuroScan: analyze and fix Python projects from an agent.
5
+ Author: NeuroMomentum DOO
6
+ License: MIT
7
+ Keywords: mcp,python,static-analysis,code-review
8
+ Requires-Python: >=3.9
9
+ Description-Content-Type: text/markdown
10
+
11
+ # archscan-mcp
12
+
13
+ The NeuroScan MCP server (stdio): five tools an agent can call against a Python project.
14
+
15
+ - `archscan_account` — balance, free projects, limits
16
+ - `archscan_analyze` — a local zip path or a public GitHub repo
17
+ - `archscan_status` — job status and findings
18
+ - `archscan_fix` — fix every finding or selected ids; `dry_run` prices it first
19
+ - `archscan_download` — save the patched project or HTML report
20
+
21
+ ## Install
22
+
23
+ ```bash
24
+ pipx install archscan-mcp
25
+ ```
26
+
27
+ or run from a checkout:
28
+
29
+ ```bash
30
+ python3 /opt/neuroscan/mcp/archscan_mcp.py
31
+ ```
32
+
33
+ ## Configure
34
+
35
+ ```json
36
+ {
37
+ "mcpServers": {
38
+ "archscan": {
39
+ "command": "archscan-mcp",
40
+ "env": {
41
+ "ARCHSCAN_API_KEY": "ask_...",
42
+ "ARCHSCAN_BASE": "https://neuromomen.com"
43
+ }
44
+ }
45
+ }
46
+ }
47
+ ```
48
+
49
+ Get an API key at https://neuromomen.com/account. The server speaks MCP `2025-06-18` over stdin/stdout and has no
50
+ third-party dependencies.
51
+
52
+ ## Tools
53
+
54
+ Every tool returns the same JSON shape as the HTTP API (`/api/v1/openapi.json`). Failures are `isError: true` with
55
+ `class` and `next` intact.
56
+
57
+ Analysis is free; `archscan_fix` spends the account's token balance. Use `dry_run: true` first.
58
+
59
+ ## Development
60
+
61
+ ```bash
62
+ python3 -m pip install build
63
+ python3 -m build
64
+ python3 -m pip install dist/archscan_mcp-0.1.0-py3-none-any.whl
65
+ printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"probe","version":"0"}}}' | archscan-mcp
66
+ ```
@@ -0,0 +1,6 @@
1
+ archscan_mcp.py,sha256=RQqmKxyGe6kh5pu1E2XxjukiCQ5gc3jhZDEgMJ4wock,8562
2
+ archscan_mcp-0.1.0.dist-info/METADATA,sha256=zhpgqR50nOlhZS3qNTpraTSl21lzbhgTRdgqISRzTLY,1780
3
+ archscan_mcp-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
4
+ archscan_mcp-0.1.0.dist-info/entry_points.txt,sha256=OmdFok5xnxkT5uqmXdgMUwIAeHKPT0yM-3tte6xtob0,51
5
+ archscan_mcp-0.1.0.dist-info/top_level.txt,sha256=iguk3PpudmVXD49EZtoS2d5xRcjHej3MY54Mb2U9bv0,13
6
+ archscan_mcp-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ archscan-mcp = archscan_mcp:main
@@ -0,0 +1 @@
1
+ archscan_mcp
archscan_mcp.py ADDED
@@ -0,0 +1,187 @@
1
+ #!/usr/bin/env python3
2
+ """ArchScan MCP server (stdio): the product as four tools an agent can call.
3
+
4
+ {"mcpServers": {"archscan": {"command": "python3",
5
+ "args": ["/opt/archscan/mcp/archscan_mcp.py"],
6
+ "env": {"ARCHSCAN_API_KEY": "ask_..."}}}}
7
+
8
+ Tools: archscan_analyze, archscan_status, archscan_fix, archscan_download, archscan_account. Every tool returns the
9
+ same JSON the HTTP API returns, so an agent that has read /api/v1/openapi.json already knows the shape. Failures are
10
+ `isError: true` with the class/next fields intact.
11
+
12
+ Implemented against the protocol by hand (initialize / tools/list / tools/call) so it runs with the system python and
13
+ no packages: an MCP server that needs `pip install` before it can talk is one more thing between the user and a call.
14
+ """
15
+ import json
16
+ import os
17
+ import pathlib
18
+ import sys
19
+ import time
20
+ import urllib.error
21
+ import urllib.request
22
+
23
+ BASE = (os.environ.get("ARCHSCAN_BASE") or "https://neuromomen.com").rstrip("/")
24
+ KEY = os.environ.get("ARCHSCAN_API_KEY") or ""
25
+ PROTOCOL = "2025-06-18"
26
+
27
+
28
+ def call(method, path, body=None, files=None, raw=False):
29
+ headers = {"Authorization": "Bearer " + KEY}
30
+ data = None
31
+ if files is not None:
32
+ name, blob = files
33
+ boundary = "----archscanmcp"
34
+ data = (f"--{boundary}\r\nContent-Disposition: form-data; name=\"file\"; filename=\"{name}\"\r\n"
35
+ f"Content-Type: application/zip\r\n\r\n").encode() + blob + f"\r\n--{boundary}--\r\n".encode()
36
+ headers["Content-Type"] = f"multipart/form-data; boundary={boundary}"
37
+ elif body is not None:
38
+ data = json.dumps(body).encode()
39
+ headers["Content-Type"] = "application/json"
40
+ req = urllib.request.Request(BASE + path, data, headers, method=method)
41
+ try:
42
+ with urllib.request.urlopen(req, timeout=600) as r:
43
+ payload = r.read()
44
+ return payload if raw else json.loads(payload or b"{}")
45
+ except urllib.error.HTTPError as e:
46
+ try:
47
+ err = json.loads(e.read())
48
+ except Exception:
49
+ err = {"detail": f"HTTP {e.code}"}
50
+ err.setdefault("ok", False)
51
+ err.setdefault("class", "http")
52
+ err["status"] = e.code
53
+ return err
54
+ except Exception as e:
55
+ return {"ok": False, "class": "server", "reason": f"{type(e).__name__}: {e}",
56
+ "next": "check ARCHSCAN_BASE and the network"}
57
+
58
+
59
+ TOOLS = [
60
+ {"name": "archscan_account", "description": "Balance, free projects and this run's limits.",
61
+ "inputSchema": {"type": "object", "properties": {}}},
62
+ {"name": "archscan_analyze",
63
+ "description": "Analyse a Python project: send a local zip path or a public GitHub repo. Analysis is free; "
64
+ "warm=true also pre-decides the patches (costs tokens, makes the fix instant).",
65
+ "inputSchema": {"type": "object", "properties": {
66
+ "zip": {"type": "string", "description": "absolute path to a .zip of the project"},
67
+ "repo": {"type": "string", "description": "owner/name on GitHub, instead of a zip"},
68
+ "warm": {"type": "boolean"}, "summaries": {"type": "boolean"}},
69
+ "anyOf": [{"required": ["zip"]}, {"required": ["repo"]}]}},
70
+ {"name": "archscan_status",
71
+ "description": "Job status and findings. Call it until status is done; ids in issues[] are what archscan_fix "
72
+ "takes. full=true adds the graph.",
73
+ "inputSchema": {"type": "object", "properties": {"job": {"type": "string"}, "full": {"type": "boolean"}},
74
+ "required": ["job"]}},
75
+ {"name": "archscan_fix",
76
+ "description": "Fix every finding, or only the ids you pass. dry_run=true prices it and spends nothing.",
77
+ "inputSchema": {"type": "object", "properties": {
78
+ "job": {"type": "string"}, "issues": {"type": "array", "items": {"type": "integer"}},
79
+ "dry_run": {"type": "boolean"}, "wait": {"type": "boolean",
80
+ "description": "block until the run finishes (up to 10 min)"}},
81
+ "required": ["job"]}},
82
+ {"name": "archscan_download",
83
+ "description": "Save the patched project (or the HTML report) to a local path.",
84
+ "inputSchema": {"type": "object", "properties": {
85
+ "job": {"type": "string"}, "kind": {"enum": ["zip", "report"]},
86
+ "output": {"type": "string", "description": "where to write it; defaults to ./archscan-<job>.zip"}},
87
+ "required": ["job"]}},
88
+ ]
89
+
90
+
91
+ def wait(job, limit=600):
92
+ started = time.time()
93
+ while time.time() - started < limit:
94
+ st = call("GET", f"/api/v1/jobs/{job}")
95
+ if st.get("status") == "done" and not (st.get("fix") or {}).get("running"):
96
+ return st
97
+ time.sleep(2)
98
+ return {"ok": False, "class": "server", "reason": "timed out", "next": f"archscan_status {job}"}
99
+
100
+
101
+ def tool(name, args):
102
+ if name == "archscan_account":
103
+ return call("GET", "/api/v1/me")
104
+ if name == "archscan_analyze":
105
+ q = []
106
+ if args.get("warm"):
107
+ q.append("warm=1")
108
+ if args.get("summaries"):
109
+ q.append("summaries=1")
110
+ path = "/api/v1/projects" + ("?" + "&".join(q) if q else "")
111
+ if args.get("repo"):
112
+ return call("POST", path, body={"repo": args["repo"]})
113
+ p = pathlib.Path(str(args.get("zip") or "")).expanduser()
114
+ if not p.is_file():
115
+ return {"ok": False, "class": "input", "reason": f"no such file: {p}",
116
+ "next": "pass an absolute path to a .zip, or repo"}
117
+ return call("POST", path, files=(p.name, p.read_bytes()))
118
+ if name == "archscan_status":
119
+ return call("GET", f"/api/v1/jobs/{args['job']}" + ("?full=1" if args.get("full") else ""))
120
+ if name == "archscan_fix":
121
+ body = {}
122
+ if args.get("issues"):
123
+ body["issues"] = args["issues"]
124
+ if args.get("dry_run"):
125
+ body["dry_run"] = True
126
+ res = call("POST", f"/api/v1/jobs/{args['job']}/fix", body=body)
127
+ return wait(args["job"]) if args.get("wait") and not args.get("dry_run") and res.get("ok") else res
128
+ if name == "archscan_download":
129
+ kind = args.get("kind") or "zip"
130
+ blob = call("GET", f"/api/v1/jobs/{args['job']}/" + ("download" if kind == "zip" else "report"), raw=True)
131
+ if isinstance(blob, dict):
132
+ return blob
133
+ dest = pathlib.Path(args.get("output") or f"archscan-{args['job'][:8]}.{'zip' if kind == 'zip' else 'html'}")
134
+ dest.write_bytes(blob)
135
+ return {"ok": True, "saved": str(dest.resolve()), "bytes": len(blob)}
136
+ return {"ok": False, "class": "input", "reason": f"no such tool: {name}", "next": "tools/list"}
137
+
138
+
139
+ def reply(rid, result=None, error=None):
140
+ msg = {"jsonrpc": "2.0", "id": rid}
141
+ if error:
142
+ msg["error"] = {"code": -32000, "message": str(error)}
143
+ else:
144
+ msg["result"] = result
145
+ sys.stdout.write(json.dumps(msg) + "\n")
146
+ sys.stdout.flush()
147
+
148
+
149
+ def main():
150
+ if not KEY:
151
+ sys.stderr.write("ARCHSCAN_API_KEY is not set: create a key at /account -> API keys\n")
152
+ for line in sys.stdin:
153
+ line = line.strip()
154
+ if not line:
155
+ continue
156
+ try:
157
+ msg = json.loads(line)
158
+ except Exception:
159
+ continue
160
+ mid, method = msg.get("id"), msg.get("method")
161
+ if method == "initialize":
162
+ reply(mid, {"protocolVersion": PROTOCOL,
163
+ "capabilities": {"tools": {}},
164
+ "serverInfo": {"name": "archscan", "version": "1.0.0"}})
165
+ elif method in ("notifications/initialized", "notifications/cancelled"):
166
+ continue
167
+ elif method == "ping":
168
+ reply(mid, {})
169
+ elif method == "tools/list":
170
+ reply(mid, {"tools": TOOLS})
171
+ elif method == "tools/call":
172
+ params = msg.get("params") or {}
173
+ name = params.get("name")
174
+ args = params.get("arguments") or {}
175
+ try:
176
+ res = tool(name, args)
177
+ except Exception as e: # never kill the server on one bad call
178
+ res = {"ok": False, "class": "server", "reason": f"{type(e).__name__}: {e}"}
179
+ text = json.dumps(res, ensure_ascii=False)
180
+ reply(mid, {"content": [{"type": "text", "text": text}],
181
+ "isError": bool(res.get("ok") is False or res.get("error"))})
182
+ elif mid is not None:
183
+ reply(mid, error=f"unknown method: {method}")
184
+
185
+
186
+ if __name__ == "__main__":
187
+ main()