encode_point_color
Set node color encoding in a graph using a specified column, with options for categorical mapping, default colors, or continuous gradients via Graphistry MCP.
Instructions
Set node color encoding for a graph using Graphistry's encode_point_color API.
Args:
graph_id (str): The ID of the graph to modify (from visualize_graph).
column (str): The node column to use for color encoding (e.g., 'type', 'score').
categorical_mapping (dict, optional): Map of category values to color codes. Example: {'mac': '#F99', 'macbook': '#99F'}. If not provided, Graphistry will auto-assign colors.
default_mapping (str, optional): Color code to use for values not in categorical_mapping. Example: 'silver'.
as_continuous (bool, optional): If True, treat the column as continuous and use a gradient palette. Example: True for numeric columns like 'score'.
Returns:
dict: { 'graph_id': ..., 'url': ... } with the updated visualization URL.
Example:
encode_point_color(graph_id, column='type', categorical_mapping={'mac': '#F99', 'macbook': '#99F'}, default_mapping='silver')
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| as_continuous | No | ||
| categorical_mapping | No | ||
| column | Yes | ||
| default_mapping | No | ||
| graph_id | Yes |
Implementation Reference
- The main handler function for the 'encode_point_color' tool. It is registered with @mcp.tool(), defines the input schema via type hints and docstring, retrieves the graph from cache, applies Graphistry's encode_point_color method with dynamic kwargs, updates the cache, and returns the graph ID and updated visualization URL.async def encode_point_color( graph_id: str, column: str, categorical_mapping: Optional[dict] = None, default_mapping: Optional[str] = None, as_continuous: Optional[bool] = False ) -> Dict[str, Any]: """ Set node color encoding for a graph using Graphistry's encode_point_color API. Args: graph_id (str): The ID of the graph to modify (from visualize_graph). column (str): The node column to use for color encoding (e.g., 'type', 'score'). categorical_mapping (dict, optional): Map of category values to color codes. Example: {'mac': '#F99', 'macbook': '#99F'}. If not provided, Graphistry will auto-assign colors. default_mapping (str, optional): Color code to use for values not in categorical_mapping. Example: 'silver'. as_continuous (bool, optional): If True, treat the column as continuous and use a gradient palette. Example: True for numeric columns like 'score'. Returns: dict: { 'graph_id': ..., 'url': ... } with the updated visualization URL. Example: encode_point_color(graph_id, column='type', categorical_mapping={'mac': '#F99', 'macbook': '#99F'}, default_mapping='silver') """ if graph_id not in graph_cache: raise ValueError(f"Graph not found: {graph_id}") g = graph_cache[graph_id]["graph"] kwargs = {"column": column} if categorical_mapping: kwargs["categorical_mapping"] = categorical_mapping if default_mapping: kwargs["default_mapping"] = default_mapping if as_continuous: kwargs["as_continuous"] = as_continuous g = g.encode_point_color(**kwargs) graph_cache[graph_id]["graph"] = g return {"graph_id": graph_id, "url": g.plot(render=False)}
- src/graphistry_mcp_server/server.py:334-334 (registration)The @mcp.tool() decorator registers the encode_point_color function as an MCP tool.async def encode_point_color(
- Function signature defines the input parameters and return type, serving as the tool schema for MCP.async def encode_point_color( graph_id: str, column: str, categorical_mapping: Optional[dict] = None, default_mapping: Optional[str] = None, as_continuous: Optional[bool] = False ) -> Dict[str, Any]: