The base branch moved twelve commits while this work was in flight --
including the per-session live stream and its own contract bump -- so this
integrates rather than leaving a PR nobody can merge. Six files
conflicted; the interesting resolutions are the two that were not
textual.
**The contract is mcp-v3.1, not v2.1.** This branch bumped v2 -> v2.1 for
an additive change; `feat/mcp-server` bumped v2 -> v3 for the live stream,
also additive. Both point releases, both correct, and they cannot both be
the same document. So v3 stands as written and the HTTP transport is the
point release on top of it, by the same rule each of us applied
independently: v2 is still the only major bump, because it is still the
only one that removed anything.
**The counts are no longer literals.** This branch asserted `21 tools` and
`5 resources` in `checks/vm-mcp-http.nix` and `5` in `test_mcp_http.py`;
the stream added two tools and one fixed resource, so the surface is 23
and 6. Rather than re-hardcode numbers that will go stale again, the
check now counts against `--list-tools` and `--list-resources` -- the
server's own table -- and the unit test against `resources.FIXED`. That
is the lesson 9708154 ("count the unnarrowed resources against the
listing, not a literal") had already learned on the other side of this
merge, arrived at twice. A stale number here would have failed in a way
indistinguishable from the HTTP transport dropping tools, which is the
one thing those subtests exist to catch.
The rest were additive on both sides and both halves are kept: the TODO
table, the checks wiring, the README check rows, the architecture diagram
(their 23/10 counts with this branch's two-transport annotation).
`nix/module.nix` needed reconstructing -- git interleaved the bodies of
`hhstream-live` and `hhstream-mcp` because both units land between the
same surrounding lines -- so the live unit is taken verbatim and the MCP
unit placed after it, with this branch's options, tmpfiles entry,
firewall rule, two assertions and two warnings re-applied on top.
One thing deliberately NOT touched: the v3 change table cites `§6` for the
idle-clock exception, but the rule it means is `§8`. That is the other
branch's prose and its author's call, not something to quietly rewrite in
a merge.
Verified after resolution: 394 unit tests pass, and the module evaluates
with both units, the right ExecStart, one firewall port and both
warnings.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KchcvnbfhhZhUHy83YL3Ya
120 lines
4.5 KiB
Nix
120 lines
4.5 KiB
Nix
# `hhstream-mcp` -- the MCP server, as its own derivation.
|
|
#
|
|
# Separate from `nix/package.nix` on purpose, and the separation is the point:
|
|
# the frame socket, the CLI and the broker are stdlib-only by policy
|
|
# (`pyproject.toml`, `docs/CONTRACT-sessions.md` §6 rule 3), the MCP SDK is a
|
|
# third-party dependency, and `packages.hhstream` runs as the compositor's own
|
|
# units. So the dependency lives here, in a package nothing else imports, and
|
|
# `packages.hhstream` keeps the closure it had.
|
|
#
|
|
# `hhstream` is a *library* dependency here and not a binary one: the tools call
|
|
# `hhstream.cli`'s handlers in process (see that module's docstring), so what
|
|
# this package needs is the import path. `toPythonModule` is what makes an
|
|
# application's site-packages visible to a dependent, which a bare
|
|
# `buildPythonApplication` output is not.
|
|
#
|
|
# `grim` and `ffmpeg` do go on PATH, because the CLI itself spawns them --
|
|
# `shot --output` and `record` are two of the twenty-three tools, and the server
|
|
# is launched by an MCP client whose PATH is not ours to predict. `--prefix`
|
|
# and not `--set`, so a deployment that wants its own ahead of these puts them
|
|
# on PATH and wins.
|
|
{
|
|
lib,
|
|
python3,
|
|
hhstream,
|
|
grim,
|
|
ffmpeg,
|
|
makeWrapper,
|
|
}:
|
|
python3.pkgs.buildPythonApplication {
|
|
pname = "hhstream-mcp";
|
|
version = "0.1.0";
|
|
pyproject = true;
|
|
|
|
# The package directory is the project root: its own pyproject.toml lives
|
|
# there and maps the package name onto `.`. See the comment in that file for
|
|
# why it is not at the repository root.
|
|
src = ../src/hhstream_mcp;
|
|
|
|
build-system = [ python3.pkgs.setuptools ];
|
|
|
|
dependencies = [
|
|
python3.pkgs.mcp
|
|
python3.pkgs.anyio
|
|
# The HTTP transport's own two, declared for the reason `anyio` is: the SDK
|
|
# propagates both today, and `hhstream_mcp.http` imports them by name. See
|
|
# the note in src/hhstream_mcp/pyproject.toml.
|
|
python3.pkgs.starlette
|
|
python3.pkgs.uvicorn
|
|
# An application is not importable by a dependent until this converts it,
|
|
# and `hhstream_mcp.invoke` imports `hhstream.cli` directly.
|
|
(python3.pkgs.toPythonModule hhstream)
|
|
];
|
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
|
|
|
makeWrapperArgs = [
|
|
"--prefix"
|
|
"PATH"
|
|
":"
|
|
"${lib.makeBinPath [
|
|
grim
|
|
ffmpeg
|
|
]}"
|
|
];
|
|
|
|
# The suite lives in `tests/` at the repository root and runs in the flake's
|
|
# `checks.unit`, which is also where `mcp` reaches it. Same choice as
|
|
# nix/package.nix, for the same reason.
|
|
doCheck = false;
|
|
|
|
# Cheap proof that both tables build and the SDK wiring imports: `tools` and
|
|
# `resources` construct every entry at import time, and `server` is the only
|
|
# module that touches `mcp`. A missing SDK, a schema that is not a dict, or a
|
|
# tool named twice all fail here rather than at an agent's first call.
|
|
pythonImportsCheck = [
|
|
"hhstream_mcp.tools"
|
|
"hhstream_mcp.resources"
|
|
"hhstream_mcp.server"
|
|
];
|
|
|
|
# `pythonImportsCheck` proves the modules load; it does not prove the script
|
|
# Nix wrapped can run, and the script is what an MCP client spawns.
|
|
# `--list-tools` and `--list-resources` are the two code paths that exercise
|
|
# argument parsing and both whole tables without opening stdio, so together
|
|
# they are the honest smoke test. `--toolsets` is in it because a selection
|
|
# that silently served everything would be the failure nobody notices.
|
|
#
|
|
# A `postPhases` entry and not `postInstall`, because the script is wrapped in
|
|
# `fixupPhase`: run any earlier and it has no PYTHONPATH, so `import mcp`
|
|
# fails and the check tests the wrong thing. `installCheckPhase` is no use
|
|
# either -- `buildPythonPackage` does not include that phase at all.
|
|
postPhases = [ "entryPointCheckPhase" ];
|
|
entryPointCheckPhase = ''
|
|
echo "checking the wrapped entry point..."
|
|
tools=$($out/bin/hhstream-mcp --list-tools)
|
|
echo "$tools"
|
|
test "$(echo "$tools" | wc -l)" -eq 23
|
|
|
|
resources=$($out/bin/hhstream-mcp --list-resources)
|
|
echo "$resources"
|
|
test "$(echo "$resources" | wc -l)" -eq 10
|
|
|
|
narrowed=$($out/bin/hhstream-mcp --list-tools --toolsets keyboard | wc -l)
|
|
echo "--toolsets keyboard offers $narrowed tools"
|
|
test "$narrowed" -eq 4
|
|
|
|
# An unknown toolset must be argparse's exit 2, not a server with no tools.
|
|
if $out/bin/hhstream-mcp --list-tools --toolsets nonsense; then
|
|
echo "an unknown toolset was accepted" >&2
|
|
exit 1
|
|
fi
|
|
'';
|
|
|
|
meta = {
|
|
description = "Drive a headless Hyprland session over the Model Context Protocol";
|
|
license = lib.licenses.mit;
|
|
mainProgram = "hhstream-mcp";
|
|
};
|
|
}
|