Skip to content

feat: implement MCP server #505

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

feat: implement MCP server #505

wants to merge 9 commits into from

Conversation

NicolasIRAGNE
Copy link
Contributor

No description provided.

assert "examples" in source_prop
examples = source_prop["examples"]
assert len(examples) >= 3
assert any("github.com" in ex for ex in examples)

Check failure

Code scanning / CodeQL

Incomplete URL substring sanitization High test

The string
github.com
may be at an arbitrary position in the sanitized URL.

Copilot Autofix

AI 3 days ago

To fix the problem, we should update the test assertion to properly validate that at least one example is a valid GitHub URL, rather than just containing the substring "github.com". The best way to do this is to parse each example as a URL and check that its hostname is exactly github.com or ends with .github.com (to allow for subdomains). This can be done using Python's urllib.parse module. The change should be made in the test method test_list_tools_source_examples in the file tests/test_mcp_server.py, specifically replacing the assertion on line 76.

Suggested changeset 1
tests/test_mcp_server.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/tests/test_mcp_server.py b/tests/test_mcp_server.py
--- a/tests/test_mcp_server.py
+++ b/tests/test_mcp_server.py
@@ -75,3 +75,10 @@
         assert len(examples) >= 3
-        assert any("github.com" in ex for ex in examples)
+        from urllib.parse import urlparse
+        def is_github_url(url):
+            try:
+                host = urlparse(url).hostname
+                return host == "github.com" or (host and host.endswith(".github.com"))
+            except Exception:
+                return False
+        assert any(is_github_url(ex) for ex in examples)
         assert any("/path/to/" in ex for ex in examples)
EOF
@@ -75,3 +75,10 @@
assert len(examples) >= 3
assert any("github.com" in ex for ex in examples)
from urllib.parse import urlparse
def is_github_url(url):
try:
host = urlparse(url).hostname
return host == "github.com" or (host and host.endswith(".github.com"))
except Exception:
return False
assert any(is_github_url(ex) for ex in examples)
assert any("/path/to/" in ex for ex in examples)
Copilot is powered by AI and may make mistakes. Always verify output.
NicolasIRAGNE and others added 5 commits August 8, 2025 16:33
- Add MCP server implementation with stdio transport
- Integrate MCP server option in CLI with --mcp-server flag
- Add ingest_repository tool for MCP clients
- Remove HTTP transport, keeping only stdio for simplicity
- Add MCP dependencies and optional installation group
- Include comprehensive documentation and client examples
- Support GitHub token authentication through MCP

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add complete test suite for MCP server functionality
- Test MCP tool registration, execution, and error handling
- Add async testing for stdio transport communication
- Update CHANGELOG.md with all feature additions
- Update README.md with MCP server installation and usage
- Document GitPython migration and MCP integration

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add complete test suite for MCP server functionality
- Test MCP tool registration, execution, and error handling
- Add async testing for stdio transport communication
- Update CHANGELOG.md with all feature additions
- Update README.md with MCP server installation and usage
- Document GitPython migration and MCP integration

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Comment on lines +175 to +181
return JSONResponse({
"jsonrpc": "2.0",
"id": message.get("id"),
"result": {
"content": [{"type": "text", "text": result}]
}
})

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

Copilot Autofix

AI 2 days ago

To fix the problem, we should ensure that the user-facing error message returned by the ingest_repository tool does not include any details from the exception object. Instead, return a generic message such as "An internal error occurred during ingestion." The detailed exception (including stack trace) should continue to be logged server-side for debugging purposes.

Specifically, in ingest_repository, replace the line:

return f"Error ingesting repository: {str(e)}"

with:

return "An internal error occurred during ingestion."

No new imports or methods are needed, as logging is already handled.


Suggested changeset 1
src/mcp_server/main.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/mcp_server/main.py b/src/mcp_server/main.py
--- a/src/mcp_server/main.py
+++ b/src/mcp_server/main.py
@@ -85,3 +85,3 @@
         logger.error(f"Error during ingestion: {e}", exc_info=True)
-        return f"Error ingesting repository: {str(e)}"
+        return "An internal error occurred during ingestion."
 
EOF
@@ -85,3 +85,3 @@
logger.error(f"Error during ingestion: {e}", exc_info=True)
return f"Error ingesting repository: {str(e)}"
return "An internal error occurred during ingestion."

Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +183 to +190
return JSONResponse({
"jsonrpc": "2.0",
"id": message.get("id"),
"error": {
"code": -32603,
"message": f"Tool execution failed: {str(e)}"
}
})

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

Copilot Autofix

AI 2 days ago

To fix the problem, we should avoid exposing the exception's string representation to the client. Instead, we should log the full exception (including stack trace) on the server for debugging purposes, and return a generic error message in the JSON-RPC response. This change should be made in the exception handler for the "tools/call" method (lines 182-190). Specifically, replace the use of str(e) in the error message with a generic message such as "Tool execution failed due to an internal error.". No changes are needed elsewhere, as the server already logs the error with stack trace.


Suggested changeset 1
src/mcp_server/main.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/mcp_server/main.py b/src/mcp_server/main.py
--- a/src/mcp_server/main.py
+++ b/src/mcp_server/main.py
@@ -182,2 +182,3 @@
                     except Exception as e:
+                        logger.error(f"Tool execution failed: {e}", exc_info=True)
                         return JSONResponse({
@@ -187,3 +188,3 @@
                                 "code": -32603,
-                                "message": f"Tool execution failed: {str(e)}"
+                                "message": "Tool execution failed due to an internal error."
                             }
EOF
@@ -182,2 +182,3 @@
except Exception as e:
logger.error(f"Tool execution failed: {e}", exc_info=True)
return JSONResponse({
@@ -187,3 +188,3 @@
"code": -32603,
"message": f"Tool execution failed: {str(e)}"
"message": "Tool execution failed due to an internal error."
}
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +214 to +221
return JSONResponse({
"jsonrpc": "2.0",
"id": message.get("id") if "message" in locals() else None,
"error": {
"code": -32603,
"message": f"Internal error: {str(e)}"
}
})

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

Copilot Autofix

AI 2 days ago

To fix the problem, we should avoid returning the string representation of the exception (str(e)) to the client. Instead, return a generic error message such as "An internal error has occurred." The detailed exception information should continue to be logged server-side for debugging purposes. Specifically, in handle_message, replace the error response's "message" field to use a generic message, and do not include any details from the exception object. Only the server logs should contain the full exception details.

  • Edit src/mcp_server/main.py, in the handle_message endpoint, lines 214 and 219.
  • Change the error response to use a generic message: "Internal error: An internal error has occurred."
  • No new imports or methods are needed.

Suggested changeset 1
src/mcp_server/main.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/mcp_server/main.py b/src/mcp_server/main.py
--- a/src/mcp_server/main.py
+++ b/src/mcp_server/main.py
@@ -218,3 +218,3 @@
                     "code": -32603,
-                    "message": f"Internal error: {str(e)}"
+                    "message": "Internal error: An internal error has occurred."
                 }
EOF
@@ -218,3 +218,3 @@
"code": -32603,
"message": f"Internal error: {str(e)}"
"message": "Internal error: An internal error has occurred."
}
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants