configure_rest_client
Set base URL, authentication, and optional Swagger documentation for REST API calls. Supports token or login-based authentication with configurable timeout and retries.
Instructions
Configure the REST client with base URL, authentication, and optional Swagger documentation URL
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| baseUrl | Yes | Base URL for the REST API | |
| swaggerUrl | No | URL to Swagger/OpenAPI documentation (optional) | |
| auth | Yes | ||
| timeout | No | Request timeout in milliseconds (default: 30000) | |
| retries | No | Number of retries for failed requests (default: 3) |
Implementation Reference
- src/index.ts:265-290 (handler)The configureRestClient private method that executes the tool logic. It validates args with ConfigSchema, creates a new RestClient instance, and initializes it (including authentication and optional Swagger parsing). Returns a success message or throws on failure.
private async configureRestClient(args: any) { try { const config = ConfigSchema.parse(args); this.restClient = new RestClient(config); await this.restClient.initialize(); return { content: [ { type: "text", text: `REST client configured successfully for ${config.baseUrl}${ config.swaggerUrl ? ` with Swagger documentation from ${config.swaggerUrl}` : "" }`, }, ], }; } catch (error) { throw new Error( `Configuration failed: ${ error instanceof Error ? error.message : "Unknown error" }` ); } } - src/types.ts:18-24 (schema)The ConfigSchema Zod schema used to validate the input arguments passed to configure_rest_client. Defines baseUrl (url), swaggerUrl (optional url), auth (AuthConfigSchema), timeout (default 30000), and retries (default 3).
export const ConfigSchema = z.object({ baseUrl: z.string().url(), swaggerUrl: z.string().url().optional(), auth: AuthConfigSchema, timeout: z.number().default(30000), retries: z.number().default(3), }); - src/types.ts:4-16 (schema)The AuthConfigSchema Zod discriminated union used within ConfigSchema. Supports two auth types: 'token' (with token field) and 'login' (with username, password, loginEndpoint, and optional tokenField defaulting to 'access_token').
export const AuthConfigSchema = z.discriminatedUnion("type", [ z.object({ type: z.literal("token"), token: z.string(), }), z.object({ type: z.literal("login"), username: z.string(), password: z.string(), loginEndpoint: z.string(), tokenField: z.string().default("access_token"), }), ]); - src/index.ts:52-126 (registration)Registration of the configure_rest_client tool in the ListToolsRequestSchema handler. Defines name, description, and inputSchema (with baseUrl required, swaggerUrl optional, auth required as oneOf token/login, timeout, retries).
{ name: "configure_rest_client", description: "Configure the REST client with base URL, authentication, and optional Swagger documentation URL", inputSchema: { type: "object", properties: { baseUrl: { type: "string", description: "Base URL for the REST API", }, swaggerUrl: { type: "string", description: "URL to Swagger/OpenAPI documentation (optional)", }, auth: { type: "object", oneOf: [ { type: "object", properties: { type: { type: "string", enum: ["token"] }, token: { type: "string", description: "Authentication token", }, }, required: ["type", "token"], }, { type: "object", properties: { type: { type: "string", enum: ["login"] }, username: { type: "string", description: "Username for login", }, password: { type: "string", description: "Password for login", }, loginEndpoint: { type: "string", description: "Login endpoint path", }, tokenField: { type: "string", description: "Field name for access token in response (default: access_token)", }, }, required: [ "type", "username", "password", "loginEndpoint", ], }, ], }, timeout: { type: "number", description: "Request timeout in milliseconds (default: 30000)", }, retries: { type: "number", description: "Number of retries for failed requests (default: 3)", }, }, required: ["baseUrl", "auth"], }, }, - src/index.ts:225-226 (registration)Dispatch in the CallToolRequestSchema handler that routes the 'configure_rest_client' tool name to the configureRestClient method.
case "configure_rest_client": return await this.configureRestClient(args);