feat(quant,lenses,mcp): implement /quant/ time-series workbench, LENS_REGISTRY, TradingView launcher, and /api/v1/* REST + OpenAPI 3.1 adapter (v2.0.18)
This commit is contained in:
1 parent
5841ccea2c
commit
ee5f458c76
27 files changed
+31096
-30
No files matched your search
@@ -28,12 +28,13 @@ from hyperstitionstud_io.mcp.resources import ( # noqa: E402
|
||||
STATIC_RESOURCES,
|
||||
read_mcp_resource,
|
||||
)
|
||||
from hyperstitionstud_io.mcp.rest import dispatch_rest_v1 # noqa: E402
|
||||
from hyperstitionstud_io.mcp.tools import MCP_TOOLS_SCHEMA, call_mcp_tool # noqa: E402
|
||||
|
||||
SERVER_INFO = {
|
||||
"name": "hyperstitionstudio-mcp",
|
||||
"version": "2.0.17",
|
||||
"namespace_urn": "urn:io:hyperstitionstud:mcp:2.0.17",
|
||||
"version": "2.0.18",
|
||||
"namespace_urn": "urn:io:hyperstitionstud:mcp:2.0.18",
|
||||
}
|
||||
|
||||
|
||||
@@ -147,10 +148,13 @@ class _MCPHTTPHandler(BaseHTTPRequestHandler):
|
||||
def log_message(self, format: str, *args: Any) -> None:
|
||||
return
|
||||
|
||||
def _send_json(self, status: int, payload: Any) -> None:
|
||||
body = (json.dumps(payload, indent=2, ensure_ascii=False) + "\n").encode("utf-8")
|
||||
def _send_payload(self, status: int, content_type: str, payload: Any) -> None:
|
||||
if isinstance(payload, str):
|
||||
body = payload.encode("utf-8")
|
||||
else:
|
||||
body = (json.dumps(payload, indent=2, ensure_ascii=False) + "\n").encode("utf-8")
|
||||
self.send_response(status)
|
||||
self.send_header("Content-Type", "application/json; charset=utf-8")
|
||||
self.send_header("Content-Type", content_type)
|
||||
self.send_header("Content-Length", str(len(body)))
|
||||
self.send_header("Access-Control-Allow-Origin", "*")
|
||||
self.send_header("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
|
||||
@@ -158,6 +162,9 @@ class _MCPHTTPHandler(BaseHTTPRequestHandler):
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
|
||||
def _send_json(self, status: int, payload: Any) -> None:
|
||||
self._send_payload(status, "application/json; charset=utf-8", payload)
|
||||
|
||||
def do_OPTIONS(self) -> None:
|
||||
self.send_response(204)
|
||||
self.send_header("Access-Control-Allow-Origin", "*")
|
||||
@@ -166,11 +173,20 @@ class _MCPHTTPHandler(BaseHTTPRequestHandler):
|
||||
self.end_headers()
|
||||
|
||||
def do_GET(self) -> None:
|
||||
if self.path.startswith("/api/v1"):
|
||||
status, ctype, payload = dispatch_rest_v1("GET", self.path)
|
||||
self._send_payload(status, ctype, payload)
|
||||
return
|
||||
manifest = {
|
||||
"serverInfo": SERVER_INFO,
|
||||
"protocols": ["2025-03-26", "2024-11-05"],
|
||||
"transport": "streamable-http",
|
||||
"endpoints": {"jsonrpc_post": "/mcp", "manifest_get": "/mcp"},
|
||||
"endpoints": {
|
||||
"jsonrpc_post": "/mcp",
|
||||
"manifest_get": "/mcp",
|
||||
"rest_api_v1": "/api/v1",
|
||||
"openapi_3_1": "/api/v1/openapi.json",
|
||||
},
|
||||
"counts": {
|
||||
"tools": len(MCP_TOOLS_SCHEMA),
|
||||
"static_resources": len(STATIC_RESOURCES),
|
||||
@@ -185,10 +201,18 @@ class _MCPHTTPHandler(BaseHTTPRequestHandler):
|
||||
|
||||
def do_POST(self) -> None:
|
||||
length = int(self.headers.get("Content-Length", "0"))
|
||||
if length <= 0 or length > 65536:
|
||||
if length < 0 or length > 65536:
|
||||
self._send_json(400, {"jsonrpc": "2.0", "id": None, "error": {"code": -32600, "message": "Invalid content length"}})
|
||||
return
|
||||
raw = self.rfile.read(length).decode("utf-8")
|
||||
raw_bytes = self.rfile.read(length) if length > 0 else b""
|
||||
if self.path.startswith("/api/v1"):
|
||||
status, ctype, payload = dispatch_rest_v1("POST", self.path, raw_bytes)
|
||||
self._send_payload(status, ctype, payload)
|
||||
return
|
||||
if not raw_bytes:
|
||||
self._send_json(400, {"jsonrpc": "2.0", "id": None, "error": {"code": -32600, "message": "Invalid content length"}})
|
||||
return
|
||||
raw = raw_bytes.decode("utf-8")
|
||||
try:
|
||||
req = json.loads(raw)
|
||||
except json.JSONDecodeError as exc:
|
||||
|
||||
Reference in new issue
Block a user