8000 chore: use cli arguments instead of environment variables by ryanleecode · Pull Request #211 · upstash/context7 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

chore: use cli arguments instead of environment variables #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ The configuration on Windows is slightly different compared to Linux or macOS (*
}
```

### Environment Variables
### Command Line Arguments

- `DEFAULT_MINIMUM_TOKENS`: Set the minimum token count for documentation retrieval (default: 10000).
- `--default-minimum-tokens, -t`: Set the minimum token count for documentation retrieval (default: 10000).

Examples:

Expand All @@ -279,10 +279,7 @@ Examples:
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp"],
"env": {
"DEFAULT_MINIMUM_TOKENS": "10000"
}
"args": ["-y", "@upstash/context7-mcp", "--default-minimum-tokens", "10000"]
}
}
}
Expand Down
Binary file added bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"homepage": "https://github.com/upstash/context7#readme",
"dependencies": {
"@mod 8000 elcontextprotocol/sdk": "^1.8.0",
"dotenv": "^16.5.0",
"commander": "^12.0.0",
"zod": "^3.24.2"
},
"devDependencies": {
Expand Down
38 changes: 25 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,34 @@ 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";
import { Command } from "commander";

// Load environment variables from .env file if present
dotenv.config();
const program = new Command();

program
.name("context7-mcp")
.description(
"Context7 MCP Server - Retrieves up-to-date documentation and code examples for any library"
)
.version("1.0.6")
.option(
"-t, --default-minimum-tokens <number>",
"Set the minimum token count for documentation retrieval",
"10000"
);

program.parse();

const options = program.opts();

// Get DEFAULT_MINIMUM_TOKENS from environment variable or use default
let DEFAULT_MINIMUM_TOKENS = 10000;
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.warn(
`Warning: Invalid DEFAULT_MINIMUM_TOKENS value provided in environment variable. Using default value of 10000`
);
}
const parsedValue = parseInt(options.defaultMinimumTokens, 10);
if (!isNaN(parsedValue) && parsedValue > 0) {
DEFAULT_MINIMUM_TOKENS = parsedValue;
} else {
console.warn(
`Warning: Invalid DEFAULT_MINIMUM_TOKENS value provided. Using default value of 10000`
);
}

// Create server instance
Expand Down
0