Skip to main content
Glama
chatmcp

mcp-server-collector

by chatmcp

extract-mcp-servers-from-content

Extract MCP servers from content by analyzing text to identify and collect server information for integration with the mcp-server-collector system.

Instructions

Extract MCP Servers from given content

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYescontent containing mcp servers

Implementation Reference

  • Core handler function that uses OpenAI to extract MCP servers from the provided content using a JSON-structured prompt.
    async def extract_mcp_servers_from_content(content: str) -> str | None:
        client = OpenAI(
            api_key=os.getenv("OPENAI_API_KEY"),
            base_url=os.getenv("OPENAI_BASE_URL"),
        )
    
        user_content = extract_mcp_servers_prompt.format(content=content)
    
        logger.info(f"Extract prompt: {user_content}")
    
        chat_completion = client.chat.completions.create(
            messages=[
                {
                    "role": "user",
                    "content": user_content,
                }
            ],
            model=os.getenv("OPENAI_MODEL"),
            response_format={"type": "json_object"},
        )
    
        return chat_completion.choices[0].message.content
  • Registers the tool in the MCP server's list_tools() method, defining name, description, and input schema.
    types.Tool(
        name="extract-mcp-servers-from-content",
        description="Extract MCP Servers from given content",
        inputSchema={
            "type": "object",
            "properties": {
                "content": {
                    "type": "string",
                    "description": "content containing mcp servers",
                },
            },
            "required": ["content"],
        },
    ),
  • Input schema defining the expected 'content' parameter for the tool.
    inputSchema={
        "type": "object",
        "properties": {
            "content": {
                "type": "string",
                "description": "content containing mcp servers",
            },
        },
        "required": ["content"],
    },
  • MCP server call_tool handler that dispatches to extract logic for this tool and formats the response.
    @server.call_tool()
    async def handle_call_tool(
        name: str, arguments: dict | None
    ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
        if not arguments:
            raise ValueError("Missing arguments")
    
        content = None
        
        match name:
            case "extract-mcp-servers-from-url":
                url = arguments.get("url")
                if not url:
                    raise ValueError("Missing url")
    
                content = await call_fetch_tool(url)
                
            case "extract-mcp-servers-from-content":
                content = arguments.get("content")
                
            case "submit-mcp-server":
                url = arguments.get("url")
                avatar_url = arguments.get("avatar_url") or ""
                result = await submit_mcp_server(url, avatar_url)
                content = json.dumps(result)
    
                return [
                    types.TextContent(
                        type="text",
                        text=content,
                    )
                ]
            case _:
                raise ValueError(f"Unknown tool: {name}")
    
        if not content:
            raise ValueError("Missing content")
    
        logger.info(f"Fetched content from {url}: {content}")
    
        mcp_servers = await extract_mcp_servers_from_content(content)
        if not mcp_servers:
            raise ValueError("Extracted no MCP Servers")
    
        logger.info(f"Extracted MCP Servers from {url}: {mcp_servers}")
    
        return [
            types.TextContent(
                type="text",
                text=mcp_servers,
            )
        ]   
  • Prompt template used in the extraction handler to guide the LLM in parsing MCP server details from content.
    extract_mcp_servers_prompt = """Please extract all MCP Servers from the following content and return a JSON array. Each item should contain:
    - name: extracted from the repository name in the URL
    - title: a human readable title
    - description: a brief description of the server
    - url: the full GitHub repository URL
    - author_name: extracted from the GitHub username in the URL
    
    Example response format:
    [
        {{
            "name": "mcp-server-example",
            "title": "MCP Server Example",
            "description": "A sample MCP server implementation",
            "url": "https://github.com/username/mcp-server-example",
            "author_name": "username"
        }}
    ]
    
    Content to analyze:
    {content}
    """

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/chatmcp/mcp-server-collector'

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