mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-23 05:54:19 +02:00
Update README.md
This commit is contained in:
parent
515cdd5cf5
commit
9788fabe19
1 changed files with 36 additions and 1 deletions
|
|
@ -4,6 +4,18 @@ This module provides the `MCPMixin` base class and associated decorators (`@mcp_
|
|||
|
||||
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.
|
||||
|
||||
Includes support for
|
||||
Tools:
|
||||
* [enable/disable](https://gofastmcp.com/servers/tools#disabling-tools)
|
||||
* [annotations](https://gofastmcp.com/servers/tools#annotations-2)
|
||||
* [excluded arguments](https://gofastmcp.com/servers/tools#excluding-arguments)
|
||||
|
||||
Prompts:
|
||||
* [enable/disable](https://gofastmcp.com/servers/prompts#disabling-prompts)
|
||||
|
||||
Resources:
|
||||
* [enable/disabe](https://gofastmcp.com/servers/resources#disabling-resources)
|
||||
|
||||
## Usage
|
||||
|
||||
Inherit from `MCPMixin` and use the decorators on the methods you want to register.
|
||||
|
|
@ -17,10 +29,33 @@ class MyComponent(MCPMixin):
|
|||
def tool_method(self):
|
||||
return "Tool executed!"
|
||||
|
||||
# example of disabled tool
|
||||
@mcp_tool(name="my_tool", description="Does something cool.", enabled=False)
|
||||
def disabled_tool_method(self):
|
||||
# This function can't be called by client because it's disabled
|
||||
return "You'll never get here!"
|
||||
|
||||
@mcp_tool(
|
||||
name="my_tool", description="Does something cool.",
|
||||
annotations={
|
||||
"title": "Attn LLM, use this tool first!",
|
||||
"readOnlyHint": False,
|
||||
"destructiveHint": False,
|
||||
"idempotentHint": False
|
||||
}
|
||||
)
|
||||
def tool_method(self):
|
||||
return "Tool executed!"
|
||||
|
||||
@mcp_resource(uri="component://data")
|
||||
def resource_method(self):
|
||||
return {"data": "some data"}
|
||||
|
||||
# Disabled resource
|
||||
@mcp_resource(uri="component://data", enabled=False)
|
||||
def resource_method(self):
|
||||
return {"data": "some data"}
|
||||
|
||||
mcp_server = FastMCP()
|
||||
component = MyComponent()
|
||||
|
||||
|
|
@ -36,4 +71,4 @@ component.register_all(mcp_server, prefix="my_comp")
|
|||
# Or 'my_tool' and 'component://data' are registered (if no prefix used)
|
||||
```
|
||||
|
||||
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.
|
||||
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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue