Skip to content

Commit 3fae822

Browse files
authored
feat: add header support (#19)
With this PR, you can now pass headers to be added to the MCP config. For stdio-configured servers, the headers just get passed via `--headers` to supergateway. For clients supporting the `url` config option, headers get passed as a `headers` field of type `Record<string, string>`.
2 parents b726ca7 + 9edfd49 commit 3fae822

File tree

3 files changed

+70
-5
lines changed

3 files changed

+70
-5
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ The tool automatically:
3939
- Infers server names from package names or URLs (e.g., `mcp.example.com``mcp-example-com`)
4040
- Handles URL-based servers with supergateway SSE support
4141

42+
### Headers Support
43+
44+
You can pass headers for authentication or other purposes using the `--header` flag:
45+
46+
```bash
47+
# Single header
48+
npx install-mcp https://api.example.com/mcp --client claude --header "Authorization: Bearer token123"
49+
50+
# Multiple headers
51+
npx install-mcp https://api.example.com/mcp --client claude \
52+
--header "Authorization: Bearer token123" \
53+
--header "X-API-Key: secret-key"
54+
```
55+
4256
where `<client>` is one of the following:
4357

4458
- `claude`

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "install-mcp",
3-
"version": "1.0.11",
3+
"version": "1.0.12",
44
"description": "A CLI tool to install and manage MCP servers.",
55
"bin": {
66
"install-mcp": "./bin/run"

src/commands/install.ts

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface InstallArgv {
3737
client: string
3838
local?: boolean
3939
yes?: boolean
40+
header?: string[]
4041
}
4142

4243
export const command = '$0 [target]'
@@ -68,6 +69,11 @@ export function builder(yargs: Argv<InstallArgv>): Argv {
6869
description: 'Skip confirmation prompt',
6970
default: false,
7071
})
72+
.option('header', {
73+
type: 'array',
74+
description: 'Headers to pass to the server (format: "Header: value")',
75+
default: [],
76+
})
7177
}
7278

7379
function isUrl(input: string): boolean {
@@ -117,6 +123,21 @@ function buildCommand(input: string): string {
117123
}
118124
}
119125

126+
function parseHeaders(headers: string[]): Record<string, string> {
127+
const parsedHeaders: Record<string, string> = {}
128+
for (const header of headers) {
129+
const colonIndex = header.indexOf(':')
130+
if (colonIndex !== -1) {
131+
const name = header.substring(0, colonIndex).trim()
132+
const value = header.substring(colonIndex + 1).trim()
133+
if (name && value) {
134+
parsedHeaders[name] = value
135+
}
136+
}
137+
}
138+
return parsedHeaders
139+
}
140+
120141
export async function handler(argv: ArgumentsCamelCase<InstallArgv>) {
121142
if (!argv.client || !clientNames.includes(argv.client)) {
122143
logger.error(`Invalid client: ${argv.client}. Available clients: ${clientNames.join(', ')}`)
@@ -137,12 +158,27 @@ export async function handler(argv: ArgumentsCamelCase<InstallArgv>) {
137158
logger.log('')
138159
logger.info('Warp requires a manual installation through their UI.')
139160
logger.log(' Please copy the following configuration object and add it to your Warp MCP config:\n')
161+
162+
// Build args array for Warp
163+
let warpArgs: string[]
164+
if (isUrl(target)) {
165+
warpArgs = ['-y', 'supergateway', '--sse', target]
166+
// Add headers as arguments for supergateway
167+
if (argv.header && argv.header.length > 0) {
168+
for (const header of argv.header) {
169+
warpArgs.push('--header', header)
170+
}
171+
}
172+
} else {
173+
warpArgs = command.split(' ').slice(1)
174+
}
175+
140176
logger.log(
141177
JSON.stringify(
142178
{
143179
[name]: {
144180
command: isUrl(target) ? 'npx' : command.split(' ')[0],
145-
args: isUrl(target) ? ['-y', 'supergateway', '--sse', target] : command.split(' ').slice(1),
181+
args: warpArgs,
146182
env: {},
147183
working_directory: null,
148184
start_on_launch: true,
@@ -177,13 +213,28 @@ export async function handler(argv: ArgumentsCamelCase<InstallArgv>) {
177213
if (isUrl(target)) {
178214
// URL-based installation
179215
if (['cursor', 'vscode'].includes(argv.client)) {
180-
setServerConfig(config, configKey, name, {
216+
const serverConfig: ClientConfig = {
181217
url: target,
182-
})
218+
}
219+
// Add headers if provided
220+
if (argv.header && argv.header.length > 0) {
221+
const parsedHeaders = parseHeaders(argv.header)
222+
if (Object.keys(parsedHeaders).length > 0) {
223+
serverConfig.headers = parsedHeaders
224+
}
225+
}
226+
setServerConfig(config, configKey, name, serverConfig)
183227
} else {
228+
const args = ['-y', 'supergateway', '--sse', target]
229+
// Add headers as arguments for supergateway
230+
if (argv.header && argv.header.length > 0) {
231+
for (const header of argv.header) {
232+
args.push('--header', header)
233+
}
234+
}
184235
setServerConfig(config, configKey, name, {
185236
command: 'npx',
186-
args: ['-y', 'supergateway', '--sse', target],
237+
args: args,
187238
})
188239
}
189240
} else {

0 commit comments

Comments
 (0)