aiohttp-tiny-mcp 0.5.9__tar.gz → 0.6.1__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.
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/PKG-INFO +2 -2
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/README.md +1 -1
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/pyproject.toml +1 -1
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/pyproject.toml.orig +1 -1
- aiohttp_tiny_mcp-0.6.1/src/aiohttp_tiny_mcp/access_log.py +73 -0
- aiohttp_tiny_mcp-0.6.1/src/aiohttp_tiny_mcp/console/__init__.py +211 -0
- aiohttp_tiny_mcp-0.6.1/src/aiohttp_tiny_mcp/console/agent-config.js +111 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/console/console.css +38 -4
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/console/console.js +468 -43
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/console/index.html +54 -7
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/server/http.py +13 -3
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/server/sse.py +4 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/storage/sqlite.py +1 -0
- aiohttp_tiny_mcp-0.5.9/src/aiohttp_tiny_mcp/console/__init__.py +0 -118
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/LICENSE +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/auth/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/auth/jwt.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/client/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/client/base.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/client/callback.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/client/http.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/client/loopback.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/client/oauth.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/client/oauth_helpers.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/client/stdio.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/console/oauth-callback.html +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/extensions/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/extensions/skills.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/oauth/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/oauth/github.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/oauth/provider.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/oauth/server.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/oauth/tokens.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/protocol/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/protocol/adapter.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/protocol/core.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/protocol/models.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/protocol/schema.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/protocol/selection.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/protocol/v2024_11_05.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/protocol/v2025_03_26.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/protocol/v2025_06_18.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/protocol/v2025_11_25.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/protocol/v2026_07_28.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/py.typed +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/server/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/server/dispatcher.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/server/exchange.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/server/registry.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/server/request_state.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/server/specs.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/server/stdio.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/server/subscriptions.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/server/tasks.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/storage/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/storage/hub.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/storage/namespaces.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/storage/postgres.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/storage/redis.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/storage/sessions.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/testing.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/transport/__init__.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/transport/metadata.py +0 -0
- {aiohttp_tiny_mcp-0.5.9 → aiohttp_tiny_mcp-0.6.1}/src/aiohttp_tiny_mcp/transport/sse.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: aiohttp-tiny-mcp
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.1
|
|
4
4
|
Summary: Remote MCP server and client library for aiohttp
|
|
5
5
|
License-Expression: Apache-2.0
|
|
6
6
|
License-File: LICENSE
|
|
@@ -200,7 +200,7 @@ automatically. See [Asking the user](https://mosquito.github.io/aiohttp-tiny-mcp
|
|
|
200
200
|
|
|
201
201
|
[MCP Chat](examples/mcp-chat/README.md) is a runnable team chat for AI agents
|
|
202
202
|
and people. Agents use MCP tools; people use the web UI. It provides channels,
|
|
203
|
-
direct messages, threads, subscriptions, persistent inboxes, and full-text
|
|
203
|
+
direct messages, threads, subscriptions, @mentions, persistent inboxes, and full-text
|
|
204
204
|
search within each organization. Live MCP notifications deliver updates, with
|
|
205
205
|
polling as a fallback. Optional JWT authentication binds each agent to an
|
|
206
206
|
organization and user, and Observe shows its activity.
|
|
@@ -156,7 +156,7 @@ automatically. See [Asking the user](https://mosquito.github.io/aiohttp-tiny-mcp
|
|
|
156
156
|
|
|
157
157
|
[MCP Chat](examples/mcp-chat/README.md) is a runnable team chat for AI agents
|
|
158
158
|
and people. Agents use MCP tools; people use the web UI. It provides channels,
|
|
159
|
-
direct messages, threads, subscriptions, persistent inboxes, and full-text
|
|
159
|
+
direct messages, threads, subscriptions, @mentions, persistent inboxes, and full-text
|
|
160
160
|
search within each organization. Live MCP notifications deliver updates, with
|
|
161
161
|
polling as a fallback. Optional JWT authentication binds each agent to an
|
|
162
162
|
organization and user, and Observe shows its activity.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Aiohttp access logging without token query values."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
from urllib.parse import unquote_plus
|
|
7
|
+
|
|
8
|
+
from aiohttp.log import access_logger
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def mask_token(url: str) -> str:
|
|
12
|
+
"""Mask each token query value while preserving the rest of the URL."""
|
|
13
|
+
path, separator, remaining = url.partition("?")
|
|
14
|
+
if not separator:
|
|
15
|
+
return url
|
|
16
|
+
query, fragment_separator, fragment = remaining.partition("#")
|
|
17
|
+
fields = []
|
|
18
|
+
for field in query.split("&"):
|
|
19
|
+
name, equals, value = field.partition("=")
|
|
20
|
+
if equals and unquote_plus(name).casefold() == "token":
|
|
21
|
+
field = f"{name}=[REDACTED]"
|
|
22
|
+
fields.append(field)
|
|
23
|
+
return path + separator + "&".join(fields) + fragment_separator + fragment
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def mask_request_line(value: str) -> str:
|
|
27
|
+
"""Mask the request target without changing the method or protocol."""
|
|
28
|
+
method, separator, target = value.partition(" ")
|
|
29
|
+
url, protocol_separator, protocol = target.rpartition(" ")
|
|
30
|
+
return method + separator + mask_token(url) + protocol_separator + protocol
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class TokenQueryFilter(logging.Filter):
|
|
34
|
+
"""Remove token query values from standard aiohttp access log records."""
|
|
35
|
+
|
|
36
|
+
def filter(self, record: logging.LogRecord) -> bool:
|
|
37
|
+
replacements: dict[str, str] = {}
|
|
38
|
+
request_line = getattr(record, "first_request_line", None)
|
|
39
|
+
if isinstance(request_line, str):
|
|
40
|
+
masked = mask_request_line(request_line)
|
|
41
|
+
if masked != request_line:
|
|
42
|
+
replacements[request_line] = masked
|
|
43
|
+
record.first_request_line = masked
|
|
44
|
+
for key in ("request_header", "response_header"):
|
|
45
|
+
headers = getattr(record, key, None)
|
|
46
|
+
if not isinstance(headers, dict):
|
|
47
|
+
continue
|
|
48
|
+
redacted = dict(headers)
|
|
49
|
+
for name, value in headers.items():
|
|
50
|
+
if not isinstance(value, str):
|
|
51
|
+
continue
|
|
52
|
+
masked = mask_token(value)
|
|
53
|
+
if masked != value:
|
|
54
|
+
replacements[value] = masked
|
|
55
|
+
redacted[name] = masked
|
|
56
|
+
setattr(record, key, redacted)
|
|
57
|
+
if replacements:
|
|
58
|
+
message = record.getMessage()
|
|
59
|
+
for value in sorted(replacements, key=len, reverse=True):
|
|
60
|
+
message = message.replace(value, replacements[value])
|
|
61
|
+
record.msg = message
|
|
62
|
+
record.args = ()
|
|
63
|
+
if hasattr(record, "message"):
|
|
64
|
+
record.message = message
|
|
65
|
+
return True
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
TOKEN_QUERY_FILTER = TokenQueryFilter()
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def install_token_filter() -> None:
|
|
72
|
+
"""Enable token masking once without replacing aiohttp logging configuration."""
|
|
73
|
+
access_logger.addFilter(TOKEN_QUERY_FILTER)
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"""Optional HTML console for an MCP endpoint."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import logging
|
|
7
|
+
from collections.abc import Mapping, Sequence
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from html import escape
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Any, Literal
|
|
12
|
+
from urllib.parse import urlsplit
|
|
13
|
+
|
|
14
|
+
from aiohttp import web
|
|
15
|
+
from pydantic import BaseModel
|
|
16
|
+
|
|
17
|
+
from aiohttp_tiny_mcp.protocol.schema import inline_refs
|
|
18
|
+
|
|
19
|
+
log = logging.getLogger("aiohttp_tiny_mcp")
|
|
20
|
+
|
|
21
|
+
HERE = Path(__file__).parent
|
|
22
|
+
|
|
23
|
+
FILES = {
|
|
24
|
+
"": ("index.html", "text/html"),
|
|
25
|
+
"console.js": ("console.js", "application/javascript"),
|
|
26
|
+
"agent-config.js": ("agent-config.js", "application/javascript"),
|
|
27
|
+
"console.css": ("console.css", "text/css"),
|
|
28
|
+
"oauth-callback": ("oauth-callback.html", "text/html"),
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def check_query_property(property_schema: dict[str, Any], name: str, *, item: bool = False) -> None:
|
|
33
|
+
"""Require one scalar type or a list of scalars, with optional nullability."""
|
|
34
|
+
branches = property_schema.get("anyOf", property_schema.get("oneOf"))
|
|
35
|
+
if branches is not None:
|
|
36
|
+
candidates = [branch for branch in branches if branch.get("type") != "null"]
|
|
37
|
+
if len(candidates) != 1:
|
|
38
|
+
raise ValueError(f"Query parameter {name!r} must have one non-null type.")
|
|
39
|
+
check_query_property(candidates[0], name, item=item)
|
|
40
|
+
return
|
|
41
|
+
kind = property_schema.get("type")
|
|
42
|
+
if isinstance(kind, list):
|
|
43
|
+
kinds = set(kind) - {"null"}
|
|
44
|
+
if len(kinds) > 1:
|
|
45
|
+
raise ValueError(f"Query parameter {name!r} must have one non-null type.")
|
|
46
|
+
kind = next(iter(kinds), "null")
|
|
47
|
+
if kind == "array" and not item:
|
|
48
|
+
items = property_schema.get("items", {})
|
|
49
|
+
check_query_property(items, name, item=True)
|
|
50
|
+
return
|
|
51
|
+
if kind not in {"string", "integer", "number", "boolean", "null"}:
|
|
52
|
+
raise ValueError(f"Query parameter {name!r} must be a scalar or a list of scalars.")
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@dataclass(frozen=True)
|
|
56
|
+
class ConsoleEndpoint:
|
|
57
|
+
"""Describe an existing MCP route and its query fields for the console."""
|
|
58
|
+
|
|
59
|
+
path: str
|
|
60
|
+
description: str
|
|
61
|
+
query: type[BaseModel] | None = None
|
|
62
|
+
auth: Sequence[Literal["none", "basic", "bearer", "query", "custom", "oauth"]] | None = None
|
|
63
|
+
|
|
64
|
+
def definition(self) -> dict[str, Any]:
|
|
65
|
+
"""Return validated, JSON-compatible endpoint metadata."""
|
|
66
|
+
if (
|
|
67
|
+
not isinstance(self.path, str)
|
|
68
|
+
or not self.path.startswith("/")
|
|
69
|
+
or self.path.startswith("//")
|
|
70
|
+
or "\\" in self.path
|
|
71
|
+
or "#" in self.path
|
|
72
|
+
or any(ord(character) < 32 or ord(character) == 127 for character in self.path)
|
|
73
|
+
):
|
|
74
|
+
raise ValueError("A console endpoint needs a root-relative path without a fragment.")
|
|
75
|
+
address = urlsplit(self.path)
|
|
76
|
+
if address.scheme or address.netloc:
|
|
77
|
+
raise ValueError("A console endpoint must be on the same origin.")
|
|
78
|
+
if not isinstance(self.description, str) or not self.description.strip():
|
|
79
|
+
raise ValueError("A console endpoint needs a nonempty description.")
|
|
80
|
+
auth = list(self.auth) if self.auth is not None else None
|
|
81
|
+
if auth is not None:
|
|
82
|
+
supported = {"none", "basic", "bearer", "query", "custom", "oauth"}
|
|
83
|
+
if not auth or any(
|
|
84
|
+
not isinstance(method, str) or method not in supported for method in auth
|
|
85
|
+
):
|
|
86
|
+
raise ValueError(
|
|
87
|
+
"Console endpoint auth must contain supported authentication types."
|
|
88
|
+
)
|
|
89
|
+
if len(auth) != len(set(auth)):
|
|
90
|
+
raise ValueError("Console endpoint authentication types must be unique.")
|
|
91
|
+
schema: dict[str, Any] = {"type": "object", "properties": {}}
|
|
92
|
+
if self.query is not None:
|
|
93
|
+
if not isinstance(self.query, type) or not issubclass(self.query, BaseModel):
|
|
94
|
+
raise ValueError("A console endpoint query must be a Pydantic model class.")
|
|
95
|
+
try:
|
|
96
|
+
schema = inline_refs(self.query.model_json_schema())
|
|
97
|
+
except RecursionError as error:
|
|
98
|
+
raise ValueError("Recursive console query models are not supported.") from error
|
|
99
|
+
if schema.get("type") != "object" or "properties" not in schema:
|
|
100
|
+
raise ValueError("A console endpoint query must describe named fields.")
|
|
101
|
+
for name, property_schema in schema["properties"].items():
|
|
102
|
+
check_query_property(property_schema, name)
|
|
103
|
+
return {"path": self.path, "description": self.description, "query": schema, "auth": auth}
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class Console:
|
|
107
|
+
"""Serve the console."""
|
|
108
|
+
|
|
109
|
+
def __init__(
|
|
110
|
+
self,
|
|
111
|
+
endpoint_path: str = "/mcp",
|
|
112
|
+
*,
|
|
113
|
+
title: str = "MCP console",
|
|
114
|
+
description: str = "",
|
|
115
|
+
template: str | Path | None = None,
|
|
116
|
+
variables: Mapping[str, str] | None = None,
|
|
117
|
+
oauth_client_id: str | None = None,
|
|
118
|
+
endpoints: Sequence[ConsoleEndpoint] | None = None,
|
|
119
|
+
) -> None:
|
|
120
|
+
self.endpoints = tuple(endpoints or ())
|
|
121
|
+
self.endpoint_definitions = [endpoint.definition() for endpoint in self.endpoints]
|
|
122
|
+
paths = [endpoint.path for endpoint in self.endpoints]
|
|
123
|
+
if len(paths) != len(set(paths)):
|
|
124
|
+
raise ValueError("Console endpoint paths must be unique.")
|
|
125
|
+
if not oauth_client_id and any(
|
|
126
|
+
"oauth" in (definition["auth"] or []) for definition in self.endpoint_definitions
|
|
127
|
+
):
|
|
128
|
+
raise ValueError("Declared OAuth authentication requires oauth_client_id.")
|
|
129
|
+
self.endpoint_path = paths[0] if paths else endpoint_path
|
|
130
|
+
self.title = title
|
|
131
|
+
self.description = description
|
|
132
|
+
self.template = Path(template) if template else HERE / "index.html"
|
|
133
|
+
self.variables = dict(variables or {})
|
|
134
|
+
self.oauth_client_id = oauth_client_id
|
|
135
|
+
|
|
136
|
+
def substitutions(self, base: str) -> dict[str, str]:
|
|
137
|
+
return {
|
|
138
|
+
"ENDPOINT": self.endpoint_path,
|
|
139
|
+
"ENDPOINTS": json.dumps(self.endpoint_definitions),
|
|
140
|
+
"BASE": base,
|
|
141
|
+
"TITLE": self.title,
|
|
142
|
+
"DESCRIPTION": self.description,
|
|
143
|
+
"OAUTH_CLIENT_ID": self.oauth_client_id or "",
|
|
144
|
+
**self.variables,
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
def render(self, name: str, base: str = "/console") -> str:
|
|
148
|
+
source = self.template if name == "index.html" else HERE / name
|
|
149
|
+
text = source.read_text(encoding="utf-8")
|
|
150
|
+
for key, value in self.substitutions(base).items():
|
|
151
|
+
text = text.replace("{{" + key + "}}", escape(str(value), quote=True))
|
|
152
|
+
return text
|
|
153
|
+
|
|
154
|
+
def reached(self, request: web.Request, wanted: str) -> str:
|
|
155
|
+
"""The prefix the browser used, taken from this request.
|
|
156
|
+
|
|
157
|
+
The page prints absolute addresses, and only the request knows them. A
|
|
158
|
+
subapplication adds its prefix to the request path and not to the route,
|
|
159
|
+
so a stored prefix would be wrong there.
|
|
160
|
+
"""
|
|
161
|
+
path = request.path
|
|
162
|
+
if wanted:
|
|
163
|
+
path = path[: -(len(wanted) + 1)]
|
|
164
|
+
return path.rstrip("/")
|
|
165
|
+
|
|
166
|
+
async def handle(self, request: web.Request) -> web.StreamResponse:
|
|
167
|
+
wanted = request.match_info.get("file", "")
|
|
168
|
+
found = FILES.get(wanted)
|
|
169
|
+
if found is None:
|
|
170
|
+
raise web.HTTPNotFound
|
|
171
|
+
name, content_type = found
|
|
172
|
+
return web.Response(
|
|
173
|
+
text=self.render(name, self.reached(request, wanted)),
|
|
174
|
+
content_type=content_type,
|
|
175
|
+
charset="utf-8",
|
|
176
|
+
headers={"Cache-Control": "no-store"},
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
def routes(self, path: str = "/console") -> list[web.RouteDef]:
|
|
180
|
+
"""The page, its assets, and the OAuth callback page."""
|
|
181
|
+
base = path.rstrip("/")
|
|
182
|
+
log.debug("console at %s, for the endpoint at %s", base, self.endpoint_path)
|
|
183
|
+
return [
|
|
184
|
+
web.get(base, self.handle),
|
|
185
|
+
web.get(f"{base}/", self.handle),
|
|
186
|
+
web.get(f"{base}/{{file}}", self.handle),
|
|
187
|
+
]
|
|
188
|
+
|
|
189
|
+
@staticmethod
|
|
190
|
+
def is_public(request: web.Request) -> bool:
|
|
191
|
+
"""Identify a mounted console asset for application authentication middleware.
|
|
192
|
+
|
|
193
|
+
Check the resolved handler, method, and file allowlist. No path prefix
|
|
194
|
+
is trusted, and an unmounted console grants no exemptions.
|
|
195
|
+
"""
|
|
196
|
+
handler = request.match_info.handler
|
|
197
|
+
console = getattr(handler, "__self__", None)
|
|
198
|
+
return (
|
|
199
|
+
request.method in {"GET", "HEAD"}
|
|
200
|
+
and isinstance(console, Console)
|
|
201
|
+
and handler == console.handle
|
|
202
|
+
and request.match_info.get("file", "") in FILES
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
def setup(self, app: web.Application, path: str = "/console") -> web.Application:
|
|
206
|
+
log.debug("adding the console routes to %r", app)
|
|
207
|
+
app.add_routes(self.routes(path))
|
|
208
|
+
return app
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
__all__ = ["Console", "ConsoleEndpoint"]
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function agentConfigurations({endpoint, name = 'mcp', headers = {}, level = 'user'} = {}) {
|
|
4
|
+
if (!['project', 'user'].includes(level)) {
|
|
5
|
+
throw new Error('Choose Project or User configuration level.');
|
|
6
|
+
}
|
|
7
|
+
if (typeof name !== 'string' || !/^[A-Za-z0-9_-]{1,64}$/.test(name)) {
|
|
8
|
+
throw new Error('Use 1–64 letters, numbers, underscores, or hyphens for the server name.');
|
|
9
|
+
}
|
|
10
|
+
const controls = /[\x00-\x1f\x7f]/;
|
|
11
|
+
const loneSurrogate = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:^|[^\uD800-\uDBFF])[\uDC00-\uDFFF]/;
|
|
12
|
+
if (typeof endpoint !== 'string' || controls.test(endpoint) || loneSurrogate.test(endpoint)
|
|
13
|
+
|| endpoint !== endpoint.trim() || !/^https?:\/\//i.test(endpoint)) {
|
|
14
|
+
throw new Error('Enter an absolute HTTP or HTTPS endpoint URL.');
|
|
15
|
+
}
|
|
16
|
+
let url;
|
|
17
|
+
try {
|
|
18
|
+
url = new URL(endpoint);
|
|
19
|
+
} catch {
|
|
20
|
+
throw new Error('Enter a valid endpoint URL.');
|
|
21
|
+
}
|
|
22
|
+
if (url.username || url.password || endpoint.includes('#')) {
|
|
23
|
+
throw new Error('The endpoint URL must not contain credentials or a fragment.');
|
|
24
|
+
}
|
|
25
|
+
if (!headers || typeof headers !== 'object' || Array.isArray(headers)) {
|
|
26
|
+
throw new Error('Headers must be an object.');
|
|
27
|
+
}
|
|
28
|
+
const entries = Object.entries(headers);
|
|
29
|
+
for (const [key, value] of entries) {
|
|
30
|
+
if (!/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/.test(key)
|
|
31
|
+
|| typeof value !== 'string' || controls.test(value) || loneSurrogate.test(value)) {
|
|
32
|
+
throw new Error('Use valid HTTP header names and values without control characters.');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const credentials = entries.length ? {headers: Object.fromEntries(entries)} : {};
|
|
36
|
+
const server = {url: endpoint, ...credentials};
|
|
37
|
+
const json = value => JSON.stringify(value, null, 2);
|
|
38
|
+
const named = value => ({mcpServers: {[name]: value}});
|
|
39
|
+
const merge = 'Create the file if it does not exist. Merge this server entry with existing settings.';
|
|
40
|
+
const userLevel = level === 'user';
|
|
41
|
+
const file = (projectPath, userPath) => {
|
|
42
|
+
const target = userLevel ? userPath : projectPath;
|
|
43
|
+
const location = userLevel ? 'your home directory for all your projects' : 'your project root';
|
|
44
|
+
return {target, instructions: `Add the configuration below to ${target} in ${location}. ${merge}`};
|
|
45
|
+
};
|
|
46
|
+
const signIn = entries.length || url.searchParams.has('token')
|
|
47
|
+
? '' : ' If the server requires OAuth, sign in from the agent.';
|
|
48
|
+
const tomlHeaders = entries.length
|
|
49
|
+
? '\nhttp_headers = { ' + entries.map(([key, value]) =>
|
|
50
|
+
`${JSON.stringify(key)} = ${JSON.stringify(value)}`).join(', ') + ' }' : '';
|
|
51
|
+
const remote = {type: 'remote', ...server};
|
|
52
|
+
if (entries.length || url.searchParams.has('token')) remote.oauth = false;
|
|
53
|
+
return [
|
|
54
|
+
{
|
|
55
|
+
id: 'mcp-json', label: 'Claude Code',
|
|
56
|
+
...file('.mcp.json', '~/.claude.json'),
|
|
57
|
+
code: json(named({type: 'http', ...server})), language: 'json',
|
|
58
|
+
verify: (userLevel ? 'Start Claude Code and open /mcp.'
|
|
59
|
+
: 'Start Claude Code in this project, approve the server, and open /mcp.') + signIn,
|
|
60
|
+
link: `https://code.claude.com/docs/en/mcp#${level}-scope`,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
id: 'codex', label: 'Codex',
|
|
64
|
+
...file('.codex/config.toml', '~/.codex/config.toml'),
|
|
65
|
+
code: `[mcp_servers.${JSON.stringify(name)}]\nurl = ${JSON.stringify(endpoint)}${tomlHeaders}\n`,
|
|
66
|
+
language: 'toml',
|
|
67
|
+
verify: (userLevel ? '' : 'Trust this project in Codex first. ')
|
|
68
|
+
+ 'Run codex mcp list to check the server.'
|
|
69
|
+
+ (signIn ? ` For OAuth, run codex mcp login ${name}.` : ''),
|
|
70
|
+
link: 'https://learn.chatgpt.com/docs/extend/mcp?surface=cli',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
id: 'cursor', label: 'Cursor',
|
|
74
|
+
...file('.cursor/mcp.json', '~/.cursor/mcp.json'),
|
|
75
|
+
code: json(named(server)), language: 'json',
|
|
76
|
+
verify: 'Open Cursor Settings → Tools & MCP and check the server.' + signIn,
|
|
77
|
+
link: 'https://cursor.com/docs/mcp',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
id: 'copilot', label: 'GitHub Copilot',
|
|
81
|
+
...file('.mcp.json', '~/.copilot/mcp-config.json'),
|
|
82
|
+
code: json(named({type: 'http', ...server, tools: ['*']})), language: 'json',
|
|
83
|
+
verify: 'In VS Code, run MCP: List Servers and start the server.' + signIn,
|
|
84
|
+
link: 'https://code.visualstudio.com/docs/agents/reference/mcp-configuration',
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
id: 'gemini', label: 'Gemini CLI',
|
|
88
|
+
...file('.gemini/settings.json', '~/.gemini/settings.json'),
|
|
89
|
+
code: json(named({httpUrl: endpoint, ...credentials})), language: 'json',
|
|
90
|
+
verify: (userLevel ? 'Start Gemini CLI and open /mcp.'
|
|
91
|
+
: 'Start Gemini CLI in this project and open /mcp.') + signIn,
|
|
92
|
+
link: 'https://geminicli.com/docs/tools/mcp-server/',
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
id: 'pi', label: 'Pi',
|
|
96
|
+
...file('.pi/mcp.json', '~/.pi/agent/mcp.json'),
|
|
97
|
+
code: json(named(server)), language: 'json',
|
|
98
|
+
verify: (userLevel ? 'Start Pi and open /mcp.'
|
|
99
|
+
: 'Trust this project in Pi, then open /mcp.') + signIn,
|
|
100
|
+
link: 'https://docs.pi.dev/latest/mcp',
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
id: 'opencode', label: 'OpenCode V2',
|
|
104
|
+
...file('opencode.json', '~/.config/opencode/opencode.json'),
|
|
105
|
+
code: json({$schema: 'https://opencode.ai/config.json', mcp: {servers: {[name]: remote}}}),
|
|
106
|
+
language: 'json',
|
|
107
|
+
verify: 'Run opencode mcp list to check the server.' + signIn,
|
|
108
|
+
link: 'https://opencode.ai/docs/mcp-servers/',
|
|
109
|
+
},
|
|
110
|
+
];
|
|
111
|
+
}
|
|
@@ -79,6 +79,14 @@ body {
|
|
|
79
79
|
.field.grow > input { flex: 1 1 auto; min-width: 8em; }
|
|
80
80
|
.field > span { color: var(--ink-soft); font-size: 12px; }
|
|
81
81
|
|
|
82
|
+
.endpoint-declared { min-width: 0; }
|
|
83
|
+
.endpoint-declared[hidden] { display: none; }
|
|
84
|
+
.endpoint-declared select { width: 100%; min-width: 0; }
|
|
85
|
+
.endpoint-declared > p { margin: 4px 0; }
|
|
86
|
+
.endpoint-parameters { display: grid; gap: 12px; border: 0; margin: 0; padding: 0; min-width: 0; }
|
|
87
|
+
.endpoint-parameters:empty { display: none; }
|
|
88
|
+
.endpoint-parameters .argument { min-width: 0; margin: 0; }
|
|
89
|
+
|
|
82
90
|
input[type="text"], input[type="password"], input[type="number"], select, textarea {
|
|
83
91
|
font: inherit;
|
|
84
92
|
color: inherit;
|
|
@@ -292,12 +300,21 @@ button.quiet { color: var(--ink-soft); }
|
|
|
292
300
|
.about > :first-child { margin-top: 0; }
|
|
293
301
|
.about > :last-child { margin-bottom: 0; }
|
|
294
302
|
.about p { margin: 0 0 8px; }
|
|
295
|
-
.about h3,
|
|
303
|
+
:is(.about, #question-text) :is(h1, h2, h3, h4, h5, h6, [role="heading"]) {
|
|
296
304
|
color: var(--ink);
|
|
297
|
-
font-size: 13px;
|
|
298
305
|
font-weight: 600;
|
|
299
|
-
|
|
306
|
+
line-height: 1.3;
|
|
307
|
+
margin: 1.2em 0 0.45em;
|
|
308
|
+
overflow-wrap: anywhere;
|
|
300
309
|
}
|
|
310
|
+
:is(.about, #question-text) h1 { font-size: 1.8em; }
|
|
311
|
+
:is(.about, #question-text) h2 { font-size: 1.55em; }
|
|
312
|
+
:is(.about, #question-text) h3 { font-size: 1.35em; }
|
|
313
|
+
:is(.about, #question-text) h4 { font-size: 1.2em; }
|
|
314
|
+
:is(.about, #question-text) h5 { font-size: 1.1em; }
|
|
315
|
+
:is(.about, #question-text) h6 { font-size: 1em; }
|
|
316
|
+
:is(.about, #question-text) [role="heading"][aria-level="7"] { font-size: 0.95em; }
|
|
317
|
+
:is(.about, #question-text) > :first-child { margin-top: 0; }
|
|
301
318
|
.about ul, .about ol { margin: 0 0 10px; padding-left: 18px; }
|
|
302
319
|
.about li { margin: 3px 0; padding-left: 2px; }
|
|
303
320
|
.about li::marker { color: var(--ink-faint); }
|
|
@@ -544,7 +561,24 @@ dialog.question .argument { margin-bottom: 10px; }
|
|
|
544
561
|
|
|
545
562
|
.auth-field { display: flex; flex-direction: column; gap: 4px; margin: 12px 0; }
|
|
546
563
|
.auth-field[hidden] { display: none; }
|
|
547
|
-
.auth-field > input, .auth-field > select {
|
|
564
|
+
.auth-field > input, .auth-field > select {
|
|
565
|
+
width: 100%;
|
|
566
|
+
min-width: 0;
|
|
567
|
+
height: calc(1.5em + 12px);
|
|
568
|
+
line-height: 1.5;
|
|
569
|
+
}
|
|
548
570
|
.auth-endpoint { overflow-wrap: anywhere; font-family: var(--mono); }
|
|
549
571
|
.auth-help { color: var(--ink-soft); font-size: 12px; }
|
|
550
572
|
.auth-error { color: var(--bad); }
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
dialog.agent-setup { max-width: 680px; width: calc(100vw - 32px); max-height: calc(100vh - 32px); overflow: auto; }
|
|
576
|
+
dialog.agent-setup menu { align-items: center; flex-wrap: wrap; }
|
|
577
|
+
#agent-docs { margin-right: auto; }
|
|
578
|
+
.agent-options { display: grid; grid-template-columns: minmax(0, 1.5fr) repeat(2, minmax(0, 1fr)); gap: 12px; }
|
|
579
|
+
#agent-headers-field[hidden] { display: none; }
|
|
580
|
+
.agent-target { font-family: var(--mono); font-weight: 600; overflow-wrap: anywhere; }
|
|
581
|
+
#agent-code { width: 100%; font-family: var(--mono); font-size: 12px; resize: vertical; }
|
|
582
|
+
@media (max-width: 540px) {
|
|
583
|
+
.agent-options { grid-template-columns: 1fr; gap: 0; }
|
|
584
|
+
}
|