This cookbook provides examples of how to use the mcp tool to query and understand your Python codebase. The "Tool" indicates which mcp tool to use, and the "JSON Arguments" are what the LLM would provide to that tool.
- Natural Language: "Where is the function
foodefined?" - Tool:
find_code - JSON Arguments:
{ "query": "foo" }
- Natural Language: "Find all calls to the
helperfunction." - Tool:
analyze_code_relationships - JSON Arguments:
{ "query_type": "find_callers", "target": "helper" }
- Natural Language: "What functions are called inside the
foofunction?" - Tool:
analyze_code_relationships - JSON Arguments:
{ "query_type": "find_callees", "target": "foo", "context": "/teamspace/studios/this_studio/demo/CodeGraphContext/tests/sample_project/module_a.py" }
- Natural Language: "Where is the
mathmodule imported?" - Tool:
analyze_code_relationships - JSON Arguments:
{ "query_type": "find_importers", "target": "math" }
- Natural Language: "What are the methods of the
Aclass?" - Tool:
analyze_code_relationships - JSON Arguments:
{ "query_type": "class_hierarchy", "target": "A" } - Note: The response for
class_hierarchyincludes a list of methods.
- Natural Language: "Show me all classes that inherit from
Base." - Tool:
analyze_code_relationships - JSON Arguments:
{ "query_type": "class_hierarchy", "target": "Base" } - Note: The response for
class_hierarchyincludes a list of child classes.
- Natural Language: "Find all functions with the
log_decorator." - Tool:
analyze_code_relationships - JSON Arguments:
{ "query_type": "find_functions_by_decorator", "target": "log_decorator" }
- Natural Language: "Find all dataclasses."
- Tool:
execute_cypher_query - JSON Arguments:
{ "cypher_query": "MATCH (c:Class) WHERE 'dataclass' IN c.decorators RETURN c.name, c.file_path" }
- Natural Language: "Find the 5 most complex functions."
- Tool:
find_most_complex_functions - JSON Arguments:
{ "limit": 5 }
- Natural Language: "What is the cyclomatic complexity of
try_except_finally?" - Tool:
calculate_cyclomatic_complexity - JSON Arguments:
{ "function_name": "try_except_finally" }
- Natural Language: "Find unused code, but ignore API endpoints decorated with
@app.route." - Tool:
find_dead_code - JSON Arguments:
{ "exclude_decorated_with": ["@app.route"] }
- Natural Language: "What is the call chain from
wrappertohelper?" - Tool:
analyze_code_relationships - JSON Arguments:
{ "query_type": "call_chain", "target": "wrapper->helper" }
- Natural Language: "Show me all functions that eventually call the
helperfunction." - Tool:
analyze_code_relationships - JSON Arguments:
{ "query_type": "find_all_callers", "target": "helper" }
- Natural Language: "Find all functions that take
requestas an argument." - Tool:
analyze_code_relationships - JSON Arguments:
{ "query_type": "find_functions_by_argument", "target": "request" }
- Natural Language: "List all python package imports from my project directory."
- Tool:
list_imports - JSON Arguments:
{ "path": "/teamspace/studios/this_studio/demo/CodeGraphContext/tests/sample_project" }
- Natural Language: "List all projects I have indexed."
- Tool:
list_indexed_repositories - JSON Arguments:
{}
- Natural Language: "What is the status of job
4cb9a60e-c1b1-43a7-9c94-c840771506bc?" - Tool:
check_job_status - JSON Arguments:
{ "job_id": "4cb9a60e-c1b1-43a7-9c94-c840771506bc" }
- Natural Language: "Show me all background jobs."
- Tool:
list_jobs - JSON Arguments:
{}
These examples use the execute_cypher_query tool for more specific and complex questions.
- Natural Language: "Find all function definitions in the codebase."
- JSON Arguments:
{ "cypher_query": "MATCH (n:Function) RETURN n.name, n.file_path, n.line_number LIMIT 50" }
- Natural Language: "Show me all the classes."
- JSON Arguments:
{ "cypher_query": "MATCH (n:Class) RETURN n.name, n.file_path, n.line_number LIMIT 50" }
- Natural Language: "Find all functions in
module_a.py." - JSON Arguments:
{ "cypher_query": "MATCH (f:Function) WHERE f.file_path ENDS WITH 'module_a.py' RETURN f.name" }
- Natural Language: "Find all classes in
advanced_classes.py." - JSON Arguments:
{ "cypher_query": "MATCH (c:Class) WHERE c.file_path ENDS WITH 'advanced_classes.py' RETURN c.name" }
- Natural Language: "List all top-level functions and classes in
module_a.py." - JSON Arguments:
{ "cypher_query": "MATCH (f:File)-[:CONTAINS]->(n) WHERE f.name = 'module_a.py' AND (n:Function OR n:Class) AND n.context IS NULL RETURN n.name" }
- Natural Language: "Find functions in
module_a.pythat callhelperinmodule_b.py." - JSON Arguments:
{ "cypher_query": "MATCH (caller:Function)-[:CALLS]->(callee:Function {name: 'helper'}) WHERE caller.file_path ENDS WITH 'module_a.py' AND callee.file_path ENDS WITH 'module_b.py' RETURN caller.name" }
- Natural Language: "Are there any circular dependencies between files?"
- JSON Arguments:
{ "cypher_query": "MATCH (f1:File)-[:IMPORTS]->(m2:Module), (f2:File)-[:IMPORTS]->(m1:Module) WHERE f1.name = m1.name + '.py' AND f2.name = m2.name + '.py' RETURN f1.name, f2.name" }
- Natural Language: "Find all functions with a large number of arguments."
- JSON Arguments:
{ "cypher_query": "MATCH (f:Function) WHERE size(f.args) > 5 RETURN f.name, f.file_path, size(f.args) as arg_count" }
- Natural Language: "Find all functions in
module_a.pythat have a docstring." - JSON Arguments:
{ "cypher_query": "MATCH (f:Function) WHERE f.file_path ENDS WITH 'module_a.py' AND f.docstring IS NOT NULL AND f.docstring <> '' RETURN f.name" }
- Natural Language: "Find all classes that have a
greetmethod." - JSON Arguments:
{ "cypher_query": "MATCH (c:Class)-[:CONTAINS]->(m:Function {name: 'greet'}) RETURN c.name, c.file_path" }
- Natural Language: "How deep are the inheritance chains for all classes?"
- JSON Arguments:
{ "cypher_query": "MATCH (c:Class) OPTIONAL MATCH path = (c)-[:INHERITS_FROM*]->(parent:Class) RETURN c.name, c.file_path, length(path) AS depth ORDER BY depth DESC" }
- Natural Language: "Show me all functions that are documented."
- JSON Arguments:
{ "cypher_query": "MATCH (f:Function) WHERE f.docstring IS NOT NULL AND f.docstring <> '' RETURN f.name, f.file_path LIMIT 50" }
- Natural Language: "Find all decorated methods in the
Childclass." - JSON Arguments:
{ "cypher_query": "MATCH (c:Class {name: 'Child'})-[:CONTAINS]->(m:Function) WHERE m.decorators IS NOT NULL AND size(m.decorators) > 0 RETURN m.name" }
- Natural Language: "How many functions are in each file?"
- JSON Arguments:
{ "cypher_query": "MATCH (f:Function) RETURN f.file_path, count(f) AS function_count ORDER BY function_count DESC" }
- Natural Language: "Find all methods that are overridden from a parent class."
- JSON Arguments:
{ "cypher_query": "MATCH (c:Class)-[:INHERITS_FROM]->(p:Class), (c)-[:CONTAINS]->(m:Function), (p)-[:CONTAINS]->(m_parent:Function) WHERE m.name = m_parent.name RETURN m.name as method, c.name as child_class, p.name as parent_class" }
- Natural Language: "Find all methods that call their parent's method via
super()." - JSON Arguments:
{ "cypher_query": "MATCH (f:Function)-[r:CALLS]->() WHERE r.full_call_name STARTS WITH 'super(' RETURN f.name, f.file_path" }
- Natural Language: "Find all calls to
helperwith the argumentx." - JSON Arguments:
{ "cypher_query": "MATCH ()-[r:CALLS]->(f:Function {name: 'helper'}) WHERE 'x' IN r.args RETURN r.full_call_name, r.line_number, r.file_path" }
- Natural Language: "Find all dead code (functions that are never called)."
- JSON Arguments:
{ "cypher_query": "MATCH (f:Function) WHERE NOT (()-[:CALLS]->(f)) AND f.is_dependency = false RETURN f.name, f.file_path" }
- Natural Language: "Find all calls to
printwith the argument'hello'." - JSON Arguments:
{ "cypher_query": "MATCH (c:Call) WHERE c.name = 'print' AND 'hello' IN c.args RETURN c.file, c.lineno" }
- Natural Language: "Show me all functions that are eventually called by the
foofunction." - Tool:
analyze_code_relationships - JSON Arguments:
{ "query_type": "find_all_callees", "target": "foo", "context": "/teamspace/studios/this_studio/demo/CodeGraphContext/tests/sample_project/module_a.py" }
- Natural Language: "Find all functions that are overridden."
- Tool:
analyze_code_relationships - JSON Arguments:
{ "query_type": "overrides", "target": "foo" }
- Natural Language: "Find all modules imported by
module_a." - Tool:
execute_cypher_query - JSON Arguments:
{ "cypher_query": "MATCH (f:File {name: 'module_a.py'})-[:IMPORTS]->(m:Module) RETURN m.name AS imported_module_name" }































