quilr-local-mcp-runtime 0.3.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.
- quilr_local_mcp_runtime-0.3.0/.gitignore +12 -0
- quilr_local_mcp_runtime-0.3.0/PKG-INFO +74 -0
- quilr_local_mcp_runtime-0.3.0/README.md +63 -0
- quilr_local_mcp_runtime-0.3.0/pyproject.toml +34 -0
- quilr_local_mcp_runtime-0.3.0/src/quilr_mcp/__init__.py +3 -0
- quilr_local_mcp_runtime-0.3.0/src/quilr_mcp/__main__.py +3 -0
- quilr_local_mcp_runtime-0.3.0/src/quilr_mcp/audit.py +141 -0
- quilr_local_mcp_runtime-0.3.0/src/quilr_mcp/cli.py +179 -0
- quilr_local_mcp_runtime-0.3.0/src/quilr_mcp/core.py +301 -0
- quilr_local_mcp_runtime-0.3.0/src/quilr_mcp/enrollment.py +139 -0
- quilr_local_mcp_runtime-0.3.0/src/quilr_mcp/host.py +481 -0
- quilr_local_mcp_runtime-0.3.0/src/quilr_mcp/install.py +214 -0
- quilr_local_mcp_runtime-0.3.0/src/quilr_mcp/packages.py +404 -0
- quilr_local_mcp_runtime-0.3.0/src/quilr_mcp/session.py +385 -0
- quilr_local_mcp_runtime-0.3.0/src/quilr_mcp/transport.py +135 -0
- quilr_local_mcp_runtime-0.3.0/src/quilr_mcp/watchdog.py +61 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: quilr-local-mcp-runtime
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Native Python connector for gateway-governed local MCP tools
|
|
5
|
+
License-Expression: LicenseRef-Proprietary
|
|
6
|
+
Requires-Python: >=3.12
|
|
7
|
+
Requires-Dist: cryptography<49,>=46
|
|
8
|
+
Requires-Dist: httpx<0.29,>=0.28.1
|
|
9
|
+
Requires-Dist: packaging<27,>=24.2
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# Quilr native Python MCP connector
|
|
13
|
+
|
|
14
|
+
Connect approved local MCP tools to your organization's Quilr gateway. Python
|
|
15
|
+
MCPs run in Python; Node MCPs run in Node when Node is installed. The connector
|
|
16
|
+
itself requires only Python 3.12 or newer on macOS or Linux.
|
|
17
|
+
|
|
18
|
+
Use the exact version and gateway supplied by your administrator. Once this
|
|
19
|
+
release is published on PyPI, the one-command setup is:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
uvx --from 'quilr-local-mcp-runtime==0.3.0' quilr-mcp connect --gateway 'https://YOUR-GATEWAY' --organization 'YOUR-ORGANIZATION-UUID' --client cursor
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Alternatively, install persistently with `pipx install
|
|
26
|
+
'quilr-local-mcp-runtime==0.3.0'` or install the reviewed wheel into your own
|
|
27
|
+
virtual environment with `python -m pip install /path/to/reviewed.whl`, then run
|
|
28
|
+
the same `quilr-mcp connect` command. A wheel can be installed directly before
|
|
29
|
+
the release is published. Never run the connector as root.
|
|
30
|
+
|
|
31
|
+
The command configures the selected AI client and opens browser sign-in. Approve
|
|
32
|
+
your computer, then open or restart your AI app. Supported clients are Cursor,
|
|
33
|
+
Claude Code, Claude Desktop on macOS, and VS Code with the `code` command
|
|
34
|
+
installed. `--client other` prints the configuration for another stdio MCP host.
|
|
35
|
+
|
|
36
|
+
The installation stores a stable launcher and its installed dependencies under
|
|
37
|
+
your private connection directory; AI-client startup does not depend on keeping
|
|
38
|
+
the temporary uvx cache. It still needs the OS Python used to connect. Reconnect
|
|
39
|
+
after replacing that interpreter.
|
|
40
|
+
|
|
41
|
+
Ask your AI app to check your Quilr connection and list the permitted tools.
|
|
42
|
+
`quilr_connect` opens browser approval when needed; `quilr_connection_status`
|
|
43
|
+
checks sign-in and package preparation. Credentials never belong in chat.
|
|
44
|
+
Packages install lazily from reviewed, signed definitions. A **Preparing** result
|
|
45
|
+
means the requested tool has not executed; check status and retry once ready.
|
|
46
|
+
|
|
47
|
+
Python dependencies use a private virtual environment and hash-locked PyPI wheels.
|
|
48
|
+
Node dependencies use an npm lockfile with integrity checks and lifecycle scripts
|
|
49
|
+
disabled. Installing a connector through PyPI does not convert Node MCPs into
|
|
50
|
+
Python, and installing through npm does not convert Python MCPs into Node.
|
|
51
|
+
|
|
52
|
+
Tool requests and results pass through the existing gateway policy path. The
|
|
53
|
+
connector does not grant access beyond your organization's policy, intercept
|
|
54
|
+
built-in AI-client tools, or provide an OS sandbox. Each MCP runs as your OS user.
|
|
55
|
+
For tools with internal agents, gateway enforcement covers their exposed MCP
|
|
56
|
+
calls, not every internal browser or model operation.
|
|
57
|
+
|
|
58
|
+
Use the printed connection directory for advanced commands:
|
|
59
|
+
|
|
60
|
+
```sh
|
|
61
|
+
quilr-mcp status --state /absolute/connection-directory
|
|
62
|
+
quilr-mcp list --state /absolute/connection-directory
|
|
63
|
+
quilr-mcp doctor --state /absolute/connection-directory --package PACKAGE_ID
|
|
64
|
+
quilr-mcp disconnect --state /absolute/connection-directory
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Disconnect revokes this connection and removes its local credential while
|
|
68
|
+
preserving package and workspace files. Optional `connect --workspace`,
|
|
69
|
+
`--python` and `--node` select local paths. Provider environment variables stay
|
|
70
|
+
local and are forwarded only when declared in the approved package.
|
|
71
|
+
|
|
72
|
+
Python and npm are alternative connector installations for the same gateway.
|
|
73
|
+
Use one connector per AI-app connection to avoid duplicate tool registrations.
|
|
74
|
+
They use the same enrollment and policy protocol.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Quilr native Python MCP connector
|
|
2
|
+
|
|
3
|
+
Connect approved local MCP tools to your organization's Quilr gateway. Python
|
|
4
|
+
MCPs run in Python; Node MCPs run in Node when Node is installed. The connector
|
|
5
|
+
itself requires only Python 3.12 or newer on macOS or Linux.
|
|
6
|
+
|
|
7
|
+
Use the exact version and gateway supplied by your administrator. Once this
|
|
8
|
+
release is published on PyPI, the one-command setup is:
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
uvx --from 'quilr-local-mcp-runtime==0.3.0' quilr-mcp connect --gateway 'https://YOUR-GATEWAY' --organization 'YOUR-ORGANIZATION-UUID' --client cursor
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Alternatively, install persistently with `pipx install
|
|
15
|
+
'quilr-local-mcp-runtime==0.3.0'` or install the reviewed wheel into your own
|
|
16
|
+
virtual environment with `python -m pip install /path/to/reviewed.whl`, then run
|
|
17
|
+
the same `quilr-mcp connect` command. A wheel can be installed directly before
|
|
18
|
+
the release is published. Never run the connector as root.
|
|
19
|
+
|
|
20
|
+
The command configures the selected AI client and opens browser sign-in. Approve
|
|
21
|
+
your computer, then open or restart your AI app. Supported clients are Cursor,
|
|
22
|
+
Claude Code, Claude Desktop on macOS, and VS Code with the `code` command
|
|
23
|
+
installed. `--client other` prints the configuration for another stdio MCP host.
|
|
24
|
+
|
|
25
|
+
The installation stores a stable launcher and its installed dependencies under
|
|
26
|
+
your private connection directory; AI-client startup does not depend on keeping
|
|
27
|
+
the temporary uvx cache. It still needs the OS Python used to connect. Reconnect
|
|
28
|
+
after replacing that interpreter.
|
|
29
|
+
|
|
30
|
+
Ask your AI app to check your Quilr connection and list the permitted tools.
|
|
31
|
+
`quilr_connect` opens browser approval when needed; `quilr_connection_status`
|
|
32
|
+
checks sign-in and package preparation. Credentials never belong in chat.
|
|
33
|
+
Packages install lazily from reviewed, signed definitions. A **Preparing** result
|
|
34
|
+
means the requested tool has not executed; check status and retry once ready.
|
|
35
|
+
|
|
36
|
+
Python dependencies use a private virtual environment and hash-locked PyPI wheels.
|
|
37
|
+
Node dependencies use an npm lockfile with integrity checks and lifecycle scripts
|
|
38
|
+
disabled. Installing a connector through PyPI does not convert Node MCPs into
|
|
39
|
+
Python, and installing through npm does not convert Python MCPs into Node.
|
|
40
|
+
|
|
41
|
+
Tool requests and results pass through the existing gateway policy path. The
|
|
42
|
+
connector does not grant access beyond your organization's policy, intercept
|
|
43
|
+
built-in AI-client tools, or provide an OS sandbox. Each MCP runs as your OS user.
|
|
44
|
+
For tools with internal agents, gateway enforcement covers their exposed MCP
|
|
45
|
+
calls, not every internal browser or model operation.
|
|
46
|
+
|
|
47
|
+
Use the printed connection directory for advanced commands:
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
quilr-mcp status --state /absolute/connection-directory
|
|
51
|
+
quilr-mcp list --state /absolute/connection-directory
|
|
52
|
+
quilr-mcp doctor --state /absolute/connection-directory --package PACKAGE_ID
|
|
53
|
+
quilr-mcp disconnect --state /absolute/connection-directory
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Disconnect revokes this connection and removes its local credential while
|
|
57
|
+
preserving package and workspace files. Optional `connect --workspace`,
|
|
58
|
+
`--python` and `--node` select local paths. Provider environment variables stay
|
|
59
|
+
local and are forwarded only when declared in the approved package.
|
|
60
|
+
|
|
61
|
+
Python and npm are alternative connector installations for the same gateway.
|
|
62
|
+
Use one connector per AI-app connection to avoid duplicate tool registrations.
|
|
63
|
+
They use the same enrollment and policy protocol.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27,<2"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "quilr-local-mcp-runtime"
|
|
7
|
+
version = "0.3.0"
|
|
8
|
+
description = "Native Python connector for gateway-governed local MCP tools"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
|
+
license = "LicenseRef-Proprietary"
|
|
12
|
+
dependencies = ["httpx>=0.28.1,<0.29", "cryptography>=46,<49", "packaging>=24.2,<27"]
|
|
13
|
+
|
|
14
|
+
[project.scripts]
|
|
15
|
+
quilr-mcp = "quilr_mcp.cli:main"
|
|
16
|
+
|
|
17
|
+
[tool.hatch.build]
|
|
18
|
+
exclude = [".gitignore", "**/__pycache__", "**/*.pyc"]
|
|
19
|
+
|
|
20
|
+
[tool.hatch.build.targets.wheel]
|
|
21
|
+
packages = ["src/quilr_mcp"]
|
|
22
|
+
|
|
23
|
+
[tool.hatch.build.targets.sdist]
|
|
24
|
+
include = ["src/quilr_mcp", "pyproject.toml", "README.md"]
|
|
25
|
+
|
|
26
|
+
[tool.ruff]
|
|
27
|
+
target-version = "py312"
|
|
28
|
+
line-length = 100
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
[tool.ruff.lint]
|
|
32
|
+
select = ["E4", "E7", "E9", "F", "I", "ASYNC"]
|
|
33
|
+
# Public operations accept a bounded timeout and enforce it with asyncio.timeout.
|
|
34
|
+
ignore = ["ASYNC109"]
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import hashlib
|
|
3
|
+
import os
|
|
4
|
+
import time
|
|
5
|
+
import uuid
|
|
6
|
+
from datetime import UTC, datetime
|
|
7
|
+
|
|
8
|
+
from .core import ConnectorError, alive, dumps, private_dir, read_json, require, save
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def slot(directory, prefix, limit):
|
|
12
|
+
for index in range(limit):
|
|
13
|
+
path = directory / f"{prefix}-{index}.json"
|
|
14
|
+
token = uuid.uuid4().hex
|
|
15
|
+
for _ in range(2):
|
|
16
|
+
try:
|
|
17
|
+
fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
|
|
18
|
+
with os.fdopen(fd, "w") as stream:
|
|
19
|
+
stream.write(dumps({"pid": os.getpid(), "token": token}))
|
|
20
|
+
stream.flush()
|
|
21
|
+
os.fsync(stream.fileno())
|
|
22
|
+
return Reservation(path, token)
|
|
23
|
+
except FileExistsError:
|
|
24
|
+
try:
|
|
25
|
+
owner = read_json(path)
|
|
26
|
+
if not alive(owner.get("pid")) and (
|
|
27
|
+
not owner.get("childPid") or not alive(owner["childPid"])
|
|
28
|
+
):
|
|
29
|
+
claim = path.with_suffix(".json.reap")
|
|
30
|
+
try:
|
|
31
|
+
claim_fd = os.open(claim, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
|
|
32
|
+
except FileExistsError:
|
|
33
|
+
continue
|
|
34
|
+
try:
|
|
35
|
+
if read_json(path).get("token") == owner.get("token"):
|
|
36
|
+
path.unlink()
|
|
37
|
+
finally:
|
|
38
|
+
os.close(claim_fd)
|
|
39
|
+
claim.unlink()
|
|
40
|
+
except (ConnectorError, FileNotFoundError):
|
|
41
|
+
pass
|
|
42
|
+
raise ConnectorError("session_capacity_exhausted")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class Reservation:
|
|
46
|
+
def __init__(self, path, token):
|
|
47
|
+
self.path, self.token = path, token
|
|
48
|
+
|
|
49
|
+
def attach(self, pid):
|
|
50
|
+
save(self.path, {"pid": os.getpid(), "childPid": pid, "token": self.token})
|
|
51
|
+
|
|
52
|
+
def close(self):
|
|
53
|
+
try:
|
|
54
|
+
if read_json(self.path).get("token") == self.token:
|
|
55
|
+
self.path.unlink()
|
|
56
|
+
except FileNotFoundError:
|
|
57
|
+
pass
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class Audit:
|
|
61
|
+
def __init__(self, root, package_id, revision, settings):
|
|
62
|
+
directory = private_dir(root / "sessions")
|
|
63
|
+
self.locks = private_dir(directory / "locks")
|
|
64
|
+
self.directory = private_dir(directory / "audit")
|
|
65
|
+
self.scope = {
|
|
66
|
+
"tenantId": settings["identity"]["tenant_id"],
|
|
67
|
+
"subscriberId": settings["identity"]["subscriber_id"],
|
|
68
|
+
"userId": settings["identity"]["id"],
|
|
69
|
+
"deviceId": settings["id"],
|
|
70
|
+
}
|
|
71
|
+
identity = hashlib.sha256(dumps(list(self.scope.values())).encode()).hexdigest()[:24]
|
|
72
|
+
self.reservations = [slot(self.locks, "device-" + identity, 8)]
|
|
73
|
+
try:
|
|
74
|
+
self.reservations.append(slot(self.locks, f"installation-{identity}-{package_id}", 2))
|
|
75
|
+
self.session_id = str(uuid.uuid4())
|
|
76
|
+
self.fd = os.open(
|
|
77
|
+
self.directory / (self.session_id + ".jsonl"),
|
|
78
|
+
os.O_WRONLY | os.O_CREAT | os.O_EXCL,
|
|
79
|
+
0o600,
|
|
80
|
+
)
|
|
81
|
+
except BaseException:
|
|
82
|
+
for item in self.reservations:
|
|
83
|
+
item.close()
|
|
84
|
+
raise
|
|
85
|
+
self.package_id, self.revision = package_id, revision
|
|
86
|
+
self.sequence, self.previous = 0, "0" * 64
|
|
87
|
+
|
|
88
|
+
def attach(self, pid):
|
|
89
|
+
for reservation in self.reservations:
|
|
90
|
+
reservation.attach(pid)
|
|
91
|
+
|
|
92
|
+
async def append(self, event, **fields):
|
|
93
|
+
deadline = time.monotonic() + 0.5
|
|
94
|
+
while True:
|
|
95
|
+
try:
|
|
96
|
+
reservation = slot(self.locks, "audit-budget", 1)
|
|
97
|
+
break
|
|
98
|
+
except ConnectorError:
|
|
99
|
+
require(time.monotonic() < deadline, "audit_budget_unavailable")
|
|
100
|
+
await asyncio.sleep(0.005)
|
|
101
|
+
try:
|
|
102
|
+
files = list(self.directory.iterdir())
|
|
103
|
+
require(
|
|
104
|
+
len(files) <= 10000 and all(p.is_file() and not p.is_symlink() for p in files),
|
|
105
|
+
"invalid_audit_file",
|
|
106
|
+
)
|
|
107
|
+
self.sequence += 1
|
|
108
|
+
record = {
|
|
109
|
+
"schemaVersion": 1,
|
|
110
|
+
"timestamp": datetime.now(UTC).isoformat(),
|
|
111
|
+
"sessionId": self.session_id,
|
|
112
|
+
"sequence": self.sequence,
|
|
113
|
+
"previousHash": self.previous,
|
|
114
|
+
"installationId": self.package_id,
|
|
115
|
+
"revision": self.revision,
|
|
116
|
+
"scope": self.scope,
|
|
117
|
+
"event": event,
|
|
118
|
+
**fields,
|
|
119
|
+
}
|
|
120
|
+
digest = hashlib.sha256(dumps(record).encode()).hexdigest()
|
|
121
|
+
data = (dumps({**record, "hash": digest}) + "\n").encode()
|
|
122
|
+
require(
|
|
123
|
+
sum(p.stat().st_size for p in files) + len(data) <= 32 * 1024 * 1024,
|
|
124
|
+
"audit_capacity_exhausted",
|
|
125
|
+
)
|
|
126
|
+
view = memoryview(data)
|
|
127
|
+
while view:
|
|
128
|
+
written = os.write(self.fd, view)
|
|
129
|
+
require(written > 0, "audit_write_failed")
|
|
130
|
+
view = view[written:]
|
|
131
|
+
os.fsync(self.fd)
|
|
132
|
+
self.previous = digest
|
|
133
|
+
finally:
|
|
134
|
+
reservation.close()
|
|
135
|
+
|
|
136
|
+
def close(self):
|
|
137
|
+
if self.fd is not None:
|
|
138
|
+
os.close(self.fd)
|
|
139
|
+
self.fd = None
|
|
140
|
+
for reservation in self.reservations:
|
|
141
|
+
reservation.close()
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import asyncio
|
|
3
|
+
import hashlib
|
|
4
|
+
import os
|
|
5
|
+
import sys
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from . import __version__
|
|
9
|
+
from .core import (
|
|
10
|
+
ORGANIZATION,
|
|
11
|
+
PACKAGE_ID,
|
|
12
|
+
Gateway,
|
|
13
|
+
dumps,
|
|
14
|
+
gateway_url,
|
|
15
|
+
private_dir,
|
|
16
|
+
read_json,
|
|
17
|
+
require,
|
|
18
|
+
safe_code,
|
|
19
|
+
)
|
|
20
|
+
from .enrollment import enrollment, open_browser
|
|
21
|
+
from .host import run_host
|
|
22
|
+
from .install import install_client
|
|
23
|
+
from .packages import setup_package, verify_installation, verify_package
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def parser():
|
|
27
|
+
cli = argparse.ArgumentParser(
|
|
28
|
+
prog="quilr-mcp",
|
|
29
|
+
description="Native Python connector for Quilr-governed MCPs. Python 3.12+, macOS/Linux.",
|
|
30
|
+
)
|
|
31
|
+
cli.add_argument("--version", action="version", version=__version__)
|
|
32
|
+
commands = cli.add_subparsers(dest="command", required=True)
|
|
33
|
+
for name in ("connect", "host", "status", "list", "disconnect", "setup", "doctor"):
|
|
34
|
+
command = commands.add_parser(name)
|
|
35
|
+
command.add_argument("--state", type=Path)
|
|
36
|
+
if name == "connect":
|
|
37
|
+
command.add_argument("--gateway", required=True)
|
|
38
|
+
command.add_argument("--organization")
|
|
39
|
+
command.add_argument(
|
|
40
|
+
"--client",
|
|
41
|
+
choices=("cursor", "claude-code", "claude-desktop", "vscode", "other"),
|
|
42
|
+
required=True,
|
|
43
|
+
)
|
|
44
|
+
command.add_argument("--allow-loopback-http", action="store_true")
|
|
45
|
+
command.add_argument("--no-browser", action="store_true")
|
|
46
|
+
if name in ("connect", "setup"):
|
|
47
|
+
command.add_argument("--workspace", type=Path)
|
|
48
|
+
command.add_argument("--python")
|
|
49
|
+
command.add_argument("--node")
|
|
50
|
+
if name in ("setup", "doctor"):
|
|
51
|
+
command.add_argument("--package", required=True)
|
|
52
|
+
return cli
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
async def execute(args):
|
|
56
|
+
require(
|
|
57
|
+
os.name == "posix" and hasattr(os, "getuid") and os.getuid() != 0, "ordinary_user_required"
|
|
58
|
+
)
|
|
59
|
+
require(sys.version_info >= (3, 12), "python_312_required")
|
|
60
|
+
if args.command == "connect":
|
|
61
|
+
gateway = gateway_url(args.gateway, args.allow_loopback_http)
|
|
62
|
+
require(
|
|
63
|
+
not args.organization or ORGANIZATION.fullmatch(args.organization),
|
|
64
|
+
"invalid_organization",
|
|
65
|
+
)
|
|
66
|
+
key = hashlib.sha256((gateway + "\n" + (args.organization or "")).encode()).hexdigest()[:24]
|
|
67
|
+
root = private_dir(args.state or Path.home() / ".quilr-mcp/connections" / key)
|
|
68
|
+
options = {
|
|
69
|
+
"gateway": gateway,
|
|
70
|
+
"organization": args.organization,
|
|
71
|
+
"client": args.client,
|
|
72
|
+
"noBrowser": args.no_browser,
|
|
73
|
+
"python": args.python,
|
|
74
|
+
"node": args.node,
|
|
75
|
+
"workspace": str(args.workspace.resolve(strict=True)) if args.workspace else None,
|
|
76
|
+
}
|
|
77
|
+
else:
|
|
78
|
+
root = private_dir(args.state or Path.home() / ".quilr-mcp")
|
|
79
|
+
if args.command == "host":
|
|
80
|
+
await run_host(root)
|
|
81
|
+
return
|
|
82
|
+
gateway = Gateway()
|
|
83
|
+
try:
|
|
84
|
+
if args.command == "connect":
|
|
85
|
+
print("Connecting Quilr to your AI app…", file=sys.stderr)
|
|
86
|
+
installed = await install_client(root, options)
|
|
87
|
+
state = await enrollment(gateway, root, options, start=True)
|
|
88
|
+
if state["state"] == "awaiting_approval":
|
|
89
|
+
print(
|
|
90
|
+
"Approve this connection in your browser:\n" + state["verificationUrl"],
|
|
91
|
+
file=sys.stderr,
|
|
92
|
+
)
|
|
93
|
+
if not args.no_browser:
|
|
94
|
+
open_browser(state["verificationUrl"])
|
|
95
|
+
while state["state"] == "awaiting_approval":
|
|
96
|
+
await asyncio.sleep(3)
|
|
97
|
+
state = await enrollment(gateway, root, options)
|
|
98
|
+
require(
|
|
99
|
+
state["state"] == "connected",
|
|
100
|
+
"connection_revoked" if state["state"] == "revoked" else "pairing_expired",
|
|
101
|
+
)
|
|
102
|
+
print(
|
|
103
|
+
dumps(
|
|
104
|
+
{
|
|
105
|
+
**installed,
|
|
106
|
+
"connected": True,
|
|
107
|
+
"connectorRuntime": "python",
|
|
108
|
+
"account": read_json(root / "connector.json")["identity"]["email"],
|
|
109
|
+
"next": "Open or restart your AI app. Approve its Quilr connection if prompted. Permitted packages prepare when you first use their tools.",
|
|
110
|
+
}
|
|
111
|
+
)
|
|
112
|
+
)
|
|
113
|
+
return
|
|
114
|
+
settings = read_json(root / "connector.json")
|
|
115
|
+
if args.command in ("status", "list"):
|
|
116
|
+
print(
|
|
117
|
+
dumps(
|
|
118
|
+
await gateway.api(
|
|
119
|
+
settings, "/me" if args.command == "status" else "/me/packages"
|
|
120
|
+
)
|
|
121
|
+
)
|
|
122
|
+
)
|
|
123
|
+
elif args.command == "disconnect":
|
|
124
|
+
try:
|
|
125
|
+
await gateway.api(settings, "/me", "DELETE")
|
|
126
|
+
except Exception as error:
|
|
127
|
+
if safe_code(error) != "gateway_http_401":
|
|
128
|
+
raise
|
|
129
|
+
(root / "connector.json").unlink()
|
|
130
|
+
print(dumps({"disconnected": True}))
|
|
131
|
+
else:
|
|
132
|
+
require(PACKAGE_ID.fullmatch(args.package), "invalid_package_id")
|
|
133
|
+
if args.command == "setup":
|
|
134
|
+
options = {
|
|
135
|
+
"python": args.python,
|
|
136
|
+
"node": args.node,
|
|
137
|
+
"workspace": str(args.workspace.resolve(strict=True))
|
|
138
|
+
if args.workspace
|
|
139
|
+
else str(Path.cwd()),
|
|
140
|
+
}
|
|
141
|
+
print(dumps(await setup_package(gateway, root, args.package, options)))
|
|
142
|
+
elif args.command == "doctor":
|
|
143
|
+
await gateway.api(settings, "/me")
|
|
144
|
+
bundle = verify_package(
|
|
145
|
+
await gateway.api(settings, f"/me/packages/{args.package}/bundle"),
|
|
146
|
+
settings,
|
|
147
|
+
args.package,
|
|
148
|
+
)
|
|
149
|
+
installed, _ = verify_installation(root, args.package, bundle)
|
|
150
|
+
missing = [
|
|
151
|
+
n for n in bundle["definition"].get("environment", []) if not os.environ.get(n)
|
|
152
|
+
]
|
|
153
|
+
print(
|
|
154
|
+
dumps(
|
|
155
|
+
{
|
|
156
|
+
"ready": not missing,
|
|
157
|
+
"connected": True,
|
|
158
|
+
"integrity": "verified",
|
|
159
|
+
"runtime": bundle["definition"]["runtime"],
|
|
160
|
+
"workspace": installed["workspace"],
|
|
161
|
+
"missingEnvironment": missing,
|
|
162
|
+
}
|
|
163
|
+
)
|
|
164
|
+
)
|
|
165
|
+
if missing:
|
|
166
|
+
raise SystemExit(1)
|
|
167
|
+
finally:
|
|
168
|
+
await gateway.close()
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def main():
|
|
172
|
+
args = parser().parse_args()
|
|
173
|
+
try:
|
|
174
|
+
asyncio.run(execute(args))
|
|
175
|
+
except (KeyboardInterrupt, asyncio.CancelledError):
|
|
176
|
+
raise SystemExit(130) from None
|
|
177
|
+
except Exception as error:
|
|
178
|
+
print("Quilr connector: " + safe_code(error), file=sys.stderr)
|
|
179
|
+
raise SystemExit(1) from None
|