get-datasource-docs
Retrieve detailed documentation for OpenTofu data sources by specifying provider namespace, name, and data source. Simplifies access to essential information for efficient infrastructure management.
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 |
|---|---|---|---|
| dataSource | Yes | Data source name WITHOUT provider prefix (e.g., 'ami', 'vpc') | |
| name | Yes | Provider name WITHOUT 'terraform-provider-' prefix (e.g., 'aws', 'kubernetes') | |
| namespace | Yes | Provider namespace (e.g., 'hashicorp', 'opentofu') | |
| version | No | Provider version (e.g., 'v4.0.0'). If not specified, latest version will be used |
Implementation Reference
- src/servers/registry/index.ts:127-140 (registration)Registration of the MCP tool 'get-datasource-docs' with description, schema, and handler function that delegates to RegistryClient.server.tool( "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/servers/registry/index.ts:30-36 (schema)Zod input schema defining 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/registry/index.ts:122-124 (handler)Handler method in RegistryClient that implements fetching data source documentation by calling the shared fetchMarkdownDoc helper.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)Core helper function that resolves provider version, constructs the API path for documentation, and fetches the markdown content from the OpenTofu registry API.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"); } }
- Helper function to format the tool response as MCP text content.export function textResult(result: string): { content: { type: "text"; text: string; }[]; } { return { content: [ { type: "text", text: result, }, ], }; }