Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/git/src/mcp_server_git/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,4 +584,4 @@ async def call_tool(name: str, arguments: dict) -> list[TextContent]:

options = server.create_initialization_options()
async with stdio_server() as (read_stream, write_stream):
await server.run(read_stream, write_stream, options, raise_exceptions=True)
await server.run(read_stream, write_stream, options)
36 changes: 36 additions & 0 deletions src/git/tests/test_server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import asyncio
from contextlib import asynccontextmanager
import pytest
from pathlib import Path
import git
from git.exc import BadName
import mcp_server_git.server as server_module
from mcp_server_git.server import (
git_checkout,
git_branch,
Expand Down Expand Up @@ -39,6 +42,39 @@ def test_git_checkout_existing_branch(test_repository):
assert "Switched to branch 'test-branch'" in result
assert test_repository.active_branch.name == "test-branch"

def test_stdio_transport_errors_do_not_abort_server(monkeypatch):
captured_run_kwargs = {}

class FakeServer:
def __init__(self, name):
self.name = name

def list_roots(self):
return lambda fn: fn

def list_tools(self):
return lambda fn: fn

def call_tool(self):
return lambda fn: fn

def create_initialization_options(self):
return object()

async def run(self, read_stream, write_stream, options, **kwargs):
captured_run_kwargs.update(kwargs)

@asynccontextmanager
async def fake_stdio_server():
yield object(), object()

monkeypatch.setattr(server_module, "Server", FakeServer)
monkeypatch.setattr(server_module, "stdio_server", fake_stdio_server)

asyncio.run(server_module.serve(repository=None))

assert "raise_exceptions" not in captured_run_kwargs

def test_git_checkout_nonexistent_branch(test_repository):

with pytest.raises(BadName):
Expand Down
Loading