Skip to main content

Python package to integrate BioContext with the BioCypher ecosystem.

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

Basic Functionality

Client

The BioContext client provides an async connection to MCP (Model Context Protocol) servers. It allows you to discover and use tools and resources provided by MCP servers:

from biocontext import MCPConnection

# Initialize connection
async with MCPConnection("my-mcp-server", base_url="http://example.com") as connection:
    # Get available tools
    tools = await connection.get_tools()

    # Get available resources
    resources = await connection.get_resources()

    # Call a specific tool
    result = await connection.call_tool("tool_name", {"param": "value"})

Server

BioContext provides a flexible server implementation for creating and managing MCP (Model Context Protocol) servers. The server supports both core MCP functionality and integration with OpenAPI specifications:

from biocontext import MCPServer
from pathlib import Path

# Initialize server with basic configuration
server = MCPServer(
    name="my-mcp-server",
    version="1.0.0",
    author="Your Name",
    config_path=Path("config.yaml")
)

# Setup server with optional core MCP
mcp_app = await server.setup()

# The server now provides:
# - Tools from OpenAPI specifications
# - Resources and resource templates
# - Automatic validation of tools and resources
# - Logging of available tools and resources

The server supports configuration through a YAML file that specifies OpenAPI schemas to integrate:

schemas:
  - name: "my-api"
    url: "https://example.com/openapi.json"
    type: "json"  # or "yaml"
    base: "https://api.example.com"  # optional base URL

Key features of the server implementation:

  • Automatic downloading and parsing of OpenAPI specifications
  • Support for both JSON and YAML OpenAPI formats
  • Validation of tools, resources, and templates
  • Custom route mapping for tool endpoints
  • Comprehensive logging of server setup and available tools
  • Error handling for configuration and schema issues

For more detailed information about server configuration and usage, please refer to the Server Documentation.

Registry

The registry helps you discover and use biological tools and knowledge resources. It maintains metadata about MCP servers, knowledge graphs, and tools, making it easy to find what you need:

from biocontext import Registry

# Initialize registry
registry = Registry()

# Find tools for a specific task
protein_tools = registry.search_resources(
    type="tool",
    keywords=["protein", "sequence analysis"]
)

# Find knowledge graphs about specific topics
disease_kgs = registry.search_resources(
    type="knowledge_graph",
    keywords=["disease", "pathway"]
)

# Find MCP servers that provide specific capabilities
servers = registry.search_resources(
    type="mcp_server",
    capabilities=["protein analysis", "sequence alignment"]
)

# Get detailed information about a specific resource
tool_info = registry.get_resource("protein-analyzer-v1")
print(f"Tool: {tool_info.name}")
print(f"Description: {tool_info.description}")
print(f"Input types: {tool_info.inputData}")
print(f"Output types: {tool_info.outputData}")
print(f"Available at: {tool_info.url}")

The registry uses schema.org and BioSchemas standards to provide rich metadata about each resource, including:

  • Detailed descriptions and capabilities
  • Input/output data types
  • License information
  • Version history
  • Related tools and knowledge graphs
  • Query interfaces and endpoints

Documentation

Please visit our documentation.

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.1.2.tar.gz (83.4 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.1.2-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for biocontext-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6e881ebbb0bc36e9df81e08a50a1d2c920fc91422a7ccf068c33333daf484eeb
MD5 646237a2111468cae20bb26292c09196
BLAKE2b-256 86c6374d678edfb90ce082ae14cfa056110a3fb33b57bfee2e59a69ae1c2e015

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for biocontext-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6019338f48ab2d0080974f6305c87aa30a36064e71d0e867629c19fa77424774
MD5 63948df92e230849a632cd5108f87ca7
BLAKE2b-256 82638095daddf60c2557252abcbda2244ffff7cec956518a38c319091c9a4519

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