Skip to main content
Glama
biocontext-ai

BioContextAI Knowledgebase MCP

Official

bc_get_string_network_image

Generate protein-protein interaction network visualizations from the STRING database for specific proteins and species, returning PNG images of biological networks.

Instructions

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.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
protein_symbolYesProtein name to search for (e.g., 'TP53')
speciesYesSpecies taxonomy ID (e.g., '10090' for mouse)
flavorNoNetwork flavor (e.g., 'confidence', 'evidence', 'actions')confidence
min_scoreNoMinimum combined score threshold (0-1000)

Implementation Reference

  • The primary handler function for the 'bc_get_string_network_image' tool. It uses inline Pydantic schema for input validation, fetches the STRING protein ID using a helper, constructs the API URL for the network image, retrieves and processes the PNG image, and returns it as an Image object or an error dictionary.
    @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}"}
  • Helper tool 'get_string_id' (likely 'bc_get_string_id') called by the main handler to resolve the protein_symbol and species to a STRING database ID.
    @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}"}
  • Defines core_mcp FastMCP instance with name 'BC' (providing the 'bc_' prefix for tools) where all core tools including get_string_network_image are registered via @core_mcp.tool() decorators.
    from fastmcp import FastMCP
    
    core_mcp = FastMCP(  # type: ignore
        "BC",
        instructions="Provides access to biomedical knowledge bases.",
    )
  • Imports the core_mcp server (with 'BC' tools) into the main 'BioContextAI' FastMCP app using slugify('BC')='bc' as the prefix, making tools available as 'bc_*'.
    for mcp in [core_mcp, *(await get_openapi_mcps())]:
        await mcp_app.import_server(
            mcp,
            slugify(mcp.name),
        )
    logger.info("MCP server setup complete.")
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions the return type ('Image or dict: Network visualization as PNG image object or error message'), which adds some behavioral context. However, it lacks details on error conditions, performance (e.g., rate limits), or side effects (e.g., whether it caches results). For a tool with no annotations, this is insufficient to fully inform agent behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and front-loaded, with the main purpose stated first. Both sentences earn their place: the first defines the tool, and the second clarifies the return type. It avoids redundancy and is appropriately sized for the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (4 parameters, no output schema, no annotations), the description is partially complete. It covers the basic purpose and return type but lacks details on error handling, usage scenarios, or integration with sibling tools. Without annotations or output schema, more context would be beneficial for agent decision-making.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema (e.g., it doesn't explain interactions between parameters like how min_score affects the image). With high schema coverage, the baseline score of 3 is appropriate as the description doesn't compensate but doesn't detract.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Generate protein-protein interaction network image from STRING database.' It specifies both the action ('generate') and resource ('network image'), and distinguishes itself from sibling tools like bc_get_string_interactions by focusing on visualization rather than raw data. However, it doesn't explicitly differentiate from all possible image-generation tools in the broader context.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides some usage guidance with 'Always provide species parameter,' which is helpful but basic. It doesn't explain when to use this tool versus alternatives like bc_get_string_interactions for non-visual data or other visualization tools. The guidance is implied rather than explicit about context or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/biocontext-ai/knowledgebase-mcp'

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