Skip to main content
Glama

python_get_documentation

Search Python library documentation using natural language queries to find specific functions, classes, and usage examples from consolidated sources.

Instructions

Primary Python documentation lookup tool. Use this for every Python documentation-related query.

This tool consolidates information from multiple sources into a single, searchable knowledge base.
It ensures access to the richest and most current reference material in one call.

Args:
    query: A natural language question (e.g., "How do I define a Deployment?").
    library: Python library to search documentation for.
    version: Optional Library version (e.g., "4.46.1"). Defaults to detected library version if not specified.
    top_k: Optional number of top matching documents to return. Defaults to 10.

Returns:
    A list of dictionaries, each containing document path and corresponding content.

Example Usage:
    # Search Python docs for Transformers
    python_get_documentation(query="what is a transformers mlm token", library="transformers", version="4.46.1")

Notes:
    - This tool automatically loads or builds a RAG (Retrieval-Augmented Generation) index for the
      specified version.
    - If an index is not found locally, the tool will fetch and index the documentation before responding.
    - You should call this function for any question that needs project documentation context.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesA natural language question (e.g., "How do I use transformers?").
libraryYesPython library to search documentation for.
versionNoOptional Library version (e.g., "4.46.1"). Defaults to detected library version if not specified.
top_kNoOptional number of top matching documents to return. Defaults to 10.

Implementation Reference

  • The async execute method implements the core logic of the tool: logs the query, posts to the /api/python/documentation endpoint using groundDocsClient, validates the response, parses each document result into {type: "text", text: ...}, and returns the content array. Errors are logged and rethrown.
    async execute({ query, library, version, top_k = 10 }: z.infer<typeof this.schema>) {
      try {
        console.log(`Fetching Python docs for library: "${library}", query: "${query}" with top_k=${top_k}`);
    
        const { data }: { data: { results: string[] } } = await groundDocsClient.post(
          "/api/python/documentation",
          {
            query,
            library,
            version,
            top_k
          }
        );
    
        if (!data || !data.results || !Array.isArray(data.results)) {
          console.error("Invalid response format:", data);
          throw new Error("Invalid response format");
        }
    
        return {
          content: data.results.map((doc: any) => {
            try {
              const parsed = typeof doc === "string" ? JSON.parse(doc) : doc;
              return {
                type: "text" as const,
                text: parsed.text,
              };
            } catch (parseError) {
              console.error("Error parsing document:", parseError);
              throw parseError;
            }
          }),
        };
    
      } catch (error) {
        console.error(`Error fetching Python documentation for ${library}:`, error);
        throw error;
      }
    }
  • Zod schema defining the input parameters for the tool: required query (string) and library (string), optional version (string), and top_k (number, default 10). Includes descriptions for each field.
    schema = z.object({
      query: z.string().describe("A natural language question (e.g., \"How do I use transformers?\")."),
      library: z.string().describe("Python library to search documentation for."),
      version: z.string().optional().describe("Optional Library version (e.g., \"4.46.1\"). Defaults to detected library version if not specified."),
      top_k: z.number().optional().default(10).describe("Optional number of top matching documents to return. Defaults to 10."),
    });
  • src/index.ts:20-20 (registration)
    Registers the Python documentation tool by instantiating GetPythonDocumentationTool and calling its register method on the MCP server instance. The BaseTool's register method uses the tool's name, description, schema, and execute function.
    new GetPythonDocumentationTool().register(server);
Behavior4/5

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

With no annotations provided, the description carries the full burden and adds valuable behavioral context beyond basic functionality. It discloses that the tool 'automatically loads or builds a RAG index,' fetches and indexes documentation if not found locally, and consolidates from multiple sources. This explains implementation details and performance characteristics, though it could mention potential delays or errors.

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

Conciseness3/5

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

The description is front-loaded with purpose and usage, but includes redundant parameter details that duplicate the schema. The 'Args' and 'Returns' sections could be trimmed since they're covered elsewhere. However, it's well-structured with clear sections, though some sentences like the consolidation claim could be more concise.

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

Completeness4/5

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

Given no annotations and no output schema, the description compensates well by explaining behavioral traits (RAG indexing, fetching) and providing an example. It covers the tool's scope and usage context effectively, though it could detail error handling or output format more explicitly to be fully complete for a complex lookup tool.

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 already documents all parameters thoroughly. The description repeats parameter information in the 'Args' section without adding significant meaning beyond the schema, such as examples of effective queries or library naming conventions. Baseline 3 is appropriate as the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the tool's purpose as a 'Python documentation lookup tool' that 'consolidates information from multiple sources into a single, searchable knowledge base.' It distinguishes from the sibling 'k8s_get_documentation' by specifying Python focus. However, it doesn't explicitly contrast with the sibling beyond the language difference, missing a more detailed distinction.

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

Usage Guidelines5/5

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

The description provides explicit usage guidance: 'Use this for every Python documentation-related query' and 'You should call this function for any question that needs project documentation context.' It clearly indicates when to use this tool (for Python docs) versus alternatives (implied for non-Python, e.g., k8s), though it doesn't name the sibling explicitly in exclusions.

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/GroundDocs/grounddocs'

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