get-datasource-docs
Retrieve detailed documentation for OpenTofu data sources by specifying provider namespace, name, and data source identifier to understand configuration options and usage.
Instructions
Get detailed documentation for a specific OpenTofu data source by provider namespace, provider name, and data source name.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| namespace | Yes | Provider namespace (e.g., 'hashicorp', 'opentofu') | |
| name | Yes | Provider name WITHOUT 'terraform-provider-' prefix (e.g., 'aws', 'kubernetes') | |
| dataSource | Yes | Data source name WITHOUT provider prefix (e.g., 'ami', 'vpc') | |
| version | No | Provider version (e.g., 'v4.0.0'). If not specified, latest version will be used |
Implementation Reference
- src/servers/registry/index.ts:132-140 (handler)MCP tool handler for 'get-datasource-docs': validates params, calls RegistryClient.getDataSourceDocs, wraps response in textResult or error message.try { const dataSourceDocs = await client.getDataSourceDocs(params.namespace, params.name, params.dataSource, params.version); return textResult(dataSourceDocs); } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : "Data source documentation not found"; return textResult(`Failed to get documentation for data source ${params.name}_${params.dataSource}: ${errorMessage}`); } }, );
- src/servers/registry/index.ts:30-35 (schema)Zod schema defining input parameters for the get-datasource-docs tool.const dataSourceDocsSchema = { namespace: z.string().min(1).describe("Provider namespace (e.g., 'hashicorp', 'opentofu')"), name: z.string().min(1).describe("Provider name WITHOUT 'terraform-provider-' prefix (e.g., 'aws', 'kubernetes')"), dataSource: z.string().min(1).describe("Data source name WITHOUT provider prefix (e.g., 'ami', 'vpc')"), version: z.string().optional().describe("Provider version (e.g., 'v4.0.0'). If not specified, latest version will be used"), };
- src/servers/registry/index.ts:128-141 (registration)Registers the 'get-datasource-docs' tool on the MCP server with name, description, schema, and handler function."get-datasource-docs", "Get detailed documentation for a specific OpenTofu data source by provider namespace, provider name, and data source name.", dataSourceDocsSchema, async (params) => { try { const dataSourceDocs = await client.getDataSourceDocs(params.namespace, params.name, params.dataSource, params.version); return textResult(dataSourceDocs); } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : "Data source documentation not found"; return textResult(`Failed to get documentation for data source ${params.name}_${params.dataSource}: ${errorMessage}`); } }, ); }
- src/registry/index.ts:122-124 (helper)RegistryClient method implementing the core logic: fetches data source documentation Markdown from OpenTofu Registry API.async getDataSourceDocs(namespace: string, name: string, target: string, version?: string): Promise<string> { return await this.fetchMarkdownDoc("datasource", namespace, name, target, version); }
- src/registry/index.ts:126-139 (helper)Private helper in RegistryClient to fetch Markdown documentation for resources or data sources, handling version resolution and API call.private async fetchMarkdownDoc(docType: DocType, namespace: string, name: string, docName: string, version?: string): Promise<string> { let targetVersion = version; if (!targetVersion) { targetVersion = await this.getLatestProviderVersion(namespace, name); if (!targetVersion) { throw new Error(`Could not determine latest version for provider ${namespace}/${name}`); } } const path = `/registry/docs/providers/${namespace}/${name}/${targetVersion}/${docType}s/${docName}.md`; console.error(`Fetching ${path}`); return this.fetchFromApi<string>(path, {}, "text"); } }