Skip to main content
Glama
base.py1.5 kB
"""Base prompt implementation.""" from abc import ABC, abstractmethod from typing import Any import mcp.types as types class BasePrompt(ABC): """Base class for MCP prompts.""" def __init__(self, name: str, description: str = "", arguments: list[dict[str, Any]] | None = None) -> None: """Initialize the prompt. Args: name: Prompt name description: Prompt description arguments: Prompt arguments schema """ self.name = name self.description = description self.arguments = arguments or [] @abstractmethod async def generate(self, arguments: dict[str, str] | None = None) -> types.GetPromptResult: """Generate the prompt with given arguments. Args: arguments: Prompt arguments Returns: Generated prompt result """ pass def to_mcp_prompt(self) -> types.Prompt: """Convert to MCP Prompt type. Returns: MCP Prompt instance """ prompt_args = [] for arg in self.arguments: prompt_args.append( types.PromptArgument( name=arg["name"], description=arg.get("description", ""), required=arg.get("required", False), ) ) return types.Prompt( name=self.name, description=self.description, arguments=prompt_args, )

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/namnd00/mcp-server-hero'

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