Skip to main content
Glama
opentofu

OpenTofu MCP Server

Official
by opentofu

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
NameRequiredDescriptionDefault
dataSourceYesData source name WITHOUT provider prefix (e.g., 'ami', 'vpc')
nameYesProvider name WITHOUT 'terraform-provider-' prefix (e.g., 'aws', 'kubernetes')
namespaceYesProvider namespace (e.g., 'hashicorp', 'opentofu')
versionNoProvider version (e.g., 'v4.0.0'). If not specified, latest version will be used

Implementation Reference

  • 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}`); } }, );
  • 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"), };
  • 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); }
  • 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, }, ], }; }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/opentofu/opentofu-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server