pirate_summary
Summarize any text in pirate style using LLM sampling. The output mimics pirate speech with a thematic twist.
Instructions
Summarise the given text in a pirate style. This is an example of a tool that can use LLM sampling to generate a summary.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/pymcp/server.py:283-292 (handler)The handler function for the pirate_summary tool. It takes a text string and uses LLM sampling (ctx.sample) to generate a pirate-style summary of the text.
async def pirate_summary(self, ctx: Context, text: str) -> str | None: """Summarise the given text in a pirate style. This is an example of a tool that can use LLM sampling to generate a summary.""" await ctx.info("Summarising text in pirate style using client LLM sampling.") response = await ctx.sample( messages=text, system_prompt="Your task is to summarise a given text in a pirate style. Use a fun and engaging tone but be concise.", temperature=0.9, # High creativity max_tokens=1024, # Pirates can be a bit verbose! ) return getattr(response, "text", None) - src/pymcp/server.py:76-76 (registration)Registration metadata for the pirate_summary tool in the PyMCP class's tools list. It maps the function name 'pirate_summary' with tags for discoverability.
{"fn": "pirate_summary", "tags": ["pirate-summary", "llm-sampling", "example"]}, - src/pymcp/mixin.py:24-39 (helper)The register_features method in the MCPMixin class iterates over the tools list and registers each tool (by looking up the function name via getattr) with the FastMCP instance. This is how pirate_summary gets registered as an MCP tool.
def register_features(self, mcp: FastMCP) -> FastMCP: """Register tools, resources, and prompts with the given FastMCP instance. Args: mcp (FastMCP): The FastMCP instance to register features with. Returns: FastMCP: The FastMCP instance with registered features. """ # Register tools for tool in self.tools: assert "fn" in tool, "Tool metadata must include the 'fn' key." tool_copy = copy.deepcopy(tool) fn_name = tool_copy.pop("fn") fn = getattr(self, fn_name) mcp.tool(**tool_copy)(fn) # pass remaining metadata as kwargs