-
Notifications
You must be signed in to change notification settings - Fork 864
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
base: main
Are you sure you want to change the base?
Conversation
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
github.com
Show autofix suggestion
Hide autofix suggestion
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.
-
Copy modified lines R76-R83
@@ -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) |
ee93018
to
f89a36f
Compare
- 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>
f89a36f
to
b9eac6c
Compare
- 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>
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
Show autofix suggestion
Hide autofix suggestion
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.
-
Copy modified line R86
@@ -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." | ||
|
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
Show autofix suggestion
Hide autofix suggestion
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.
-
Copy modified line R183 -
Copy modified line R189
@@ -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." | ||
} |
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
Show autofix suggestion
Hide autofix suggestion
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 thehandle_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.
-
Copy modified line R219
@@ -218,3 +218,3 @@ | ||
"code": -32603, | ||
"message": f"Internal error: {str(e)}" | ||
"message": "Internal error: An internal error has occurred." | ||
} |
No description provided.