This commit is contained in:
Eugene Yurtsev
2025-03-18 13:01:26 -04:00
parent 64ffe99083
commit 36a7b3834a
4 changed files with 82 additions and 3 deletions

View File

@@ -0,0 +1,3 @@
from mcpdoc._version import __version__
__all__ = ["__version__"]

7
mcpdoc/_version.py Normal file
View File

@@ -0,0 +1,7 @@
from importlib import metadata
try:
__version__ = metadata.version(__package__)
except metadata.PackageNotFoundError:
# Case where package metadata is not available.
__version__ = ""

View File

@@ -12,11 +12,45 @@ from mcpdoc.main import create_server, DocSource
from mcpdoc.splash import SPLASH
class CustomFormatter(
argparse.RawDescriptionHelpFormatter, argparse.ArgumentDefaultsHelpFormatter
):
# Custom formatter to preserve epilog formatting while showing default values
pass
EPILOG = """
Examples:
# Directly specifying llms.txt URLs with optional names
mcpdoc --urls LangGraph:https://langchain-ai.github.io/langgraph/llms.txt
# Using a YAML config file
mcpdoc --yaml sample_config.yaml
# Using a JSON config file
mcpdoc --json sample_config.json
# Combining multiple documentation sources
mcpdoc --yaml sample_config.yaml --json sample_config.json --urls LangGraph:https://langchain-ai.github.io/langgraph/llms.txt
# Using SSE transport with default host (127.0.0.1) and port (8000)
mcpdoc --yaml sample_config.yaml --transport sse
# Using SSE transport with custom host and port
mcpdoc --yaml sample_config.yaml --transport sse --host 0.0.0.0 --port 9000
# Using SSE transport with additional HTTP options
mcpdoc --yaml sample_config.yaml --follow-redirects --timeout 15 --transport sse --host localhost --port 8080
"""
def parse_args() -> argparse.Namespace:
"""Parse command-line arguments."""
# Custom formatter to preserve epilog formatting
parser = argparse.ArgumentParser(
description="MCP LLMS-TXT Documentation Server",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
formatter_class=CustomFormatter,
epilog=EPILOG,
)
# Allow combining multiple doc source methods
@@ -50,6 +84,20 @@ def parse_args() -> argparse.Namespace:
help="Transport protocol for MCP server",
)
# SSE-specific options
parser.add_argument(
"--host",
type=str,
default="127.0.0.1",
help="Host to bind the server to (only used with --transport sse)",
)
parser.add_argument(
"--port",
type=int,
default=8000,
help="Port to bind the server to (only used with --transport sse)",
)
return parser.parse_args()
@@ -104,6 +152,17 @@ def create_doc_sources_from_urls(urls: List[str]) -> List[DocSource]:
def main() -> None:
"""Main entry point for the CLI."""
# Check if any arguments were provided
if len(sys.argv) == 1:
# No arguments, print help
# Use the same custom formatter as parse_args()
argparse.ArgumentParser(
description="MCP LLMS-TXT Documentation Server",
formatter_class=CustomFormatter,
epilog=EPILOG,
).print_help()
sys.exit(0)
args = parse_args()
# Load doc sources based on command-line arguments
@@ -125,11 +184,18 @@ def main() -> None:
if args.urls:
doc_sources.extend(create_doc_sources_from_urls(args.urls))
# Only used with SSE transport
settings = {
"host": args.host,
"port": args.port,
}
# Create and run the server
server = create_server(
doc_sources,
follow_redirects=args.follow_redirects,
timeout=args.timeout,
settings=settings,
)
print()
@@ -137,9 +203,11 @@ def main() -> None:
print()
print(
f"Starting MCP LLMS-TXT server with {len(doc_sources)} doc sources",
f"Launching MCPDOC server with {len(doc_sources)} doc sources",
file=sys.stderr,
)
# Pass transport-specific options
server.run(transport=args.transport)

View File

@@ -39,9 +39,10 @@ def create_server(
*,
follow_redirects: bool = False,
timeout: float = 10,
settings: dict | None = None,
) -> FastMCP:
"""Create the server and generate tools."""
server = FastMCP(name="llms-txt")
server = FastMCP(name="llms-txt", **settings)
httpx_client = httpx.AsyncClient(follow_redirects=follow_redirects, timeout=timeout)
@server.tool()