list_spaces
Fetch available Snapshot spaces to identify governance platforms for tracking DAO proposals and decentralized decision-making.
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:18-56 (handler)The handler function for the 'list_spaces' tool. It uses a GraphQL query to fetch the latest 10 Snapshot spaces, formats their ID, name, and about text, and returns as a string. Includes error handling.@mcp.tool() 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)}"