Skip to main content
Glama

f0_make_randomvalues MCP Server

server.py2.17 kB
#!/usr/bin/env python3 """ MCP Server for f0_make_randomvalues Function Block Provides random number generation capabilities via Model Context Protocol """ from mcp.server.fastmcp import FastMCP, Context from pathlib import Path from contextlib import asynccontextmanager from dataclasses import dataclass, field from typing import Optional, List, AsyncIterator import logging # Configure logging logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' ) logger = logging.getLogger(__name__) # Application context @dataclass class AppContext: """Application state shared across requests""" data_dir: Path current_data: Optional[List[int]] = None stats_cache: dict = field(default_factory=dict) # Lifespan management @asynccontextmanager async def app_lifespan(server: FastMCP) -> AsyncIterator[AppContext]: """ Manage server lifecycle and application context. This context manager handles: - Directory initialization on startup - Resource cleanup on shutdown - Shared state management """ # Initialize on startup data_dir = Path("./data") data_dir.mkdir(exist_ok=True) context = AppContext( data_dir=data_dir, stats_cache={} ) logger.info(f"MCP Server '{server.name}' initialized") logger.info(f"Data directory: {data_dir.absolute()}") try: yield context finally: # Cleanup on shutdown logger.info(f"MCP Server '{server.name}' shutting down") # Create MCP server instance mcp = FastMCP( name="f0_random_server", lifespan=app_lifespan ) # Import tool, resource, and prompt implementations from tools import register_tools from resources import register_resources from prompts import register_prompts # Register all capabilities register_tools(mcp) register_resources(mcp) register_prompts(mcp) # Entry point if __name__ == "__main__": import sys # Check for debug mode if "--debug" in sys.argv: logging.getLogger().setLevel(logging.DEBUG) logger.debug("Debug mode enabled") # Run server logger.info("Starting MCP server...") mcp.run()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sengokusal2025/f0_20251002'

If you have feedback or need assistance with the MCP directory API, please join our Discord server