fetchUrlContent
Retrieves and parses content from a specified URL to extract text data, enabling integration with AI models for knowledge management and analysis.
Instructions
Fetches the content of a URL. Particularly useful for fetching parsed text file URLs.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apiKey | No | ||
| tenantId | No | ||
| url | Yes |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"apiKey": {
"type": "string"
},
"tenantId": {
"type": "string"
},
"url": {
"format": "uri",
"type": "string"
}
},
"required": [
"url"
],
"type": "object"
}
Implementation Reference
- src/index.ts:739-764 (handler)The core handler function for the fetchUrlContent tool. It extracts url, optional apiKey, and tenantId from params, creates a wretch HTTP client, adds authentication headers if provided, fetches the text content from the URL, and returns it wrapped in safeApiCall for error handling.async (params: FetchUrlContentParams) => { return safeApiCall(async () => { const { url, apiKey, tenantId } = params try { // Create a wretch client with authentication if provided let client = wretch(url) if (apiKey) { client = client.auth(`Bearer ${apiKey}`) } if (tenantId) { client = client.headers({ 'X-Tenant-ID': tenantId, }) } // Fetch the content from the URL const content = await client.get().text() return { content } } catch (error: any) { throw new Error(`Error fetching URL content: ${error.message}`) } }) },
- src/schemas.ts:502-507 (schema)Zod schema defining the input parameters for the fetchUrlContent tool: required 'url' (validated as URL string), optional 'apiKey' and 'tenantId' (referencing predefined schemas).export const FetchUrlContentSchema = z.object({ url: z.string().url(), // Authentication might be needed for some SourceSync URLs apiKey: apiKeySchema, tenantId: tenantIdSchema, })
- src/index.ts:735-765 (registration)Registers the fetchUrlContent tool on the MCP server using server.tool(), providing the name, description, input schema shape, and inline handler function.server.tool( 'fetchUrlContent', 'Fetches the content of a URL. Particularly useful for fetching parsed text file URLs.', FetchUrlContentSchema.shape, async (params: FetchUrlContentParams) => { return safeApiCall(async () => { const { url, apiKey, tenantId } = params try { // Create a wretch client with authentication if provided let client = wretch(url) if (apiKey) { client = client.auth(`Bearer ${apiKey}`) } if (tenantId) { client = client.headers({ 'X-Tenant-ID': tenantId, }) } // Fetch the content from the URL const content = await client.get().text() return { content } } catch (error: any) { throw new Error(`Error fetching URL content: ${error.message}`) } }) }, )