Tool Mode Development Guide
This guide demonstrates how to develop an MCP (Model Context Protocol) based scmcphub API using Tool Mode. Tool Mode allows you to create custom tools that can be integrated into the scmcphub ecosystem for single-cell analysis workflows.Overview
- Provide standardized interfaces for data processing
- Build reusable components for the scmcphub community
What We’ll Build
We’ll create a simple demo that demonstrates the basic structure of an MCP tool. This demo will:- Query data from
adata.uns
(unstructured data storage in AnnData) - List available keys in the unstructured data
- Follow scmcphub conventions
Project Setup
1. Install UV Package Manager
UV is a fast Python package installer and resolver. It’s recommended for scmcphub development:2. Initialize the Project
Create a new MCP project using UV:3. Create Required Files
We need to create three main files for our MCP tool:Implementation Details
1. Schema Definition (schema.py
)
The schema file defines the input parameters for your tools using Pydantic models. This ensures type safety and provides automatic validation:
Field(...)
indicates this is a required parameter- The
description
provides documentation for the tool - Pydantic automatically validates the input type
2. Server Implementation (server.py
)
The server file contains the core logic of your MCP tools. Here’s a detailed breakdown:
- AdataInfo: Standard parameter for specifying which AnnData object to use
- get_ads(): Utility function to access the AnnData manager
3. CLI Implementation (cli.py
)
The CLI file provides a command-line interface for your MCP tools in scmcphub:
- Standardized CLI interface across all scmcphub tools
- Built-in help and documentation
- Consistent command-line argument handling
- Integration with the broader scmcphub ecosystem