packagedocs

package
v0.16.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

README

Package Documentation Tools

The packagedocs package provides MCP tools for retrieving comprehensive documentation for libraries and packages through the Context7 API.

Overview

This tool set enables AI agents and developers to access up-to-date documentation for any library or framework, making it particularly useful for:

  • Understanding API references and usage patterns
  • Getting code examples and implementation guidance
  • Finding specific documentation topics (e.g., hooks, routing, authentication)
  • Accessing documentation that may not be available in training data

Tools

1. resolve_library_id

Resolves a library name to a Context7-compatible library ID.

Purpose: Before fetching documentation, you need to resolve the library name to an exact library ID that Context7 recognises.

Parameters:

  • libraryName (required): The name of the library to search for (e.g., "react", "tensorflow", "express")

Example Usage:

{
  "name": "resolve_library_id",
  "arguments": {
    "libraryName": "react"
  }
}

Response: Returns the best matching library ID along with alternatives and selection rationale based on:

  • Name similarity (exact matches prioritised)
  • Trust score (7-10 are more authoritative)
  • Documentation coverage (number of code snippets and tokens)
  • GitHub stars and community adoption
2. get_library_docs

Fetches comprehensive documentation for a specific library using its Context7-compatible ID.

Purpose: Retrieves up-to-date documentation content optimised for AI consumption.

Parameters:

  • context7CompatibleLibraryID (required): The exact library ID from resolve_library_id (e.g., "/facebook/react", "/vercel/next.js")
  • topic (optional): Focus on specific documentation topics (e.g., "hooks", "routing", "authentication")
  • tokens (optional): Maximum tokens to retrieve (default: 10,000, max: 100,000)

Example Usage:

{
  "name": "get_library_docs",
  "arguments": {
    "context7CompatibleLibraryID": "/facebook/react",
    "topic": "hooks",
    "tokens": 15000
  }
}

Response: Returns formatted documentation with metadata including topic focus, token limits, and content length.

Workflow

The typical workflow for using these tools is:

  1. Resolve Library ID: Use resolve_library_id to find the correct library identifier
  2. Fetch Documentation: Use get_library_docs with the resolved ID to get the documentation
graph LR
    A[Library Name] --> B[resolve_library_id]
    B --> C[Library ID]
    C --> D[get_library_docs]
    D --> E[Documentation]

Features

  • Intelligent Library Matching: Finds the most relevant library based on multiple criteria
  • Topic Filtering: Focus documentation retrieval on specific areas of interest
  • Scalable Content: Adjust token limits based on your needs (1,000 - 100,000 tokens)
  • Rich Metadata: Includes trust scores, GitHub stars, and documentation coverage stats
  • Alternative Suggestions: Shows other potential matches when multiple libraries exist
  • Caching: Built-in caching reduces API calls and improves performance

Error Handling

The tools provide clear error messages for common issues:

  • Invalid library names or IDs
  • No matching libraries found
  • API communication failures
  • Token limit violations

Implementation Details

  • Client: HTTP client with 30-second timeout for Context7 API communication
  • Caching: In-memory cache with 30-minute expiry for search results
  • Validation: Library ID format validation and parameter sanitisation
  • Logging: Comprehensive logging for debugging and monitoring

Context7 Integration

These tools integrate with the Context7 API, which provides:

  • Curated documentation from official sources
  • AI-optimised content formatting
  • Real-time updates from library maintainers
  • Quality scoring and trust metrics
  • Comprehensive coverage across programming languages and frameworks

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateLibraryID

func ValidateLibraryID(libraryID string) error

ValidateLibraryID validates a Context7 library ID format

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client handles communication with the Context7 API

func NewClient

func NewClient(logger *logrus.Logger) *Client

NewClient creates a new Context7 API client

func (*Client) GetLibraryDocs

func (c *Client) GetLibraryDocs(ctx context.Context, libraryID string, params *SearchLibraryDocsParams) (string, error)

GetLibraryDocs retrieves documentation for a specific library

func (*Client) SearchLibraries

func (c *Client) SearchLibraries(ctx context.Context, query string) ([]*SearchResult, error)

SearchLibraries searches for libraries matching the given query

type GetLibraryDocsTool

type GetLibraryDocsTool struct {
	// contains filtered or unexported fields
}

GetLibraryDocsTool fetches documentation for a specific library

func (*GetLibraryDocsTool) Definition

func (t *GetLibraryDocsTool) Definition() mcp.Tool

Definition returns the tool's definition for MCP registration

func (*GetLibraryDocsTool) Execute

func (t *GetLibraryDocsTool) Execute(ctx context.Context, logger *logrus.Logger, cache *sync.Map, args map[string]interface{}) (*mcp.CallToolResult, error)

Execute executes the get_library_docs tool

type ResolveLibraryIDTool

type ResolveLibraryIDTool struct {
	// contains filtered or unexported fields
}

ResolveLibraryIDTool resolves a library name to a Context7-compatible library ID

func (*ResolveLibraryIDTool) Definition

func (t *ResolveLibraryIDTool) Definition() mcp.Tool

Definition returns the tool's definition for MCP registration

func (*ResolveLibraryIDTool) Execute

func (t *ResolveLibraryIDTool) Execute(ctx context.Context, logger *logrus.Logger, cache *sync.Map, args map[string]interface{}) (*mcp.CallToolResult, error)

Execute executes the resolve_library_id tool

type SearchLibrariesResponse

type SearchLibrariesResponse struct {
	Results []*SearchResult `json:"results"`
}

SearchLibrariesResponse represents the response from the search API

type SearchLibraryDocsParams

type SearchLibraryDocsParams struct {
	Topic   string   `json:"topic,omitempty"`
	Tokens  int      `json:"tokens,omitempty"`
	Folders []string `json:"folders,omitempty"`
}

SearchLibraryDocsParams represents parameters for searching library documentation

type SearchResult

type SearchResult struct {
	ID            string    `json:"id"`
	Title         string    `json:"title"`
	Description   string    `json:"description"`
	LastUpdate    time.Time `json:"lastUpdateDate"`
	TotalTokens   int       `json:"totalTokens"`
	TotalSnippets int       `json:"totalSnippets"`
	Stars         int       `json:"stars"`
	TrustScore    float64   `json:"trustScore,omitempty"`
}

SearchResult represents a library search result

func (*SearchResult) GetResourceURI

func (s *SearchResult) GetResourceURI() string

GetResourceURI returns the Context7 resource URI for this search result

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL