Skip to main content
Glama
dahuangbaojian

Phone Carrier Detector MCP Server

detect_carrier

Identify Chinese mobile phone carriers and their geographic locations by analyzing phone numbers. This tool determines whether a number belongs to China Mobile, China Unicom, China Telecom, or other providers, and provides province and city information.

Instructions

Detect carrier and location for a single phone number

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
phone_numberYesPhone number to detect (11 digits)

Implementation Reference

  • The core handler function for the 'detect_carrier' tool. Validates the 11-digit Chinese phone number format using regex, extracts the 7-digit prefix, and queries the PHONE_DATABASE for carrier and location info.
    def detect_carrier(phone_number: str) -> Dict[str, Any]:
        """检测手机号运营商和归属地"""
        # 验证手机号格式
        if not re.match(r"^1[3-9]\d{9}$", phone_number):
            return {
                "success": False,
                "error": "Invalid phone number format. Must be 11 digits starting with 1.",
            }
    
        # 提取前缀(前7位)
        prefix = phone_number[:7]
    
        # 查找数据库
        if prefix in PHONE_DATABASE:
            info = PHONE_DATABASE[prefix]
            return {
                "success": True,
                "phone_number": phone_number,
                "carrier": info["carrier"],
                "carrier_cn": info["carrier_cn"],
                "province": info["province"],
                "city": info["city"],
                "prefix": prefix,
            }
        else:
            return {
                "success": False,
                "error": f"Phone number prefix {prefix} not found in database",
            }
  • The JSON schema definition for the 'detect_carrier' tool, including input schema requiring a 'phone_number' string.
    {
        "name": "detect_carrier",
        "description": "Detect carrier and location for a single phone number",
        "inputSchema": {
            "type": "object",
            "properties": {
                "phone_number": {
                    "type": "string",
                    "description": "Phone number to detect (11 digits)",
                }
            },
            "required": ["phone_number"],
        },
    },
  • mcp_server.py:143-168 (registration)
    Registration and dispatch logic in call_tool method: checks if tool name is 'detect_carrier', validates arguments, calls the handler, and formats the JSON-RPC response.
    if name == "detect_carrier":
        phone_number = arguments.get("phone_number")
        if not phone_number:
            return {
                "jsonrpc": "2.0",
                "id": self.request_id,
                "error": {
                    "code": -32602,
                    "message": "Missing required parameter: phone_number",
                },
            }
        result = detect_carrier(phone_number)
        return {
            "jsonrpc": "2.0",
            "id": self.request_id,
            "result": {
                "content": [
                    {
                        "type": "text",
                        "text": json.dumps(
                            result, ensure_ascii=False, indent=2
                        ),
                    }
                ]
            },
        }
  • Helper function to load the phone carrier database from JSON file, used by the global PHONE_DATABASE variable essential for carrier detection.
    def load_phone_database():
        """加载手机号数据库"""
        try:
            with open("data/phone_database.json", "r", encoding="utf-8") as f:
                return json.load(f)
        except FileNotFoundError:
            print("警告: phone_database.json 文件不存在,使用默认数据库")
            return {}
  • Global PHONE_DATABASE initialized by load_phone_database(), providing the lookup data for detect_carrier.
    PHONE_DATABASE = load_phone_database()
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool detects carrier and location, but doesn't cover aspects like rate limits, authentication needs, error handling, or what the output looks like (e.g., format, possible values). For a tool with no annotation coverage, this is a significant gap in transparency.

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

Conciseness5/5

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

The description is a single, clear sentence that efficiently conveys the tool's purpose without unnecessary words. It's front-loaded with the core functionality and appropriately sized for a simple tool, earning a top score for conciseness.

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

Completeness2/5

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

Given the lack of annotations and output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., carrier name, location details, error responses) or behavioral traits like performance or limitations. For a detection tool with no structured output, the description should provide more context to be fully helpful.

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

Parameters3/5

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

The input schema has 100% description coverage, with the parameter 'phone_number' documented as 'Phone number to detect (11 digits).' The description doesn't add any additional meaning beyond this, such as format examples or validation rules. Given the high schema coverage, the baseline score of 3 is appropriate.

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

Purpose4/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: 'Detect carrier and location for a single phone number.' It specifies the verb ('detect'), resource ('carrier and location'), and scope ('single phone number'), making it easy to understand what the tool does. However, it doesn't explicitly differentiate from its sibling 'batch_detect_carriers' beyond implying single vs. batch processing.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus its sibling 'batch_detect_carriers.' It mentions 'single phone number,' which hints at usage for individual queries, but lacks explicit alternatives, prerequisites, or exclusions. This leaves the agent without clear decision-making criteria.

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

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/dahuangbaojian/sms-mcp-server'

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