Skip to main content

url_parse

Parse a URL string into its individual components. Returns the scheme, host, optional port, path, raw query string, fragment, and optional credentials from the authority component.

Parameters​

ParameterTypeRequiredDescription
urlstringYesThe URL string to parse (e.g. https://example.com/path?key=value#section).

Response​

FieldTypeDescription
schemestringURL scheme (e.g. "https", "http", "ftp").
hoststringHostname or IP address (e.g. "example.com").
portnumber or nullPort number if explicitly present in the URL; null if absent.
pathstringPath component (e.g. "/path/to/resource"); always present, "/" if absent.
querystring or nullRaw query string without the leading ? (e.g. "key=value&other=x"); null if absent.
fragmentstring or nullFragment identifier without the leading # (e.g. "section"); null if absent.
usernamestring or nullUsername from the authority component; null if absent.
passwordstring or nullPassword from the authority component; null if absent.

Examples​

Input:

{
"url": "https://user:pass@api.example.com:8080/v1/users?page=2&limit=10#results"
}

Result:

{
"scheme": "https",
"host": "api.example.com",
"port": 8080,
"path": "/v1/users",
"query": "page=2&limit=10",
"fragment": "results",
"username": "user",
"password": "pass"
}

Input (minimal URL):

{
"url": "https://example.com"
}

Result:

{
"scheme": "https",
"host": "example.com",
"port": null,
"path": "/",
"query": null,
"fragment": null,
"username": null,
"password": null
}

Errors​

Each failure carries a precise code in the response. Argument-schema and server errors are JSON-RPC protocol errors; a rejected value is returned as a tool result with isError: true (so the agent can read the code and self-correct).

CodeWhenDelivered as
invalid_argumentsAn argument is missing or the wrong type.protocol error (invalid_params)
invalid_urlThe input string is not a valid URL, or has no host (e.g. bare data: or mailto: URIs).tool error (isError)
internal_errorAn unexpected server error.protocol error (internal_error)

Notes​

  • The query field is the raw query string. Individual key-value pairs are not split — use string manipulation or url_build to reconstruct query strings.
  • port is only set when the port is explicitly present in the URL. Standard ports (443 for HTTPS, 80 for HTTP) are not returned unless written literally in the input.
  • Credentials (username, password) are extracted from the authority component (user:pass@host). They are not percent-decoded.