duck.contrib.mcp.decorators¶
Decorators for MCPView.
Module Contents¶
Functions¶
Extract a short description from a function’s docstring. |
|
Mark a method as an MCP prompt template, listed via |
|
Resolve MCP metadata description. |
|
Mark a method as an MCP resource, addressable at |
|
Mark a method as an MCP resource template. |
|
Build a JSON Schema “object” definition from a function’s signature,
using its type hints for property types and the presence/absence of a
default value to determine which parameters are required. |
|
Mark a method as an MCP tool. The method’s signature is introspected to
build its JSON Schema |
Data¶
API¶
- duck.contrib.mcp.decorators.PY_TO_JSON_TYPE¶
None
- duck.contrib.mcp.decorators.get_summary_from_docstring(func) str[source]¶
Extract a short description from a function’s docstring.
The function uses the docstring summary section, stopping before common Google-style docstring sections such as Args, Returns, Raises, Examples, and Notes.
- Parameters:
func – Function whose docstring should be inspected.
- Returns:
A cleaned description string, or an empty string when no docstring exists.
- duck.contrib.mcp.decorators.prompt(description: str = '', name: str = None, scopes: list = None)[source]¶
Mark a method as an MCP prompt template, listed via
prompts/listand rendered viaprompts/getusing the given (or inferred) name. The method’s signature is introspected the same way as for tools.scopes, if given, are required scopes checked againstself.granted_scopes(set inauthenticate()) before it’s rendered.
- duck.contrib.mcp.decorators.resolve_description(func, description: str = '') str[source]¶
Resolve MCP metadata description.
Explicit decorator descriptions take priority. If no description is provided, the function docstring summary is used.
- Parameters:
func – Function being decorated.
description – Explicit MCP description.
- Returns:
Resolved description string.
- duck.contrib.mcp.decorators.resource(uri: str, name: str, description: str = '', mime_type: str = 'text/plain', scopes: list = None)[source]¶
Mark a method as an MCP resource, addressable at
uriand readable via theresources/readRPC method.The method should take no arguments (beyond
self) and return the resource’s content.- Parameters:
uri – Unique URI identifying the resource.
name – Human-readable resource name displayed by MCP clients.
description – Optional description of the resource.
mime_type – MIME type of the returned resource content.
scopes – Optional authorization scopes required to read the resource. Checked against
self.granted_scopes(set inauthenticate()).
- Raises:
TypeError – If the decorated method is not asynchronous.
- duck.contrib.mcp.decorators.resource_template(uri_template: str, name: str, description: str = '', mime_type: str = 'text/plain', scopes: list = None)[source]¶
Mark a method as an MCP resource template.
Resource templates describe dynamic resources that can be resolved from URI templates. The method should accept the extracted URI template arguments and return the resource content.
- Parameters:
uri_template – URI template used to match dynamic resources.
name – Human-readable resource template name.
description – Optional description of the resource template.
mime_type – MIME type of the returned resource content.
scopes – Optional authorization scopes required to access the resource.
- Raises:
TypeError – If the decorated method is not asynchronous.
- duck.contrib.mcp.decorators.schema_from_signature(func) dict[source]¶
Build a JSON Schema “object” definition from a function’s signature, using its type hints for property types and the presence/absence of a default value to determine which parameters are required.
selfis skipped. Unannotated parameters default to “string”.
- duck.contrib.mcp.decorators.tool(description: str = '', name: str = None, scopes: list = None)[source]¶
Mark a method as an MCP tool. The method’s signature is introspected to build its JSON Schema
inputSchema, and it becomes callable via thetools/callRPC method using the given (or inferred) name.scopes, if given, are required scopes checked againstself.granted_scopes(set inauthenticate()) before the tool runs.