mirror of
https://github.com/upstash/context7.git
synced 2025-11-30 17:11:41 +00:00
Merge pull request #757 from upstash/feat/env-var-api-key
This commit is contained in:
commit
8bb5ce46c2
38
README.md
38
README.md
@ -518,13 +518,14 @@ it also can be solved tith the full path to Node.js and the installed package:
|
||||
```toml
|
||||
[mcp_servers.context7]
|
||||
command = "/Users/yourname/.nvm/versions/node/v22.14.0/bin/node" # Node.js full path
|
||||
args = ["/Users/yourname/.nvm/versions/node/v22.14.0/lib/node_modules/@upstash/context7-mcp/dist/index.js",
|
||||
args = ["/Users/yourname/.nvm/versions/node/v22.14.0/lib/node_modules/@upstash/context7-mcp/dist/index.js",
|
||||
"--transport",
|
||||
"stdio",
|
||||
"--api-key",
|
||||
"YOUR_API_KEY"
|
||||
]
|
||||
```
|
||||
|
||||
This ensures Codex CLI works reliably on MacOS.
|
||||
|
||||
</details>
|
||||
@ -1136,7 +1137,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 +1151,39 @@ 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 .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