Skip to main content
Glama
devhub

DevHub CMS MCP

Official
by devhub

site_from_url

Extract DevHub site ID and details from a URL to enable content management operations in the CMS system.

Instructions

Get the DevHub site ID from a URL.

Can prompt the user for the URL instead of passing a site_id.

Returns details about the Site matches the URL that can be used in the other tools.
- Site ID: ID of the DevHub site
- Site URL: URL of the DevHub site
- Site Location IDs: List of location IDs associated with the site

Args:
    url: URL of the DevHub site, all lowercase and ends with a slash

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes

Implementation Reference

  • The handler function for the 'site_from_url' tool. It parses the input URL, queries the DevHub API for matching sites using subdomain, domain, and base_directory, and returns formatted site details including ID, URL, and location IDs if found, or 'No site found' otherwise. Registered via @mcp.tool() decorator.
    @mcp.tool()
    def site_from_url(url: str) -> str:
        """Get the DevHub site ID from a URL.
    
        Can prompt the user for the URL instead of passing a site_id.
    
        Returns details about the Site matches the URL that can be used in the other tools.
        - Site ID: ID of the DevHub site
        - Site URL: URL of the DevHub site
        - Site Location IDs: List of location IDs associated with the site
    
        Args:
            url: URL of the DevHub site, all lowercase and ends with a slash
        """
        parsed_url = urlparse(url)
        subdomain = parsed_url.netloc.split('.', 1)[0] or 'www'
        domain = parsed_url.netloc.split('.', 1)[1]
        base_directory = parsed_url.path
        client, base_url = get_client()
        r = client.get('{}sites/'.format(base_url), params={
            'base_directory': base_directory,
            'deleted': 0,
            'domain': domain,
            'subdomain': subdomain,
        })
        content = json.loads(r.content)
        if len(content['objects']) == 0:
            return 'No site found'
        site = content['objects'][0]
        return f"""
    Site ID: {site['id']}
    Site URL: {site['formatted_url']}
    Site Location IDs: {", ".join([str(location_id) for location_id in site['location_ids']])}
    """
  • The @mcp.tool() decorator registers the site_from_url function as an MCP tool.
    @mcp.tool()
  • Helper function get_client() used by site_from_url to obtain the OAuth client and base URL for API calls.
    def get_client():
        """Get DevHub API client and base_url."""
        client = OAuth1Session(
            os.environ['DEVHUB_API_KEY'],
            client_secret=os.environ['DEVHUB_API_SECRET'])
        base_url = '{}/api/v2/'.format(os.environ['DEVHUB_BASE_URL'])
        return client, base_url
  • Docstring providing schema: input 'url: str', output str with site details.
    """Get the DevHub site ID from a URL.
    
    Can prompt the user for the URL instead of passing a site_id.
    
    Returns details about the Site matches the URL that can be used in the other tools.
    - Site ID: ID of the DevHub site
    - Site URL: URL of the DevHub site
    - Site Location IDs: List of location IDs associated with the site
    
    Args:
        url: URL of the DevHub site, all lowercase and ends with a slash
    """

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/devhub/devhub-cms-mcp'

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