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

Development

Install the project using make install. Test code quality using make check. Run tests using make test. Bump version using ./bump.sh <patch|minor|major>. Build and deploy docs locally using uv run mkdocs serve.

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.3.tar.gz (84.5 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.3-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for biocontext-0.1.3.tar.gz
Algorithm Hash digest
SHA256 8ece140ba6755d7b2be6f1fefb5cd1adc4523bd48ef66c0cb20e526aca6d57a9
MD5 ac5bf0f09f4e4f01d4cb7c34442305c5
BLAKE2b-256 048372d555bcfe763041e2f8a937b381c2d4733a3f3b59254cb68093164b6ffa

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for biocontext-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cba8bbed51c4ee72bffe1e68ef9612c92cd75c86affbaefb0d1e1bdcb47f5a97
MD5 b6595753352e4bbd1a1fe3950a0a7e9f
BLAKE2b-256 07039cba995cf9edfc7dd5dbef1d5423a789bba96a6c8f527e138ac7df3c91d6

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