Spaces:
Running
Running
Ryan Malloy commited on
Update README.md
Browse files
src/fastmcp/contrib/mcp_mixin/README.md
CHANGED
|
@@ -4,6 +4,18 @@ This module provides the `MCPMixin` base class and associated decorators (`@mcp_
|
|
| 4 |
|
| 5 |
It allows developers to easily define classes whose methods can be registered as tools, resources, or prompts with a `FastMCP` server instance using the `register_all()`, `register_tools()`, `register_resources()`, or `register_prompts()` methods provided by the mixin.
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
## Usage
|
| 8 |
|
| 9 |
Inherit from `MCPMixin` and use the decorators on the methods you want to register.
|
|
@@ -17,10 +29,33 @@ class MyComponent(MCPMixin):
|
|
| 17 |
def tool_method(self):
|
| 18 |
return "Tool executed!"
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
@mcp_resource(uri="component://data")
|
| 21 |
def resource_method(self):
|
| 22 |
return {"data": "some data"}
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
mcp_server = FastMCP()
|
| 25 |
component = MyComponent()
|
| 26 |
|
|
@@ -36,4 +71,4 @@ component.register_all(mcp_server, prefix="my_comp")
|
|
| 36 |
# Or 'my_tool' and 'component://data' are registered (if no prefix used)
|
| 37 |
```
|
| 38 |
|
| 39 |
-
The `prefix` argument in registration methods is optional. If omitted, methods are registered with their original decorated names/URIs. Individual separators (`tools_separator`, `resources_separator`, `prompts_separator`) can also be provided to `register_all` to change the separator for specific types.
|
|
|
|
| 4 |
|
| 5 |
It allows developers to easily define classes whose methods can be registered as tools, resources, or prompts with a `FastMCP` server instance using the `register_all()`, `register_tools()`, `register_resources()`, or `register_prompts()` methods provided by the mixin.
|
| 6 |
|
| 7 |
+
Includes support for
|
| 8 |
+
Tools:
|
| 9 |
+
* [enable/disable](https://gofastmcp.com/servers/tools#disabling-tools)
|
| 10 |
+
* [annotations](https://gofastmcp.com/servers/tools#annotations-2)
|
| 11 |
+
* [excluded arguments](https://gofastmcp.com/servers/tools#excluding-arguments)
|
| 12 |
+
|
| 13 |
+
Prompts:
|
| 14 |
+
* [enable/disable](https://gofastmcp.com/servers/prompts#disabling-prompts)
|
| 15 |
+
|
| 16 |
+
Resources:
|
| 17 |
+
* [enable/disabe](https://gofastmcp.com/servers/resources#disabling-resources)
|
| 18 |
+
|
| 19 |
## Usage
|
| 20 |
|
| 21 |
Inherit from `MCPMixin` and use the decorators on the methods you want to register.
|
|
|
|
| 29 |
def tool_method(self):
|
| 30 |
return "Tool executed!"
|
| 31 |
|
| 32 |
+
# example of disabled tool
|
| 33 |
+
@mcp_tool(name="my_tool", description="Does something cool.", enabled=False)
|
| 34 |
+
def disabled_tool_method(self):
|
| 35 |
+
# This function can't be called by client because it's disabled
|
| 36 |
+
return "You'll never get here!"
|
| 37 |
+
|
| 38 |
+
@mcp_tool(
|
| 39 |
+
name="my_tool", description="Does something cool.",
|
| 40 |
+
annotations={
|
| 41 |
+
"title": "Attn LLM, use this tool first!",
|
| 42 |
+
"readOnlyHint": False,
|
| 43 |
+
"destructiveHint": False,
|
| 44 |
+
"idempotentHint": False
|
| 45 |
+
}
|
| 46 |
+
)
|
| 47 |
+
def tool_method(self):
|
| 48 |
+
return "Tool executed!"
|
| 49 |
+
|
| 50 |
@mcp_resource(uri="component://data")
|
| 51 |
def resource_method(self):
|
| 52 |
return {"data": "some data"}
|
| 53 |
|
| 54 |
+
# Disabled resource
|
| 55 |
+
@mcp_resource(uri="component://data", enabled=False)
|
| 56 |
+
def resource_method(self):
|
| 57 |
+
return {"data": "some data"}
|
| 58 |
+
|
| 59 |
mcp_server = FastMCP()
|
| 60 |
component = MyComponent()
|
| 61 |
|
|
|
|
| 71 |
# Or 'my_tool' and 'component://data' are registered (if no prefix used)
|
| 72 |
```
|
| 73 |
|
| 74 |
+
The `prefix` argument in registration methods is optional. If omitted, methods are registered with their original decorated names/URIs. Individual separators (`tools_separator`, `resources_separator`, `prompts_separator`) can also be provided to `register_all` to change the separator for specific types.
|