get_method_code_by_id
Retrieve method code using its unique ID to analyze implementation details, aiding in code review and security analysis within the Joern MCP Server environment.
Instructions
Get the code of a method by its class full name and method name
@param class_full_name: The fully qualified name of the class
@param method_name: The name of the method
@return: List of full name, name, signature and id of methods in the class
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| method_id | Yes |
Implementation Reference
- server_tools.py:87-96 (handler)The core handler function for the 'get_method_code_by_id' tool. It is registered via the @joern_mcp.tool() decorator and implements the tool logic by querying the Joern server with the method ID and extracting the response.@joern_mcp.tool() def get_method_code_by_id(method_id:str) -> str: """Get the code of a method by its class full name and method name @param class_full_name: The fully qualified name of the class @param method_name: The name of the method @return: List of full name, name, signature and id of methods in the class """ response = joern_remote(f'get_method_code_by_id("{method_id}")') return extract_value(response)
- server.py:38-70 (helper)Helper function joern_remote that sends the actual query to the Joern server endpoint and returns the cleaned stdout response.def joern_remote(query): """ Execute remote query and return results Parameters: query -- The query string to execute Returns: Returns the server response stdout content on success Returns None on failure, error message will be output to stderr """ data = {"query": query} headers = {'Content-Type': 'application/json'} try: response = requests.post( f'http://{server_endpoint}/query-sync', data=json.dumps(data), headers=headers, auth=basic_auth, timeout=timeout ) response.raise_for_status() result = response.json() return remove_ansi_escape_sequences(result.get('stdout', '')) except requests.exceptions.RequestException as e: sys.stderr.write(f"Request Error: {str(e)}\n") except json.JSONDecodeError: sys.stderr.write("Error: Invalid JSON response\n") return None
- common_tools.py:111-133 (helper)Helper function extract_value that parses the Joern response string to extract the method code value based on patterns like triple quotes for code blocks.def extract_value(input_str: str) -> str: """Extract value from a string based on its pattern. This function automatically selects the appropriate extraction method based on the input string format: * If contains 'Long =', uses extract_long_value * If contains triple quotes, uses extract_code_between_triple_quotes * If contains single quotes, uses extract_quoted_string Args: input_str (str): Input string containing a value to extract Returns: str: Extracted value based on the detected pattern """ if 'Long =' in input_str: return extract_long_value(input_str) elif 'String = """' in input_str: return extract_code_between_triple_quotes(input_str) elif 'String = "' in input_str: return extract_quoted_string(input_str) else: return input_str