list_spaces
Retrieve a formatted list of Snapshot space IDs and names to track decentralized governance proposals efficiently. Supports real-time decision-making for DAO monitoring.
Instructions
Fetch a list of available Snapshot spaces.
Parameters:
None
Returns:
A formatted string containing space IDs and names.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- main.py:19-56 (handler)The main handler function for the 'list_spaces' tool. It performs a GraphQL query to the Snapshot API to fetch the top 10 recently created spaces, formats their ID, name, and about text into a string, and returns it. Handles errors gracefully.async def list_spaces(ctx: Context) -> str: """ Fetch a list of available Snapshot spaces. Parameters: None Returns: A formatted string containing space IDs and names. """ query = """ query Spaces { spaces(first: 10, orderBy: "created", orderDirection: desc) { id name about } } """ async with httpx.AsyncClient() as client: try: response = await client.post(SNAPSHOT_API, json={"query": query}) response.raise_for_status() data = response.json() spaces = data.get("data", {}).get("spaces", []) # Format spaces as a readable string result = [] for i, space in enumerate(spaces): result.append( f"Space ID: {space['id']}\n" f"Name: {space['name']}\n" f"About: {space['about']}\n" "---" ) return "\n".join(result) if result else "No spaces found" except Exception as e: return f"Error: {str(e)}"
- main.py:18-18 (registration)The @mcp.tool() decorator registers the list_spaces function as an MCP tool.@mcp.tool()
- main.py:20-28 (schema)Docstring serving as the tool schema, describing no input parameters and string return value with formatted space list.""" Fetch a list of available Snapshot spaces. Parameters: None Returns: A formatted string containing space IDs and names. """