Skip to main content

Python package for use with

Project description

BioContext

Release Build status codecov Commit activity License

Python package for use with BioContext MCP servers to enable LLM tool use.

Installation

pip install biocontext

Quick Start

from biocontext import MCPConnection, OpenAPIServerFactory

# Connect to an existing MCP server
async with MCPConnection("my-server") as conn:
    # Get available tools
    tools = await conn.get_tools()

    # Call a tool
    result = await conn.call_tool("tool-name", {"param": "value"})

# Create MCP servers from OpenAPI specs
factory = OpenAPIServerFactory()
servers = await factory.create_servers()

Use Cases

1. Connecting to Existing MCP Servers

Use MCPConnection to connect to any MCP server and access its tools:

from biocontext import MCPConnection

async def use_remote_tools():
    async with MCPConnection("my-server") as conn:
        # List available tools
        tools = await conn.get_tools()
        print(f"Available tools: {list(tools.keys())}")

        # Call a tool
        result = await conn.call_tool("search", {"query": "example"})
        print(f"Search results: {result}")

2. Creating MCP Servers from OpenAPI Specs

Use OpenAPIServerFactory to create MCP servers from OpenAPI specifications:

from biocontext import OpenAPIServerFactory

async def create_servers():
    # Create servers from OpenAPI specs
    factory = OpenAPIServerFactory()
    servers = await factory.create_servers()

    # Use the created servers
    for server in servers:
        tools = await server.get_tools()
        print(f"Server {server.name} has tools: {list(tools.keys())}")

Configuration

OpenAPI Server Configuration

Create a config.yaml file in the biocontext/config directory:

schemas:
  - name: example-server
    url: https://api.example.com/openapi.json
    type: json
    base: https://api.example.com

Integration with LLMs

The package is designed to work seamlessly with LLMs. Here's a typical workflow:

  1. Connect to or create MCP servers
  2. Get available tools and their descriptions
  3. Use the tools in your LLM prompts
  4. Call tools based on LLM decisions

Example with an LLM:

from biocontext import MCPConnection

async def llm_workflow():
    async with MCPConnection("my-server") as conn:
        # Get tool descriptions for the LLM
        tools = await conn.get_tools()

        # Example LLM prompt
        prompt = f"""
        Available tools:
        {tools}

        User request: Search for information about proteins
        """

        # LLM decides to use the search tool
        result = await conn.call_tool("search", {"query": "proteins"})

Installation

pip install biocontext

Requirements

  • Python 3.8+
  • fastmcp
  • httpx
  • requests
  • pyyaml

Features

  • Simple interface for interacting with MCP servers
  • Support for OpenAPI-based MCP servers
  • Async/await support for efficient I/O operations
  • Utility functions for common operations

Development

We use uv for dependency management and versioning. The script bump.sh is used to bump the version and create a git tag, which then can be used to create a release on GitHub that triggers publication to PyPI. It can be used with semantic versioning by passing the bump type as an argument, e.g. ./bump.sh patch.

License

MIT License - see LICENSE file for details

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

biocontext-0.0.8.tar.gz (74.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

biocontext-0.0.8-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file biocontext-0.0.8.tar.gz.

File metadata

  • Download URL: biocontext-0.0.8.tar.gz
  • Upload date:
  • Size: 74.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for biocontext-0.0.8.tar.gz
Algorithm Hash digest
SHA256 7de2da52667baf78103a156221e09a35162a290013449729417d9c8f0f94c0f6
MD5 1177e624d0ecf392fd2159077619d606
BLAKE2b-256 e7d3ec543a4fe01797cf63c942e33a4180a8ddbebc18064b25b71f218a10d577

See more details on using hashes here.

File details

Details for the file biocontext-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: biocontext-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for biocontext-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 5f2e040ab6d7276787fc2ce59228ec5fde62cf130fe37b788e3f3251db820506
MD5 f42077ea068ad46da2cdce8431051f74
BLAKE2b-256 84c78c535f9596a76e1cad05c7a4b4a4344a57f98eccca8a551078b202e90413

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page