bc_get_string_network_image
Retrieve a network image for a specific protein from the STRING database. Specify the protein symbol, species taxonomy ID, and optional parameters like network flavor and score threshold to generate the image.
Instructions
Get a network image for a given protein from the STRING database.
Always provide the species parameter to ensure the correct protein is returned.
Args: protein_symbol (str): The name of the protein to search for (e.g., "TP53"). species (str): The species taxonomy ID (e.g., "10090" for mouse). flavor (str): The network flavor to use (default: "confidence"). min_score (int): Minimum combined score threshold (default: 700).
Returns: Image: The network image for the protein.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| flavor | No | The network flavor to use | confidence |
| min_score | No | Minimum combined score threshold | |
| protein_symbol | Yes | The name of the protein to search for (e.g., 'TP53') | |
| species | Yes | The species taxonomy ID (e.g., '10090' for mouse) |
Implementation Reference
- The core handler function for the 'bc_get_string_network_image' tool (registered as 'get_string_network_image' under 'BC' MCP prefix). It resolves the protein STRING ID, queries the STRING API for a network PNG image based on parameters, processes it with PIL, and returns an Image object or error dict.@core_mcp.tool() def get_string_network_image( protein_symbol: Annotated[str, Field(description="Protein name to search for (e.g., 'TP53')")], species: Annotated[str, Field(description="Species taxonomy ID (e.g., '10090' for mouse)")], flavor: Annotated[ str, Field(description="Network flavor (e.g., 'confidence', 'evidence', 'actions')") ] = "confidence", min_score: Annotated[int, Field(description="Minimum combined score threshold (0-1000)", ge=0, le=1000)] = 700, ) -> Image | dict: """Generate protein-protein interaction network image from STRING database. Always provide species parameter. Returns: Image or dict: Network visualization as PNG image object or error message. """ # First resolve the protein name to a STRING ID try: string_id = get_string_id.fn(protein_symbol=protein_symbol, species=species) if not string_id or not isinstance(string_id, str): return {"error": f"No STRING ID found for protein: {protein_symbol}"} url = f"https://string-db.org/api/image/network?identifiers={string_id}&species={species}&required_score={min_score}&network_flavor={flavor}&format=png" response = requests.get(url) response.raise_for_status() img = PILImage.open(BytesIO(response.content)) buffer = BytesIO() img.save(buffer, format="PNG") img_bytes = buffer.getvalue() return Image(data=img_bytes, format="png") except requests.exceptions.RequestException as e: return {"error": f"Failed to fetch image: {e!s}"} except Exception as e: return {"error": f"An error occurred: {e!s}"}
- src/biocontext_kb/core/__init__.py:19-19 (registration)Import statement that loads all STRING DB tools (including get_string_network_image), triggering their automatic registration via the @core_mcp.tool() decorator on the FastMCP instance named 'BC', likely prefixing tool names with 'bc_'.from .stringdb import *
- Supporting helper tool 'get_string_id' (used via get_string_id.fn() in the main handler) that maps protein symbols to STRING database IDs via the STRING API.@core_mcp.tool() def get_string_id( protein_symbol: Annotated[str, Field(description="Protein name or identifier (e.g., 'TP53')")], species: Annotated[str, Field(description="Species taxonomy ID (e.g., '9606' for human)")] = "", return_field: Annotated[str, Field(description="Field to return: 'stringId' or 'preferredName'")] = "stringId", limit: Annotated[int, Field(description="Maximum number of matches to return")] = 1, ) -> Union[dict, str]: """Map protein identifiers (gene names, synonyms, UniProt IDs) to STRING database IDs. Using STRING IDs improves reliability. Returns: str or dict: STRING ID string (e.g., '9606.ENSP00000269305') or dict with error message. """ url = f"https://string-db.org/api/json/get_string_ids?identifiers={protein_symbol}&echo_query=1&limit={limit}" if species: url += f"&species={species}" try: response = requests.get(url) response.raise_for_status() data = response.json() if isinstance(data, dict) and "error" in data: return data if not data: return {"error": f"No STRING ID found for protein: {protein_symbol}"} return data[0].get(return_field) except requests.exceptions.RequestException as e: return {"error": f"Failed to fetch STRING ID: {e!s}"}
- src/biocontext_kb/core/_server.py:3-6 (registration)Definition of the FastMCP server instance 'core_mcp' with name 'BC', used for tool decorators. Tools registered under this instance likely get prefixed with 'bc_' (e.g., 'bc_get_string_network_image').core_mcp = FastMCP( # type: ignore "BC", instructions="Provides access to biomedical knowledge bases.", )