-
Notifications
You must be signed in to change notification settings - Fork 71
feat: prototype MCP docs generation via mcpdocs-gen #1013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Aaron ("AJ") Steers (aaronsteers)
wants to merge
1
commit into
main
Choose a base branch
from
devin/1776390943-mcp-docs-prototype
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright (c) 2026 Airbyte, Inc., all rights reserved. | ||
| """Generate static HTML docs for the PyAirbyte MCP server using `mcpdocs-gen`. | ||
|
|
||
| This script: | ||
|
|
||
| 1. Starts the PyAirbyte MCP server in SSE mode as a background subprocess. | ||
| 2. Waits for the SSE endpoint to become reachable. | ||
| 3. Shells out to `mcpdocs generate` to emit a static HTML site. | ||
| 4. Tears down the server subprocess cleanly, even on failure or `Ctrl+C`. | ||
|
|
||
| Usage: | ||
|
|
||
| ``` | ||
| uv run python scripts/generate_mcp_docs.py [--port 8765] [--output docs/mcp-generated] | ||
| ``` | ||
|
|
||
| Or via the project's poe task: | ||
|
|
||
| ``` | ||
| poe mcp-docs-generate | ||
| ``` | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import contextlib | ||
| import os | ||
| import shutil | ||
| import signal | ||
| import socket | ||
| import subprocess | ||
| import sys | ||
| import time | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| DEFAULT_PORT = 8765 | ||
| DEFAULT_OUTPUT = Path("docs/mcp-generated") | ||
| STARTUP_TIMEOUT_SECONDS = 60.0 | ||
|
|
||
|
|
||
| def _wait_for_port(host: str, port: int, timeout: float) -> None: | ||
| """Block until `host:port` accepts TCP connections or `timeout` elapses.""" | ||
| deadline = time.monotonic() + timeout | ||
| last_error: Exception | None = None | ||
| while time.monotonic() < deadline: | ||
| try: | ||
| with socket.create_connection((host, port), timeout=1.0): | ||
| return | ||
| except OSError as ex: | ||
| last_error = ex | ||
| time.sleep(0.5) | ||
| raise TimeoutError( | ||
| f"MCP SSE server did not become reachable at {host}:{port} " | ||
| f"within {timeout:.0f}s (last error: {last_error!r})." | ||
| ) | ||
|
|
||
|
|
||
| def _start_mcp_server(host: str, port: int) -> subprocess.Popen[bytes]: | ||
| """Start the PyAirbyte MCP server in SSE mode as a background subprocess.""" | ||
| cmd = [ | ||
| sys.executable, | ||
| "-c", | ||
| ( | ||
| "from airbyte.mcp.server import app; " | ||
| f"app.run(transport='sse', host={host!r}, port={port})" | ||
| ), | ||
| ] | ||
| # Start in its own process group so we can signal the whole tree on shutdown. | ||
| return subprocess.Popen( | ||
| cmd, | ||
| stdout=subprocess.DEVNULL, | ||
| stderr=subprocess.STDOUT, | ||
| start_new_session=True, | ||
| ) | ||
|
|
||
|
|
||
| def _stop_mcp_server(proc: subprocess.Popen[bytes]) -> None: | ||
| """Terminate the MCP server subprocess tree cleanly.""" | ||
| if proc.poll() is not None: | ||
| return | ||
| try: | ||
| os.killpg(proc.pid, signal.SIGTERM) | ||
| except ProcessLookupError: | ||
| return | ||
| try: | ||
| proc.wait(timeout=10.0) | ||
| except subprocess.TimeoutExpired: | ||
| with contextlib.suppress(ProcessLookupError): | ||
| os.killpg(proc.pid, signal.SIGKILL) | ||
| proc.wait(timeout=5.0) | ||
|
|
||
|
|
||
| def _run_mcpdocs(url: str, output: Path) -> None: | ||
| """Invoke the `mcpdocs generate` CLI to emit a static HTML site.""" | ||
| mcpdocs_bin = shutil.which("mcpdocs") | ||
| if mcpdocs_bin is None: | ||
| raise RuntimeError( | ||
| "`mcpdocs` CLI not found on PATH. Install it with " | ||
| "`uv pip install mcpdocs-gen` (or `pip install mcpdocs-gen`)." | ||
| ) | ||
| output.mkdir(parents=True, exist_ok=True) | ||
| subprocess.run( | ||
| [mcpdocs_bin, "generate", "--url", url, "--output", str(output)], | ||
| check=True, | ||
| ) | ||
|
|
||
|
|
||
| def generate(host: str, port: int, output: Path) -> None: | ||
| """Start the MCP server, generate docs with mcpdocs-gen, then shut down.""" | ||
| print(f"Starting PyAirbyte MCP server on http://{host}:{port} (SSE)...") | ||
| proc = _start_mcp_server(host=host, port=port) | ||
| try: | ||
| _wait_for_port(host=host, port=port, timeout=STARTUP_TIMEOUT_SECONDS) | ||
| print(f"Generating MCP docs into {output}/ ...") | ||
| _run_mcpdocs(url=f"http://{host}:{port}/sse", output=output) | ||
| print(f"MCP docs written to {output}/index.html") | ||
| finally: | ||
| print("Stopping MCP server...") | ||
| _stop_mcp_server(proc) | ||
|
|
||
|
|
||
| def main() -> int: | ||
| """CLI entrypoint for the MCP docs generator.""" | ||
| parser = argparse.ArgumentParser(description=__doc__) | ||
| parser.add_argument( | ||
| "--host", | ||
| default="127.0.0.1", | ||
| help="Host to bind the MCP SSE server to (default: 127.0.0.1).", | ||
| ) | ||
| parser.add_argument( | ||
| "--port", | ||
| type=int, | ||
| default=DEFAULT_PORT, | ||
| help=f"Port to bind the MCP SSE server to (default: {DEFAULT_PORT}).", | ||
| ) | ||
| parser.add_argument( | ||
| "--output", | ||
| type=Path, | ||
| default=DEFAULT_OUTPUT, | ||
| help=f"Output directory for generated HTML (default: {DEFAULT_OUTPUT}).", | ||
| ) | ||
| args = parser.parse_args() | ||
| try: | ||
| generate(host=args.host, port=args.port, output=args.output) | ||
| except KeyboardInterrupt: | ||
| print("Interrupted.", file=sys.stderr) | ||
| return 130 | ||
| except (subprocess.CalledProcessError, TimeoutError, RuntimeError) as ex: | ||
| print(f"MCP docs generation failed: {ex}", file=sys.stderr) | ||
| return 1 | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
POSIX-only process group handling — is Windows support in scope for this prototype?
start_new_session=Trueis a no-op on Windows, andos.killpg/signal.SIGKILLaren't available there, so_stop_mcp_serverwill raiseAttributeErroron Windows even in the "happy path" (it runs unconditionally in thefinally). Given the project supports Python 3.10–3.12 on Windows perrequires-pythonand there are Windows-specific pytest filters, would you like to either (a) gate this script to POSIX with a friendly error up-front, or (b) add a Windows fallback usingproc.terminate()/proc.kill(), wdyt?🛠️ Sketch of a cross-platform fallback
def _start_mcp_server(host: str, port: int) -> subprocess.Popen[bytes]: ... + popen_kwargs: dict = {"stdout": subprocess.DEVNULL, "stderr": subprocess.STDOUT} + if os.name == "posix": + popen_kwargs["start_new_session"] = True + else: + popen_kwargs["creationflags"] = subprocess.CREATE_NEW_PROCESS_GROUP # type: ignore[attr-defined] - return subprocess.Popen( - cmd, - stdout=subprocess.DEVNULL, - stderr=subprocess.STDOUT, - start_new_session=True, - ) + return subprocess.Popen(cmd, **popen_kwargs) def _stop_mcp_server(proc: subprocess.Popen[bytes]) -> None: if proc.poll() is not None: return - try: - os.killpg(proc.pid, signal.SIGTERM) - except ProcessLookupError: - return + if os.name == "posix": + try: + os.killpg(proc.pid, signal.SIGTERM) + except ProcessLookupError: + return + else: + proc.terminate() try: proc.wait(timeout=10.0) except subprocess.TimeoutExpired: - with contextlib.suppress(ProcessLookupError): - os.killpg(proc.pid, signal.SIGKILL) + with contextlib.suppress(ProcessLookupError): + if os.name == "posix": + os.killpg(proc.pid, signal.SIGKILL) + else: + proc.kill() proc.wait(timeout=5.0)🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks CodeRabbit (@coderabbitai) — acknowledged. All four are reasonable, but per the task brief this is a deliberately minimal prototype ("don't over-engineer") so I'm leaving them as follow-ups rather than expanding scope here:
scripts/generate_mcp_docs.py.mcp-docs-installtask — intentionally skipped, per the PR description: we don't want to commit tomcpdocs-genas a first-party dep until the eval is accepted.Happy to fold any/all of these in if AJ wants the prototype hardened before merge.
Devin session
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.