vonmises_random
Generate random angles from the von Mises distribution by specifying the mean direction and using elicitation to determine the concentration parameter.
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
| Name | Required | Description | Default |
|---|---|---|---|
| mu | Yes | The mean angle mu (μ), expressed in radians between 0 and 2π |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/pymcp/server.py:294-333 (handler)The vonmises_random async method is the tool handler. It takes a 'mu' parameter (radians between 0 and 2π), elicits 'kappa' from the user via ctx.elicit(), validates it, and returns a random value from the von Mises distribution using 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): 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(): await ctx.warning("User declined to provide kappa (κ). Using default value of 1.0.") case CancelledElicitation(): 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:297-304 (schema)Input schema: 'mu' parameter is a float annotated with Field constraints (ge=0, le=2*math.pi) describing the mean angle in radians. The return type is float.
mu: Annotated[ float, Field( description="The mean angle mu (μ), expressed in radians between 0 and 2π", ge=0, le=2 * math.pi, ), ], - src/pymcp/server.py:77-77 (registration)Tool registration entry in the PyMCP class's 'tools' list, mapping the function name 'vonmises_random' with tags ['experimental', 'elicitation', 'example'].
{"fn": "vonmises_random", "tags": ["experimental", "elicitation", "example"]}, - src/pymcp/server.py:333-333 (helper)Uses random.vonmisesvariate(mu, kappa) from Python's standard library to generate the random number from the von Mises distribution.
return random.vonmisesvariate(mu, kappa)