Skip to main content

url_build

Construct a well-formed URL string from individual components. Useful when assembling a URL from values that come from separate sources such as configuration, templates, or user input.

Parameters​

ParameterTypeRequiredDescription
schemestringYesURL scheme (e.g. "https", "http", "ftp").
hoststringYesHostname or IP address (e.g. "example.com", "192.168.1.1").
portnumberNoPort number to include in the URL. Omit to use the scheme default.
pathstringNoURL path (e.g. "/path/to/resource"). Defaults to "/" when omitted.
querystringNoRaw query string without the leading ? (e.g. "key=value&other=x").
fragmentstringNoFragment identifier without the leading # (e.g. "section").
usernamestringNoUsername for the authority component.
passwordstringNoPassword for the authority component. Requires username to be set.

Response​

FieldTypeDescription
urlstringThe fully constructed URL string.

Examples​

Input (full URL):

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

Result:

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

Input (minimal):

{
"scheme": "https",
"host": "example.com"
}

Result:

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

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 components do not form a valid URL — e.g. a malformed or unsupported scheme or host, a port or credentials that cannot be set on the URL, or password provided without username.tool error (isError)
internal_errorAn unexpected server error.protocol error (internal_error)

Notes​

  • The query parameter is inserted verbatim — values are not percent-encoded automatically. Use url_encode first if individual parameter values may contain special characters.
  • Providing password without username returns an invalid_url tool error.