Skip to main content

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:
This creates a basic Python package structure with the following layout:

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:
Key Points:
  • 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:
Important Concepts:
  1. AdataInfo: Standard parameter for specifying which AnnData object to use
  2. 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:
Benefits of using MCPCLI:
  • Standardized CLI interface across all scmcphub tools
  • Built-in help and documentation
  • Consistent command-line argument handling
  • Integration with the broader scmcphub ecosystem

4. Package Configuration (pyproject.toml)

Update the project configuration to include all necessary dependencies:

Running the Demo

1. Install in Development Mode

Install your package in development mode to enable live code changes:

2. Test the CLI

Run the MCP server in tool mode:
This starts the server and makes your tools available for use.