Merge pull request #139 from akbxr/master

This commit is contained in:
Enes Gules 2025-05-01 20:21:10 +03:00 committed by GitHub
commit 7c8e5bdab3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 2 deletions

View File

@ -229,6 +229,25 @@ If you prefer to run the MCP server in a Docker container:
```
*Note: This is an example configuration. Please refer to the specific examples for your MCP client (like Cursor, VS Code, etc.) earlier in this README to adapt the structure (e.g., `mcpServers` vs `servers`). Also, ensure the image name in `args` matches the tag used during the `docker build` command.*
### Environment Variables
- `DEFAULT_MINIMUM_TOKENS`: Set the minimum token count for documentation retrieval (default: 5000).
Examples:
```json
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp@latest"],
"env": {
"DEFAULT_MINIMUM_TOKENS": "10000"
}
}
}
}
```
### Available Tools
- `resolve-library-id`: Resolves a general library name into a Context7-compatible library ID.
@ -236,7 +255,7 @@ If you prefer to run the MCP server in a Docker container:
- `get-library-docs`: Fetches documentation for a library using a Context7-compatible library ID.
- `context7CompatibleLibraryID` (required)
- `topic` (optional): Focus the docs on a specific topic (e.g., "routing", "hooks")
- `tokens` (optional, default 5000): Max number of tokens to return. Values less than 5000 are automatically increased to 5000.
- `tokens` (optional, default 5000): Max number of tokens to return. Values less than the configured `DEFAULT_MINIMUM_TOKENS` value are automatically increased to that value.
## Development

View File

@ -32,6 +32,7 @@
"homepage": "https://github.com/upstash/context7#readme",
"dependencies": {
"@modelcontextprotocol/sdk": "^1.8.0",
"dotenv": "^16.5.0",
"zod": "^3.24.2"
},
"devDependencies": {

View File

@ -5,8 +5,23 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
import { z } from "zod";
import { searchLibraries, fetchLibraryDocumentation } from "./lib/api.js";
import { formatSearchResults } from "./lib/utils.js";
import dotenv from "dotenv";
const DEFAULT_MINIMUM_TOKENS = 5000;
// Load environment variables from .env file if present
dotenv.config();
// Get DEFAULT_MINIMUM_TOKENS from environment variable or use default
let DEFAULT_MINIMUM_TOKENS = 5000;
if (process.env.DEFAULT_MINIMUM_TOKENS) {
const parsedValue = parseInt(process.env.DEFAULT_MINIMUM_TOKENS, 10);
if (!isNaN(parsedValue) && parsedValue > 0) {
DEFAULT_MINIMUM_TOKENS = parsedValue;
} else {
console.error(
`Warning: Invalid DEFAULT_MINIMUM_TOKENS value provided in environment variable. Using default value of 5000`
);
}
}
// Create server instance
const server = new McpServer({