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

Implementation Reference

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

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