We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/PARS-DOE/autodocument'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
review.md•2.24 KiB
# OpenRouter Client Documentation
## Overview
The OpenRouter Client module provides a client for communicating with the OpenRouter API using the OpenAI SDK. It allows for generating documentation and content based on code files using large language models (LLMs).
## Key Components
### DocumentationResponse Interface
This interface represents the response from the LLM after generating documentation:
- `content`: The generated documentation content
- `successful`: Boolean indicating if the generation was successful
- `error`: Optional error message if generation failed
### OpenRouterClient Class
This class handles communication with the OpenRouter API and provides methods for generating documentation.
#### Constructor
Creates a new OpenRouter client instance:
- Accepts optional `apiKey` and `model` parameters that override configuration
- Validates the API key's presence
- Initializes an OpenAI client with OpenRouter-specific settings
#### Key Methods
1. **generateWithCustomPrompt**
- Generates content using a custom system prompt
- Parameters:
- `files`: Array of file objects with path and content
- `systemPrompt`: Custom system prompt to use
- `existingContent`: Optional existing content to update
- `isTopLevel`: Whether this is the top level directory
- `childrenContent`: Optional content from child directories
- Returns a `DocumentationResponse`
2. **generateDocumentation**
- Backward compatibility method that generates documentation for files
- Automatically selects an appropriate system prompt based on context
- Parameters similar to `generateWithCustomPrompt`
- Internally calls `generateWithCustomPrompt` with the constructed prompt
## Implementation Details
The client:
- Uses environment variables or passed parameters for configuration
- Sets required headers for OpenRouter API
- Constructs appropriate prompts based on the directory level
- Handles errors and returns structured responses
- Adapts the prompt based on whether files exist in the current directory
- Incorporates information from subdirectories when available
- Considers existing documentation for updates
The implementation ensures proper error handling and provides meaningful feedback when documentation generation fails.