fetchUrlContent
Retrieve and parse content from web URLs to organize information in knowledge bases. This tool extracts text from specified URLs for content management and search purposes.
Instructions
Fetches the content of a URL. Particularly useful for fetching parsed text file URLs.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | ||
| apiKey | No | ||
| tenantId | No |
Implementation Reference
- src/index.ts:739-764 (handler)Handler function that fetches the content from the given URL using wretch HTTP client, supports optional API key authentication and tenant ID header.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-509 (schema)Zod schema defining input parameters: url (required), optional apiKey and tenantId.export const FetchUrlContentSchema = z.object({ url: z.string().url(), // Authentication might be needed for some SourceSync URLs apiKey: apiKeySchema, tenantId: tenantIdSchema, }) export type FetchUrlContentParams = z.infer<typeof FetchUrlContentSchema>
- src/index.ts:735-765 (registration)Registers the fetchUrlContent tool on the MCP server with description, input schema, 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}`) } }) }, )