vonmises_random
Generate random numbers from the von Mises distribution for circular data analysis by specifying the mean angle in radians.
Instructions
Generate a random number from the von Mises distribution. This is an example of a tool that uses elicitation to obtain the required parameter kappa (κ).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| mu | Yes | The mean angle mu (μ), expressed in radians between 0 and 2π |
Implementation Reference
- src/pymcp/server.py:264-304 (handler)The main handler function for the 'vonmises_random' tool. It takes mu as input, elicits kappa from the user, validates it, and returns a random sample from the von Mises distribution using Python's random.vonmisesvariate.async def vonmises_random( self, ctx: Context, mu: Annotated[ float, Field( description="The mean angle mu (μ), expressed in radians between 0 and 2π", ge=0, le=2 * math.pi, ), ], ) -> float: """Generate a random number from the von Mises distribution. This is an example of a tool that uses elicitation to obtain the required parameter kappa (κ).""" await ctx.info("Requesting the user for the value of kappa for von Mises distribution.") response = await ctx.elicit( message="Please provide the value of kappa (κ) for the von Mises distribution. It should be a positive number.", response_type=float, ) kappa: float = 1.0 # Default value match response: # pragma: no cover case AcceptedElicitation(data=kappa): # type: ignore[misc] await ctx.warning(f"Received kappa: {kappa}") if kappa < 0: raise McpError( error=ErrorData( code=INVALID_PARAMS, message="kappa (κ) must be a positive number.", ) ) case DeclinedElicitation(): # type: ignore[misc] await ctx.warning("User declined to provide kappa (κ). Using default value of 1.0.") case CancelledElicitation(): # type: ignore[misc] await ctx.warning("User cancelled the operation. The random number will NOT be generated.") raise McpError( error=ErrorData( code=INVALID_PARAMS, message="Operation cancelled by the user.", ) ) return random.vonmisesvariate(mu, kappa)
- src/pymcp/server.py:267-275 (schema)Pydantic-based input schema definition for the 'mu' parameter, including description and range constraints (0 to 2π). Kappa is elicited at runtime.mu: Annotated[ float, Field( description="The mean angle mu (μ), expressed in radians between 0 and 2π", ge=0, le=2 * math.pi, ), ], ) -> float:
- src/pymcp/server.py:72-72 (registration)Tool registration entry in the PyMCP class 'tools' list, specifying the function name and tags.{"fn": "vonmises_random", "tags": ["experimental", "elicitation", "example"]},