-
-
Notifications
You must be signed in to change notification settings - Fork 269
Add ask-agent CLI and MCP integration tool #162
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
qdrddr
wants to merge
11
commits into
vitali87:main
Choose a base branch
from
qdrddr:add-cmd-question
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d9dcbf8
feat: add non-interactive mode with --question parameter
qdrddr 7261498
docs: add non-interactive mode documentation to README
qdrddr a6d4ee4
feat: add question mode logging configuration
qdrddr 1157d96
feat: add ask_code_graph MCP tool and MCP client for single-question …
qdrddr bd43fe5
feat(mcp): rename ask_code_graph tool to ask_agent and expose via CLI
qdrddr ac58048
chore: update ignore patterns and documentation
qdrddr fb65230
refactor(tools): remove image handling from question processing
qdrddr 5ab5e2b
chore: update --question to be --ask-agent
qdrddr 9a0149c
fix: MCP server JSONRPC and output validation issues
qdrddr f67bca8
feat(logging): add optional logging and suppress logs in tool execution
qdrddr 29d84d6
docs(readme): add new tool entries and usage examples to README
qdrddr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,3 +15,8 @@ wheels/ | |
| .pytest_cache/ | ||
| .claude/ | ||
| .qdrant_code_embeddings/ | ||
|
|
||
| # Popular VibeCoding Agents | ||
| .roo/ | ||
| .augment | ||
| .vscode | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| """MCP client for querying the code graph via the MCP server. | ||
|
|
||
| This module provides a simple CLI client that connects to the MCP server | ||
| and executes the ask_agent tool with a provided question. | ||
| """ | ||
|
|
||
| import asyncio | ||
| import json | ||
| import os | ||
| import sys | ||
| from typing import Any | ||
|
|
||
| import typer | ||
| from mcp import ClientSession | ||
| from mcp.client.stdio import StdioServerParameters, stdio_client | ||
|
|
||
| app = typer.Typer() | ||
|
|
||
|
|
||
| async def query_mcp_server(question: str) -> dict[str, Any]: | ||
| """Query the MCP server with a question. | ||
|
|
||
| Args: | ||
| question: The question to ask about the codebase | ||
|
|
||
| Returns: | ||
| Dictionary with the response from the server | ||
| """ | ||
| # Start the MCP server as a subprocess with stderr redirected to /dev/null | ||
| # This suppresses all server logs while keeping stdout/stdin for MCP communication | ||
| with open(os.devnull, "w") as devnull: | ||
| server_params = StdioServerParameters( | ||
| command="python", | ||
| args=["-m", "codebase_rag.main", "mcp-server"], | ||
| ) | ||
|
|
||
| async with stdio_client(server=server_params, errlog=devnull) as (read, write): | ||
| async with ClientSession(read, write) as session: | ||
| # Initialize the session | ||
| await session.initialize() | ||
|
|
||
| # Call the ask_agent tool | ||
| result = await session.call_tool("ask_agent", {"question": question}) | ||
|
|
||
| # Extract the response text | ||
| if result.content: | ||
| response_text = result.content[0].text | ||
| # Parse JSON response | ||
| try: | ||
| parsed = json.loads(response_text) | ||
| if isinstance(parsed, dict): | ||
| return parsed | ||
| return {"output": str(parsed)} | ||
| except json.JSONDecodeError: | ||
| return {"output": response_text} | ||
| return {"output": "No response from server"} | ||
|
|
||
|
|
||
| @app.command() | ||
| def main( | ||
| question: str = typer.Option( | ||
| ..., "--ask-agent", "-a", help="Question to ask about the codebase" | ||
| ), | ||
| ) -> None: | ||
| """Query the code graph via MCP server. | ||
|
|
||
| Example: | ||
| python -m codebase_rag.mcp.client --ask-agent "What functions call UserService.create_user?" | ||
| """ | ||
| try: | ||
| # Run the async query | ||
| result = asyncio.run(query_mcp_server(question)) | ||
|
|
||
| # Print only the output (clean for scripting) | ||
| if isinstance(result, dict) and "output" in result: | ||
| print(result["output"]) | ||
| else: | ||
| print(json.dumps(result)) | ||
|
|
||
| except Exception as e: | ||
| # Print error to stderr and exit with error code | ||
| print(f"Error: {str(e)}", file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| app() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.