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");
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states what the tool does, not how it behaves. It doesn't disclose whether this is a read-only operation, what format the documentation returns, potential rate limits, error conditions, or authentication requirements. The description is functional but lacks behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence efficiently conveys the core purpose with zero wasted words. Front-loaded with the main action and key parameters, making it immediately understandable without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 4-parameter tool with no annotations and no output schema, the description is minimally adequate but incomplete. It explains what the tool does but lacks information about return format, error handling, or behavioral characteristics that would help an agent use it effectively in context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all parameters. The description adds minimal value beyond the schema by mentioning the three required parameters, but doesn't provide additional semantic context about parameter relationships or usage nuances. Baseline 3 is appropriate when schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Get detailed documentation') and target resource ('OpenTofu data source'), with precise identification parameters (provider namespace, provider name, data source name). It distinguishes from siblings like 'get-resource-docs' by focusing on data sources rather than resources or other registry components.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context by specifying the required parameters, but doesn't explicitly state when to use this tool versus alternatives like 'search-opentofu-registry' or 'get-provider-details'. It provides the 'what' but not the 'when' relative to sibling tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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