HTTP Protocol Plugin
Relevant source files
The following files were used as context for generating this wiki page:The HTTP Protocol Plugin is a core component of the Universal Tool Calling Protocol (UTCP) that enables interaction with tools exposed over HTTP-based protocols. It provides a versatile implementation for communicating with standard REST APIs, Server-Sent Events (SSE) endpoints, and services that offer streaming HTTP responses. This plugin is essential for integrating UTCP with the vast majority of modern web services and APIs.
The plugin is designed to be highly configurable, supporting various authentication methods, custom headers, and dynamic URL parameters. It also includes a powerful OpenAPI integration feature, which can automatically generate UTCP tools from an OpenAPI specification, significantly reducing the effort required to integrate existing APIs. The plugin registers itself via the utcp.plugins entry point in its pyproject.toml.
Sources: plugins/communication_protocols/http/README.md, README.md, plugins/communication_protocols/http/pyproject.toml:29-30
Features
The HTTP plugin provides a comprehensive set of features for web-based tool interaction.
| Feature | Description |
|---|---|
| HTTP/REST APIs | Full support for GET, POST, PUT, DELETE, and PATCH methods. |
| Authentication | Built-in support for API Key, Basic Auth, and OAuth2. |
| Server-Sent Events (SSE) | Native handling of real-time event streams from SSE endpoints. |
| Streaming HTTP | Efficiently handles large responses via chunked transfer for protocols like ndjson. |
| OpenAPI Integration | Automatically generates UTCP tools from OpenAPI 2.0/3.0 specifications. |
| Dynamic URLs | Supports URL path parameter substitution using the {parameter} syntax. |
| Custom Headers | Allows for both static and dynamic headers in requests. |
Sources: plugins/communication_protocols/http/README.md, README.md
Architecture and Components
The plugin's architecture is centered around communication protocol classes that implement the CommunicationProtocol interface and Pydantic models for configuration.
Core Classes
StreamableHttpCommunicationProtocol
This class implements the logic for handling HTTP-based communication, with a specific focus on streaming responses. It manages the entire lifecycle of a tool call, from building the request with proper authentication and parameters to processing the response stream.
Key responsibilities include:
- Registering and deregistering tool manuals from remote HTTP endpoints.
- Executing streaming tool calls via
call_tool_streaming. - Handling authentication, including OAuth2 token acquisition and refresh.
- Processing different streaming content types like
ndjson,octet-stream, and standardjson. - Substituting path parameters in URLs.
Sources: plugins/communication_protocols/http/src/utcp_http/streamable_http_communication_protocol.py:23-27
StreamableHttpCallTemplate
This Pydantic model defines the configuration for a tool that communicates over a streaming HTTP connection. It inherits from the base CallTemplate and adds fields specific to HTTP, such as http_method, headers, auth, chunk_size, and timeout. This model is used to configure how the StreamableHttpCommunicationProtocol interacts with an endpoint.
Sources: plugins/communication_protocols/http/src/utcp_http/streamable_http_communication_protocol.py:14
Component Diagram
The following diagram illustrates the key classes within the utcp-http plugin and their relationship to the core UTCP interfaces.
Configuration
The HTTP plugin supports multiple call_template_type values, each with its own configuration options.
streamable_http Call Template
This template is for endpoints that stream data, such as chunked responses or ndjson.
| Field | Type | Default | Description |
|---|---|---|---|
call_template_type | string | "streamable_http" | Required. Identifies the protocol type. |
url | string | - | Required. The endpoint URL, with optional {path_param} placeholders. |
http_method | string | "GET" | The HTTP method to use for the request. |
content_type | string | "application/octet-stream" | The Content-Type header for the request body. |
chunk_size | integer | 4096 | The size of chunks to read from the streaming response. |
timeout | integer | 60000 (ms) | The total timeout for the request in milliseconds. |
auth | object | null | Authentication configuration object (See Authentication). |
headers | object | {} | Static headers to include in the request. |
body_field | string | "data" | The name of the tool argument that contains the request body. |
header_fields | array | [] | A list of tool argument names to be placed in the request headers. |
Sources: README.md, plugins/communication_protocols/http/src/utcp_http/streamable_http_communication_protocol.py:237-240,256
http Call Template
This is for standard, non-streaming REST API calls.
{
"name": "my_rest_api",
"call_template_type": "http",
"url": "https://api.example.com/users/{user_id}",
"http_method": "POST",
"content_type": "application/json",
"auth": {
"auth_type": "api_key",
"api_key": "Bearer $API_KEY",
"var_name": "Authorization",
"location": "header"
},
"headers": {
"X-Custom-Header": "value"
},
"body_field": "body",
"header_fields": ["user_id"]
}
Sources: README.md
sse Call Template
This template is specifically for consuming Server-Sent Events streams.
{
"name": "my_sse_stream",
"call_template_type": "sse",
"url": "https://api.example.com/events",
"event_type": "message",
"reconnect": true,
"retry_timeout": 30000
}
Sources: README.md
Execution Flow
Manual Registration
The register_manual method discovers tools by making an HTTP request to the url defined in the call template. It expects a JSON response that conforms to the UtcpManual schema.
This diagram shows the sequence for registering a manual from an HTTP endpoint.
Tool Calling (Streaming)
The call_tool_streaming method executes a tool call and yields response chunks as they arrive. It constructs the request URL, headers, and body from the tool arguments and call template configuration.
This diagram shows the sequence for a streaming tool call.
The _process_http_stream method inspects the Content-Type header to determine how to parse the incoming stream, supporting application/x-ndjson, application/json, application/octet-stream, and others.
Sources: plugins/communication_protocols/http/src/utcp_http/streamable_http_communication_protocol.py:287-321
Authentication
The plugin handles authentication via the _apply_auth and _handle_oauth2 methods.
This flowchart shows the logic for applying authentication to a request.
- API Key: The key can be placed in a header, query parameter, or cookie, as defined in the
ApiKeyAuthmodel. - Basic Auth: Standard HTTP Basic authentication using a username and password.
- OAuth2: Implements the Client Credentials flow. It first attempts to get a token by sending credentials in the request body, and if that fails, it retries using a Basic Auth header, which covers common OAuth2 server implementations. Tokens are cached in memory.
Security Considerations
To prevent Man-in-the-Middle (MITM) attacks, the register_manual method enforces a strict security policy on endpoint URLs. A ValueError is raised if the URL does not use https:// or is not a localhost address (http://localhost or http://127.0.0.1). This ensures that tool discovery occurs over a secure, encrypted channel in production environments.
Sources: plugins/communication_protocols/http/src/utcp_http/streamable_http_communication_protocol.py:88-94
OpenAPI Integration
The HTTP plugin is a key enabler of UTCP's OpenAPI ingestion feature. When a manual_call_template of type http points to an OpenAPI specification URL, the UTCP client can automatically parse the specification and generate a UtcpManual with corresponding tools. This allows for zero-infrastructure integration with any existing REST API that has an OpenAPI definition.
Sources: README.md, plugins/communication_protocols/http/README.md