Skip to main content
Glama

execute_query

Run queries on NebulaGraph database to retrieve graph data and insights from specified spaces.

Instructions

Execute a query Args: query: The query to execute space: The space to use Returns: The results of the query

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
spaceYes

Implementation Reference

  • The 'execute_query' tool handler function. Decorated with @mcp.tool(), it connects to NebulaGraph, switches to the specified space, executes the provided query, formats and returns the results or error message.
    @mcp.tool() def execute_query(query: str, space: str) -> str: """Execute a query Args: query: The query to execute space: The space to use Returns: The results of the query """ pool = get_connection_pool() session = pool.get_session( os.getenv("NEBULA_USER", "root"), os.getenv("NEBULA_PASSWORD", "nebula") ) try: session.execute(f"USE {space}") result = session.execute(query) if result.is_succeeded(): # Format the query results if result.row_size() > 0: columns = result.keys() output = "Results:\n" output += " | ".join(columns) + "\n" output += "-" * (len(" | ".join(columns))) + "\n" # Iterate through all rows for i in range(result.row_size()): row = result.row_values(i) output += " | ".join(str(val) for val in row) + "\n" return output return "Query executed successfully (no results)" else: return f"Query failed: {result.error_msg()}" finally: session.release()
  • The @mcp.tool() decorator registers the 'execute_query' function as an MCP tool.
    @mcp.tool()
  • Function signature and docstring define the input schema (query: str, space: str) and output (str) for the tool, used by MCP for validation.
    def execute_query(query: str, space: str) -> str: """Execute a query Args: query: The query to execute space: The space to use Returns: The results of the query """

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nebula-contrib/nebulagraph-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server