1. Description
The primary source for a component’s description is its module-level docstring.- This docstring is mandatory. If missing, the build will fail.
- The function docstring of the exported function is generally ignored if a module docstring is present. It might be used as a fallback if the module docstring is missing, but relying on this is not recommended.
2. Entry function (export)
GolfMCP needs to know which function within your Python file is the main entry point for the component. This is primarily done by assigning the function to a module-level variable named export.
export variable is not found, GolfMCP build will fail.
3. Function signature requirements
The signature of your exported function must adhere to certain rules:- Tools:
- Parameters must have type hints (e.g.,
param: str,count: int). - The return value must have a type hint (e.g.,
-> str,-> Dict[str, Any]). - Can be
async defordef.
- Parameters must have type hints (e.g.,
- Resources:
- If defined as a function, it follows similar rules to tools.
- Resource functions typically do not take arguments unless they are part of a resource template (where arguments come from URI path parameters).
- The URI for the resource is defined by a module-level variable
resource_uri: str. - Example:
resource_uri = "data://config" - Can also be a simple module-level constant (JSON-serializable).
- Prompts:
- The function should return either a
str(which becomes a single user message) or aList[Dict]. - Parameters should have type hints.
- The function should return either a
BaseModel is highly recommended for defining complex input argument structures and output shapes, enabling clear schemas and validation.
-
Input Parameters & Schema:
Tool inputs are always defined by the parameters of your exported tool function. These parameters must have type hints and descriptions.
- Direct Function Parameters: You define inputs directly in the tool function’s signature.
- Direct Function Parameters: You define inputs directly in the tool function’s signature.
-
Output Structure & Schema:
The structure of your tool’s output should be defined by its return type hint. It is strongly recommended to use a Pydantic
BaseModelfor this return type to ensure a clear and validated output schema.
4. Parameter annotations (recommended)
While simple type hints are sufficient, usingAnnotated with Pydantic Field provides rich descriptions and validation that significantly improves how AI agents understand and use your tools.
Basic parameter annotations
Parameter validation
Field annotations support various validation constraints:5. Tool annotations (MCP behavioral hints)
Tool annotations provide behavioral hints about your tools to MCP clients, following the official MCP specification. These hints help clients understand how to interact with your tools safely and efficiently.Overview
Add anannotations dictionary at the module level to specify behavioral hints:
Supported annotation types
boolean
true → tool cannot change state (pure “GET-style” call)Note: When true, other hints are ignored by MCP clients.boolean
true → tool may delete or irreversibly mutate dataOnly meaningful when readOnlyHint is false.boolean
true → repeated calls with identical arguments are safe and side-effect-freeHelps MCP clients add caching and deduplication.boolean
true → behavior depends on external mutable state (e.g., live web, clock)Signals lower reproducibility to MCP clients.