mirror of
https://github.com/debpalash/VoiceStudio.git
synced 2026-12-05 09:58:17 +00:00
* fix(mcp): serve /mcp without redirect, follow OMNIVOICE_PORT, real integration setups - /mcp and /mcp/ both reach the Streamable HTTP transport for every method, ahead of the SPA StaticFiles mount (POST /mcp was 405 on Docker/source builds, 307 without a built SPA). Regression test drives initialize -> tools/list -> DELETE on the real main.app with a dist dir and follow_redirects=False; the client-setup test no longer follows redirects. - MCP tool callbacks resolve the backend URL from OMNIVOICE_BIND_HOST + OMNIVOICE_PORT (OMNIVOICE_API_URL still overrides) instead of a hard-coded :3900; speech_client and the dev fallback redirect follow their port env too, with a class guard against literal :39xx URLs in backend code. - Integrations: setup registry keyed by slug drives the Works with VoiceStudio badge and capability chips; adds Codex CLI config.toml, generic MCP (HTTP + stdio shim), VoiceStudio API (curl + OpenAI SDK) and Docker/GHCR setups. Removes the fake category chips from the shared catalog config; fixes the duplicate Details headings. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test: pin capture path in speech envelope test; changelog refs (#2289) A prior lifespan-running test persists a sherpa dictation.model_id pref via the startup performance profile, routing the envelope test to the sherpa handler. Pin the capture path it asserts. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(integrations): export <base>/mcp/ for every MCP client The trailing-slash URL works on backends without the bare-/mcp fix too, so Claude Code, Cursor, Codex and the generic MCP card all export it. Docs lead with /mcp/ and note bare /mcp works on current backends. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(mcp): in-process tool callbacks; remote-safe stdio and API snippets Review findings on #2289: - Greptile P1: mounted MCP tools now call the backend app in-process via httpx.ASGITransport as a loopback caller, so a concrete LAN OMNIVOICE_BIND_HOST behind an API key / share PIN no longer 401s every tool. Standalone runs keep the HTTP backend_self_url() path. - Greptile P1: the stdio shim accepts OMNIVOICE_URL (https + path prefix) and forwards OMNIVOICE_API_KEY as a Bearer token; the MCP card exports the full base URL instead of host/port. - Greptile P1: remote API snippets read the key from $OMNIVOICE_API_KEY (curl Bearer header, Python os.environ) without exporting credentials. - CodeQL (Bandit B104): wildcard detection uses ipaddress.is_unspecified instead of a 0.0.0.0 literal. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(integrations): API keys only over https or loopback; reference them by env CodeRabbit findings on #2289: - Standalone MCP server and the stdio shim send OMNIVOICE_API_KEY as a Bearer token only to https or loopback targets (same rule as backend.speech_client); the shim refuses to start otherwise. - Remote https exports reference the key from the user's environment in each client's own syntax (Claude Code ${VAR}, Cursor ${env:VAR}, Codex bearer_token_env_var, curl/Python $OMNIVOICE_API_KEY); plain-http remotes export no key. - test_backend_self_url imports app modules inside the tests. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(integrations): credential guidance via translated hints; HTTP card auth line CodeRabbit findings on #2289: - The generic Streamable HTTP card lists the env-backed Authorization header for remote https backends. - English comments inside copyable snippets (API credentials, Docker GPU) move to translated hints (apiBearerHint, apiInsecureHint, dockerGpuHint, all 21 locales); a test forbids natural-language comments in snippets. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(integrations): PowerShell docker run; scheme-aware Agents SDK key CodeRabbit findings on #2289: - Docker/GHCR pages add a Windows PowerShell docker run (backtick continuations, CSPRNG key that works on PowerShell 5.1 and 7), so the default setup works on every platform. - The OpenAI Agents snippet only reads OMNIVOICE_API_KEY for loopback or https backends; a remote plain-http backend gets a placeholder. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(integrations): Agents SDK key only for remote https backends Greptile/CodeRabbit findings on #2289: the OpenAI Agents snippet now follows the shared remoteAuth policy exactly. It requires os.environ["OMNIVOICE_API_KEY"] for remote https backends, uses a placeholder on loopback (no key over plain http, even locally), and for a remote plain-http backend shows the translated 'use https' hint instead of implying the key will be sent. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test: drop the speech-platform capture pin now that #2294 isolates settings Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(integrations): remote https Python snippets tolerate an unkeyed backend Greptile finding on #2289: os.environ[...] raised KeyError on a remote https backend that runs without an API key. Read the key with a placeholder fallback (Agents SDK and API Python snippets); still loopback- and plain-http-safe via remoteAuth. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
119 lines
5.0 KiB
Python
119 lines
5.0 KiB
Python
"""The published MCP URL (`/mcp`, no slash) works on the real app with a built SPA.
|
|
|
|
Docker images and source builds serve `frontend/dist` from a StaticFiles mount
|
|
at "/". The MCP transport is mounted at "/mcp", which only matches "/mcp/...",
|
|
so a bare "/mcp" used to fall through to the SPA and answer POST with 405
|
|
(without an SPA: a 307 most MCP clients never re-POST). Every exported client
|
|
config and doc publishes "/mcp", so both spellings must serve MCP directly.
|
|
"""
|
|
import importlib
|
|
import json
|
|
|
|
import pytest
|
|
|
|
pytest.importorskip("mcp")
|
|
|
|
HEADERS = {"Accept": "application/json, text/event-stream", "X-OmniVoice-Client-Id": "codex-cli"}
|
|
|
|
|
|
def _result(response):
|
|
assert response.status_code == 200, (response.status_code, response.text[:200])
|
|
if response.headers.get("content-type", "").startswith("text/event-stream"):
|
|
return json.loads(next(
|
|
line[6:] for line in response.text.splitlines() if line.startswith("data: ")
|
|
))
|
|
return response.json()
|
|
|
|
|
|
@pytest.fixture
|
|
def app_with_spa(monkeypatch, tmp_path):
|
|
from core import spa_inject
|
|
|
|
dist = tmp_path / "dist"
|
|
dist.mkdir()
|
|
(dist / "index.html").write_text("<!doctype html><title>spa</title>")
|
|
monkeypatch.setattr(spa_inject, "frontend_dist_dir", lambda: str(dist))
|
|
monkeypatch.delenv("OMNIVOICE_MCP_DISABLE", raising=False)
|
|
import main
|
|
|
|
importlib.reload(main)
|
|
try:
|
|
yield main.app
|
|
finally:
|
|
monkeypatch.undo()
|
|
importlib.reload(main) # restore the default app for later tests
|
|
|
|
|
|
@pytest.mark.parametrize("path", ["/mcp", "/mcp/"])
|
|
def test_mcp_streamable_http_on_real_app_with_spa_mount(app_with_spa, path):
|
|
from starlette.testclient import TestClient
|
|
|
|
with TestClient(
|
|
app_with_spa, base_url="http://127.0.0.1:3900", follow_redirects=False
|
|
) as client:
|
|
assert "<title>spa</title>" in client.get("/").text # SPA really mounted
|
|
headers = dict(HEADERS)
|
|
init = client.post(path, headers=headers, json={
|
|
"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {
|
|
"protocolVersion": "2025-03-26", "capabilities": {},
|
|
"clientInfo": {"name": "codex-cli", "version": "test"},
|
|
},
|
|
})
|
|
assert "serverInfo" in _result(init)["result"]
|
|
headers["Mcp-Session-Id"] = init.headers["mcp-session-id"]
|
|
assert client.post(path, headers=headers, json={
|
|
"jsonrpc": "2.0", "method": "notifications/initialized",
|
|
}).status_code == 202
|
|
tools = _result(client.post(path, headers=headers, json={
|
|
"jsonrpc": "2.0", "id": 2, "method": "tools/list",
|
|
}))
|
|
assert "generate_speech" in {t["name"] for t in tools["result"]["tools"]}
|
|
# Session teardown (DELETE) reaches the transport too — not 405/307.
|
|
assert client.delete(path, headers=headers).status_code == 200
|
|
|
|
|
|
def test_bare_mcp_route_accepts_every_method(app_with_spa):
|
|
"""GET opens the SSE stream; the bare route must not restrict methods."""
|
|
from starlette.routing import Route
|
|
|
|
bare = [r for r in app_with_spa.router.routes if isinstance(r, Route) and r.path == "/mcp"]
|
|
assert len(bare) == 1 and bare[0].methods is None
|
|
names = [getattr(r, "path", None) for r in app_with_spa.router.routes]
|
|
assert names.index("/mcp") < names.index("") # ahead of the SPA mount at "/"
|
|
|
|
|
|
def test_tools_reach_the_api_when_bound_to_a_lan_address_behind_a_key(monkeypatch, app_with_spa):
|
|
"""A concrete OMNIVOICE_BIND_HOST plus an API key must not break the tools.
|
|
|
|
Tool calls go in-process as a loopback caller, so neither the bind address
|
|
nor the API-key / share-PIN gates apply to them.
|
|
"""
|
|
from starlette.testclient import TestClient
|
|
|
|
monkeypatch.setenv("OMNIVOICE_BIND_HOST", "192.0.2.10") # not a local address
|
|
monkeypatch.setenv("OMNIVOICE_PORT", "1") # nothing listens here
|
|
monkeypatch.setenv("OMNIVOICE_API_KEY", "k" * 40)
|
|
monkeypatch.delenv("OMNIVOICE_API_URL", raising=False)
|
|
with TestClient(
|
|
app_with_spa, base_url="http://127.0.0.1:3900", follow_redirects=False,
|
|
client=("127.0.0.1", 50000), # the agent itself is local
|
|
) as client:
|
|
headers = dict(HEADERS)
|
|
init = client.post("/mcp", headers=headers, json={
|
|
"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {
|
|
"protocolVersion": "2025-03-26", "capabilities": {},
|
|
"clientInfo": {"name": "codex-cli", "version": "test"},
|
|
},
|
|
})
|
|
_result(init)
|
|
headers["Mcp-Session-Id"] = init.headers["mcp-session-id"]
|
|
client.post("/mcp", headers=headers, json={
|
|
"jsonrpc": "2.0", "method": "notifications/initialized",
|
|
})
|
|
called = _result(client.post("/mcp", headers=headers, json={
|
|
"jsonrpc": "2.0", "id": 2, "method": "tools/call",
|
|
"params": {"name": "check_health", "arguments": {}},
|
|
}))
|
|
assert not called["result"].get("isError"), called
|
|
assert "status" in called["result"]["content"][0]["text"]
|