Skip to content

Commit 95e6391

Browse files
committed
test: add comprehensive MCP server testing and documentation
1 parent b793c3a commit 95e6391

File tree

7 files changed

+318
-52
lines changed

7 files changed

+318
-52
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
- name: Install dependencies
4444
run: |
4545
python -m pip install --upgrade pip
46-
python -m pip install ".[dev,server]"
46+
python -m pip install ".[dev,server,mcp]"
4747
4848
- name: Cache pytest results
4949
uses: actions/cache@v4

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ Gitingest includes an MCP server that allows LLMs to directly access repository
165165

166166
```bash
167167
# Start the MCP server with stdio transport
168-
gitingest --mcp-server
168+
python -m mcp_server
169169
```
170170

171171
### Available Tools
@@ -188,8 +188,8 @@ Use the provided `examples/mcp-config.json` to configure the MCP server in your
188188
{
189189
"mcpServers": {
190190
"gitingest": {
191-
"command": "gitingest",
192-
"args": ["--mcp-server"],
191+
"command": "python",
192+
"args": ["-m", "mcp_server"],
193193
"env": {
194194
"GITHUB_TOKEN": "${GITHUB_TOKEN}"
195195
}

docs/MCP_USAGE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ Create a configuration file for your MCP client:
6161
{
6262
"mcpServers": {
6363
"gitingest": {
64-
"command": "gitingest",
65-
"args": ["--mcp-server"],
64+
"command": "python",
65+
"args": ["-m", "mcp_server"],
6666
"env": {
6767
"GITHUB_TOKEN": "${GITHUB_TOKEN}"
6868
}

examples/start_mcp_server.py

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/mcp_server/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""MCP (Model Context Protocol) server module for Gitingest."""

src/mcp_server/__main__.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
"""MCP server module entry point for running with python -m mcp_server."""
2+
3+
import asyncio
4+
import click
5+
6+
# Import logging configuration first to intercept all logging
7+
from gitingest.utils.logging_config import get_logger
8+
from mcp_server.main import start_mcp_server_tcp
9+
10+
logger = get_logger(__name__)
11+
12+
@click.command()
13+
@click.option(
14+
"--transport",
15+
type=click.Choice(["stdio", "tcp"]),
16+
default="stdio",
17+
show_default=True,
18+
help="Transport protocol for MCP communication"
19+
)
20+
@click.option(
21+
"--host",
22+
default="0.0.0.0",
23+
show_default=True,
24+
help="Host to bind TCP server (only used with --transport tcp)"
25+
)
26+
@click.option(
27+
"--port",
28+
type=int,
29+
default=8001,
30+
show_default=True,
31+
help="Port for TCP server (only used with --transport tcp)"
32+
)
33+
def main(transport: str, host: str, port: int) -> None:
34+
"""Start the Gitingest MCP (Model Context Protocol) server.
35+
36+
The MCP server provides repository analysis capabilities to LLMs through
37+
the Model Context Protocol standard.
38+
39+
Examples:
40+
41+
# Start with stdio transport (default, for MCP clients)
42+
python -m mcp_server
43+
44+
# Start with TCP transport for remote access
45+
python -m mcp_server --transport tcp --host 0.0.0.0 --port 8001
46+
"""
47+
if transport == "tcp":
48+
# TCP mode needs asyncio
49+
asyncio.run(_async_main_tcp(host, port))
50+
else:
51+
# FastMCP stdio mode gère son propre event loop
52+
_main_stdio()
53+
54+
def _main_stdio() -> None:
55+
"""Main function for stdio transport."""
56+
try:
57+
logger.info("Starting Gitingest MCP server with stdio transport")
58+
# FastMCP gère son propre event loop pour stdio
59+
from mcp_server.main import mcp
60+
mcp.run(transport="stdio")
61+
except KeyboardInterrupt:
62+
logger.info("MCP server stopped by user")
63+
except Exception as exc:
64+
logger.error(f"Error starting MCP server: {exc}", exc_info=True)
65+
raise click.Abort from exc
66+
67+
async def _async_main_tcp(host: str, port: int) -> None:
68+
"""Async main function for TCP transport."""
69+
try:
70+
logger.info(f"Starting Gitingest MCP server with TCP transport on {host}:{port}")
71+
await start_mcp_server_tcp(host, port)
72+
except KeyboardInterrupt:
73+
logger.info("MCP server stopped by user")
74+
except Exception as exc:
75+
logger.error(f"Error starting MCP server: {exc}", exc_info=True)
76+
raise click.Abort from exc
77+
78+
if __name__ == "__main__":
79+
main()

0 commit comments

Comments
 (0)