Skip to main content
Glama
jjunmomo

BaaS SMS/MCP Server

by jjunmomo

generate_direct_api_code

Create code to integrate BaaS API for SMS/MMS features by fetching templates from CDN. Supports multiple languages and frameworks, includes examples, and automatically injects API keys for secure production deployments.

Instructions

Generate code that directly calls BaaS API by fetching templates from CDN

Perfect for: Production deployments, custom integrations, framework-specific implementations
Token-optimized: Fetches maintained templates from CDN instead of generating locally

Args:
    language: Programming language (javascript, python, php, java, go, csharp)
    framework: Optional framework (react, vue, django, laravel, fastapi, spring, etc.)
    include_examples: Include usage examples and configuration templates
    
Returns:
    Dictionary with code fetched from CDN, filename, and integration instructions
    Code directly calls https://api.aiapp.link/api/message/ with X-API-KEY header authentication
    If MCP server has BAAS_API_KEY set, it will be automatically injected into code

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
frameworkNo
include_examplesNo
languageNojavascript

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • FastMCP decorator that registers the 'generate_direct_api_code' tool.
    @mcp.tool()
  • Function signature with type hints defining input schema (language, framework, include_examples) and output Dict[str, Any], plus comprehensive docstring describing parameters and return value.
    async def generate_direct_api_code(
        language: str = "javascript",
        framework: Optional[str] = None,
        include_examples: bool = True
    ) -> Dict[str, Any]:
        """
        Generate code that directly calls BaaS API by fetching templates from CDN
        
        Perfect for: Production deployments, custom integrations, framework-specific implementations
        Token-optimized: Fetches maintained templates from CDN instead of generating locally
        
        Args:
            language: Programming language (javascript, python, php, java, go, csharp)
            framework: Optional framework (react, vue, django, laravel, fastapi, spring, etc.)
            include_examples: Include usage examples and configuration templates
            
        Returns:
            Dictionary with code fetched from CDN, filename, and integration instructions
            Code directly calls https://api.aiapp.link/api/message/ with X-API-KEY header authentication
            If MCP server has BAAS_API_KEY set, it will be automatically injected into code
        """
  • Core implementation fetches Markdown template from CDN, extracts code blocks using regex, injects BAAS_API_KEY if available, constructs filename and configuration instructions based on language, and returns structured response with code and metadata.
    async def generate_direct_api_code(
        language: str = "javascript",
        framework: Optional[str] = None,
        include_examples: bool = True
    ) -> Dict[str, Any]:
        """
        Generate code that directly calls BaaS API by fetching templates from CDN
        
        Perfect for: Production deployments, custom integrations, framework-specific implementations
        Token-optimized: Fetches maintained templates from CDN instead of generating locally
        
        Args:
            language: Programming language (javascript, python, php, java, go, csharp)
            framework: Optional framework (react, vue, django, laravel, fastapi, spring, etc.)
            include_examples: Include usage examples and configuration templates
            
        Returns:
            Dictionary with code fetched from CDN, filename, and integration instructions
            Code directly calls https://api.aiapp.link/api/message/ with X-API-KEY header authentication
            If MCP server has BAAS_API_KEY set, it will be automatically injected into code
        """
        try:
            language = language.lower()
            framework = framework.lower() if framework else None
            
            # CDN base URL for templates
            base_url = "https://cdn.mbaas.kr/templates/sms-mms"
            
            # Construct template path
            template_path = language
            if framework:
                template_path += f"/{framework}"
            else:
                template_path += "/vanilla"
            
            template_url = f"{base_url}/{template_path}.md"
            
            # Fetch template from CDN
            try:
                response = await client.get(template_url)
                if response.status_code == 200:
                    template_content = response.text
                    
                    # Extract code from markdown (assuming code is in ```language blocks)
                    import re
                    code_blocks = re.findall(f'```{language}(.*?)```', template_content, re.DOTALL)
                    
                    if code_blocks:
                        code = code_blocks[0].strip()
                    else:
                        # Fallback: use entire content if no code blocks found
                        code = template_content
                        
                else:
                    return {
                        "success": False,
                        "error": f"CDN에서 템플릿을 가져올 수 없습니다 (HTTP {response.status_code})",
                        "cdn_url": template_url,
                        "error_code": "CDN_UNAVAILABLE"
                    }
                        
            except Exception as cdn_error:
                return {
                    "success": False,
                    "error": f"CDN 연결 오류: {str(cdn_error)}",
                    "cdn_url": template_url,
                    "error_code": "CDN_CONNECTION_ERROR"
                }
            
            # Apply environment variable injection if API key is available
            if BAAS_API_KEY:
                code = code.replace('your-api-key', BAAS_API_KEY)
                code = code.replace('process.env.BAAS_API_KEY', f"'{BAAS_API_KEY}'")
                code = code.replace('os.getenv(\'BAAS_API_KEY\')', f"'{BAAS_API_KEY}'")
                code = code.replace('$_ENV[\'BAAS_API_KEY\']', f"'{BAAS_API_KEY}'")
            
            # File naming
            extensions = {
                "javascript": "js",
                "js": "js", 
                "python": "py",
                "py": "py",
                "php": "php"
            }
            
            extension = extensions.get(language, language)
            filename = f"baas-sms-service.{extension}"
            
            # Configuration instructions
            config_instructions = {
                "javascript": {
                    "env_vars": ["BAAS_API_KEY"],
                    "install": "npm install (dependencies included in template)",
                    "usage": "Import and instantiate BaaSMessageService class",
                    "api_key_injected": bool(BAAS_API_KEY)
                },
                "python": {
                    "env_vars": ["BAAS_API_KEY"],
                    "install": "pip install requests",
                    "usage": "Import and instantiate BaaSMessageService class",
                    "api_key_injected": bool(BAAS_API_KEY)
                },
                "php": {
                    "env_vars": ["BAAS_API_KEY"],
                    "install": "cURL extension required (usually included)",
                    "usage": "Include file and instantiate BaaSMessageService class",
                    "api_key_injected": bool(BAAS_API_KEY)
                }
            }
            
            return {
                "success": True,
                "language": language,
                "framework": framework,
                "code": code,
                "filename": filename,
                "description": f"{language.title()} BaaS SMS service for direct /api/message/ API calls",
                "source": "CDN template",
                "template_url": template_url,
                "configuration": config_instructions.get(language, {}),
                "api_endpoint": "https://api.aiapp.link/api/message/",
                "message": f"{language.title()} 코드가 성공적으로 생성되었습니다 (CDN 소스, API Key {'주입됨' if BAAS_API_KEY else '미설정'})"
            }
            
        except Exception as e:
            return {
                "success": False,
                "error": f"코드 생성에 실패했습니다: {str(e)}",
                "error_code": "CODE_GENERATION_ERROR"
            }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behaviors: the tool fetches maintained templates from a CDN (not generating locally), returns a dictionary with code, filename, and instructions, and automatically injects BAAS_API_KEY if set. However, it lacks details on error handling, rate limits, or authentication requirements beyond the API key mention.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and front-loaded with the core purpose, followed by usage guidelines, token optimization note, parameter details, and return value explanation. It's appropriately sized, though the 'Returns' section could be slightly more concise by integrating details into fewer sentences.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (3 parameters, no annotations, but has an output schema), the description is largely complete. It covers purpose, usage, parameters, and return behavior. The output schema exists, so the description needn't detail return values extensively, but it still provides useful context on code injection and authentication. Minor gaps include lack of error handling or prerequisite information.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 0%, so the description must fully compensate. It does so by clearly explaining all three parameters: 'language' (programming language options), 'framework' (optional framework examples), and 'include_examples' (includes usage examples and configuration templates). This adds significant meaning beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Generate code that directly calls BaaS API by fetching templates from CDN.' It specifies the verb ('Generate'), resource ('code'), and mechanism ('fetching templates from CDN'), distinguishing it from siblings like 'create_message_service_template' (which likely creates templates) and 'get_code_template_url' (which retrieves URLs).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly provides usage guidance: 'Perfect for: Production deployments, custom integrations, framework-specific implementations.' It also contrasts with alternatives by noting token optimization via CDN fetching instead of local generation, helping differentiate from potential sibling tools that might generate code locally.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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/jjunmomo/BaaS-MCP'

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