mirror of
https://github.com/upstash/context7.git
synced 2025-11-30 00:50:06 +00:00
feat: add CONTEXT7_API_KEY environment variable support
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
8a6d3445e2
commit
aa8f407906
41
README.md
41
README.md
@ -1136,7 +1136,7 @@ bun run dist/index.js
|
||||
|
||||
- `--transport <stdio|http>` – Transport to use (`stdio` by default). Note that HTTP transport automatically provides both HTTP and SSE endpoints.
|
||||
- `--port <number>` – Port to listen on when using `http` transport (default `3000`).
|
||||
- `--api-key <key>` – API key for authentication. You can get your API key by creating an account at [context7.com/dashboard](https://context7.com/dashboard).
|
||||
- `--api-key <key>` – API key for authentication (or set `CONTEXT7_API_KEY` env var). You can get your API key by creating an account at [context7.com/dashboard](https://context7.com/dashboard).
|
||||
|
||||
Example with HTTP transport and port 8080:
|
||||
|
||||
@ -1150,6 +1150,45 @@ Another example with stdio transport:
|
||||
bun run dist/index.js --transport stdio --api-key YOUR_API_KEY
|
||||
```
|
||||
|
||||
### Environment Variables
|
||||
|
||||
You can use the `CONTEXT7_API_KEY` environment variable instead of passing the `--api-key` flag. This is useful for:
|
||||
- Storing API keys securely in `.env` files
|
||||
- Integration with MCP server setups that use dotenv
|
||||
- Tools that prefer environment variable configuration
|
||||
|
||||
**Note:** The `--api-key` CLI flag takes precedence over the environment variable when both are provided.
|
||||
|
||||
**Example with environment variable:**
|
||||
|
||||
```bash
|
||||
export CONTEXT7_API_KEY=your_api_key_here
|
||||
npx -y @upstash/context7-mcp
|
||||
```
|
||||
|
||||
**Example with .env file:**
|
||||
|
||||
```bash
|
||||
# .env
|
||||
CONTEXT7_API_KEY=your_api_key_here
|
||||
```
|
||||
|
||||
**Example MCP configuration using environment variable:**
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"context7": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@upstash/context7-mcp"],
|
||||
"env": {
|
||||
"CONTEXT7_API_KEY": "YOUR_API_KEY"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary><b>Local Configuration Example</b></summary>
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@ const DEFAULT_PORT = 3000;
|
||||
const program = new Command()
|
||||
.option("--transport <stdio|http>", "transport type", "stdio")
|
||||
.option("--port <number>", "port for HTTP transport", DEFAULT_PORT.toString())
|
||||
.option("--api-key <key>", "API key for authentication")
|
||||
.option("--api-key <key>", "API key for authentication (or set CONTEXT7_API_KEY env var)")
|
||||
.allowUnknownOption() // let MCP Inspector / other wrappers pass through extra flags
|
||||
.parse(process.argv);
|
||||
|
||||
@ -415,7 +415,8 @@ async function main() {
|
||||
startServer(initialPort);
|
||||
} else {
|
||||
// Stdio transport - this is already stateless by nature
|
||||
const server = createServerInstance(undefined, cliOptions.apiKey);
|
||||
const apiKey = cliOptions.apiKey || process.env.CONTEXT7_API_KEY;
|
||||
const server = createServerInstance(undefined, apiKey);
|
||||
const transport = new StdioServerTransport();
|
||||
await server.connect(transport);
|
||||
console.error("Context7 Documentation MCP Server running on stdio");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user