search_substructure
Search for chemical compounds by substructure using SMILES strings to find synthesizable building blocks and screening compounds.
Instructions
Substructure search by SMILES
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| smiles | Yes | ||
| shipToCountry | No | The country you want your order to be shipped to as two-letter country ISO code, e.g DE, US, FR | US |
| count | No | Maximum number of results on a page | |
| page | No | Number of the page | |
| categories | No | A list of product categories to searchCSSB - In-stock building blocksCSSS - In-stock screening compoundsCSMB - Make-on-demand building blocksCSMS - Make-on-demand screening compoundsCSCS - Custom request |
Implementation Reference
- src/chemspace_mcp/tools.py:73-105 (handler)The async handler function that implements the core logic of the 'search_substructure' tool. It performs a substructure search by posting the SMILES to the Chemspace API /v4/search/sub endpoint, authenticates with a token, and returns the JSON response.@mcp.tool(enabled=True) async def search_substructure( smiles: str, shipToCountry: Country = "US", count: ResultCount = 10, page: ResultPage = 1, categories: ProductCategories = ["CSSB", "CSMB"], ): """Substructure search by SMILES""" access_token = await mgr.get_token() async with httpx.AsyncClient() as client: r = await client.post( url="https://api.chem-space.com/v4/search/sub", headers={ "Accept": "application/json; version=4.1", "Authorization": f"Bearer {access_token}", }, params={ "shipToCountry": shipToCountry, "count": count, "page": page, "categories": ",".join(categories), }, files={ "SMILES": (None, smiles), }, ) r.raise_for_status() data = r.json() return data
- src/chemspace_mcp/tools.py:8-36 (schema)Pydantic Annotated type definitions for input parameters used in the search_substructure tool (and other search tools): Country, ResultCount, ResultPage, ProductCategory, ProductCategories.Country = Annotated[ str, Field( description="The country you want your order to be shipped to as two-letter country ISO code, e.g DE, US, FR" ), ] ResultCount = Annotated[ int, Field(description="Maximum number of results on a page", ge=1) ] ResultPage = Annotated[int, Field(description="Number of the page", ge=1)] ProductCategory = Literal["CSSB", "CSSS", "CSMB", "CSMS", "CSCS"] ProductCategories = Annotated[ List[ProductCategory], Field( description=( "A list of product categories to search" "CSSB - In-stock building blocks" "CSSS - In-stock screening compounds" "CSMB - Make-on-demand building blocks" "CSMS - Make-on-demand screening compounds" "CSCS - Custom request" ), min_length=1, ), ]
- src/chemspace_mcp/__init__.py:10-10 (registration)Invocation of register_tools(mcp, mgr) which defines and registers the search_substructure tool (via decorator) with the FastMCP server instance.register_tools(mcp, mgr)