feat(mcp): add HTTP transport support to MCP server with configurable host and port#448
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the MCP (Memgraph Code Processor) server by introducing an HTTP transport layer. This change allows the MCP server to be run as a web service, providing greater flexibility in how it can be deployed and integrated with other systems. Users can now choose between the existing standard I/O transport and the new HTTP transport, with options to configure the host and port for the HTTP server directly from the command line or through environment variables. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds HTTP transport support to the MCP server, making it accessible over the network. The changes include new CLI options to configure the transport, host, and port, with corresponding settings and help text. The core logic is implemented in codebase_rag/mcp/server.py with a new serve_http function that uses uvicorn and starlette. My review includes a couple of suggestions to improve code quality and robustness: one to remove unused imports and another to leverage typer's enum support for better CLI argument validation.
Greptile SummaryThis PR adds HTTP transport support to the MCP server, allowing it to be started with Key changes:
Issues found:
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant CLI as cli.py mcp_server()
participant Server as mcp/server.py
participant SM as StreamableHTTPSessionManager
participant Uvicorn
participant Client as MCP HTTP Client
User->>CLI: codebase-rag mcp-server --transport http [--host H] [--port P]
CLI->>CLI: resolve host/port (CLI arg or settings)
CLI->>Server: asyncio.run(serve_http(host, port))
Server->>Server: create_server() → (Server, MemgraphIngestor)
Server->>SM: StreamableHTTPSessionManager(app=server)
Server->>Uvicorn: uvicorn.Config(Starlette app, host, port)
Uvicorn->>Server: lifespan startup
Server->>Server: ingestor.__enter__()
Server->>SM: session_manager.run().__aenter__()
SM-->>Server: ready
Server-->>Uvicorn: yield (server ready)
Uvicorn-->>User: HTTP server listening on host:port/mcp
Client->>Uvicorn: POST /mcp (MCP request)
Uvicorn->>SM: handle_request(scope, receive, send)
SM->>Server: route to MCP tool handler
Server-->>SM: tool result
SM-->>Client: HTTP response
Prompt To Fix All With AIThis is a comment left during a code review.
Path: codebase_rag/constants.py
Line: 2410-2411
Comment:
**Unused `MCPEnvVar` entries are dead code**
`MCP_HTTP_HOST` and `MCP_HTTP_PORT` are added to `MCPEnvVar` but are never referenced anywhere in the codebase. The existing entries (`TARGET_REPO_PATH`, `CLAUDE_PROJECT_ROOT`, `PWD`) are used in `server.py` via `os.environ.get(cs.MCPEnvVar.XXX)` to read environment variables not managed by pydantic-settings. However, `MCP_HTTP_HOST` and `MCP_HTTP_PORT` are already handled automatically by pydantic-settings as `AppConfig.MCP_HTTP_HOST` / `AppConfig.MCP_HTTP_PORT`, and `serve_http` only accesses them via `settings.MCP_HTTP_HOST` / `settings.MCP_HTTP_PORT` — never through `os.environ.get`. These two entries serve no purpose and are misleading.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: codebase_rag/mcp/server.py
Line: 185-186
Comment:
**Missing return type annotation on `lifespan`**
The inner `lifespan` function has no return type annotation. Per the project's strict typing standards ("use type hints everywhere"), the decorated generator function should declare `AsyncIterator[None]` as its return type. Without it, `uv run ty check` will flag this, and the Starlette `Lifespan` type contract is not verified statically.
```suggestion
async def lifespan(app: Starlette) -> AsyncIterator[None]:
```
You will also need to add the import — either `from collections.abc import AsyncIterator` or `from typing import AsyncIterator`.
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: 602ecac |
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
@vitali87, could you please review the code and let me know how we can fix the SonarCloud issues? |
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
|
Thanks @NoSugarCoffee — this is a clean implementation and I'd like to get it merged. A few things to address before merging:
Once these are addressed, I'm happy to merge. Let me know if you need any help! |
|
@vitali87 There's a time difference, so I don't respond that quickly.Your opinion is very valuable. Thanks for the merge, even though there were some flaws.Regarding SonarCloud, it says there’s no token — it’s not a coverage issue. |
Summary
Type of Change
Related Issues
Test Plan
Can start up the http server as expected, and list tools
Checklist
make pre-commit)# type: ignore,cast(),Any, orobjecttype hints