Python package for use with
Project description
BioContext
Python package for use with BioContext MCP servers to enable LLM tool use.
- Github repository: https://github.com/biocypher/biocontext/
- Documentation https://biocypher.github.io/biocontext/
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:
- Connect to or create MCP servers
- Get available tools and their descriptions
- Use the tools in your LLM prompts
- 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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file biocontext-0.0.2.tar.gz.
File metadata
- Download URL: biocontext-0.0.2.tar.gz
- Upload date:
- Size: 66.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a23c4c09310ee62fbee3f75babca3a03ce5f9fc8480157244e045c2480f48cdb
|
|
| MD5 |
08d9c16860c61789aa5ab262ec4ab0d9
|
|
| BLAKE2b-256 |
7a9a63ad55e2618e9ea45db899669dacefc6d14b605c0602c77ee0c081cdb7c5
|
File details
Details for the file biocontext-0.0.2-py3-none-any.whl.
File metadata
- Download URL: biocontext-0.0.2-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffbb00164cab839a828bb88e0ab00a24d8ce334c69b6df4bf06e965ce568ca2a
|
|
| MD5 |
7fe136c034423b444c41b3e418eb6409
|
|
| BLAKE2b-256 |
bf3df84909bdf79ad0bca511e12547f52d9ef45047d44e7f91fcce5db55052a1
|