Can't send inline json with additional-mcp-config flag
Describe the bug
I'm trying to add inline json with the additional-mcp-config flag. It seems that the JSON parsing dies on the second character no matter what I do, so I can't even get to the point of configuring my actual MCP server. I assume escaping quotes is the problem, but I've tried multiple ways around it with no luck. The following command fails in Windows powershell:
npx -y @github/copilot@latest --additional-mcp-config '{"mcpServers":{}}'
Output:
Invalid JSON in --additional-mcp-config: Expected property name or '}' in JSON at position 1 (line 1 column 2)
Affected version
0.0.353
Steps to reproduce the behavior
- In windows powershell, run
npx -y @github/copilot@latest --additional-mcp-config '{mcpServers:{}}'
Expected behavior
Copilot is launched. I have an actual mcp server config in my case, but it doesn't launch even if I pass an empty set of servers.
Additional context
- Happens with powershell via windows terminal or directly opening powershell.
@ellismg I saw your comment in #288 mentioning that you made this change recently - would you be able to share details on how you were able to get quote-escaping to work properly? Is there something obvious I'm missing?
That's very interesting, @ArcticZeroo! I thought this could be a powershell quoting issue (I'm on macOS, not windows) but I installed PowerShell 7.5.4 from homebrew, ran pwsh and tried this command:
npx -y @github/copilot@latest --additional-mcp-config '{"mcpServers": { "test-mcp-server": {"type": "local", "command": "npx", "args": ["tsx", "/Users/matell/dd/github/sweagentd/runtime/test/mcp-client/test-mcp-server.ts"], "tools": ["*"]}}}'
This worked for me, and I saw that the configuration got picked up (with this printed to the timeline):
● Configured MCP servers: test-mcp-server
After doing this, I noticed that in your example, the mcpServers token was not double quoted, and so I think things are blowing up just because of invalid JSON?
If I use
npx -y @github/copilot@latest --additional-mcp-config '{"mcpServers":{}}'
(note the additional quotes around mcpServers)
Then copilot launches as expected (of course, no additional MCP servers are configured, since this configuration is empty).
Maybe this helps you unblock yourself? Note, if the quoting ends up being tedious, you can write the JSON into a file and run with --additional-mcp-config @<path-to-json-file>. Prefixing the file path with @ will have us interpret the value as a path to open and read JSON from.
I have found that I had to use single quotes in my shell ('') so that I could use "" in the JSON with ease and not escape double quotes in the JSON string.
Thanks for taking a look @ellismg !
I must have copy/pasted the second command wrong since I tried various methods for quoting the JSON - if you look at the first version of the command in the original post, I did double-quote mcpServers and was still seeing the failure. So it's definitely not just that unfortunately, I suspect this is some Windows-specific weirdness.
I'll look more into using a file path. The reason I was trying to pass a string is because my team's MCP server has user-specific config for environment variables, and we have so far relied on env variables being passed through from whatever VS/VSCode was launched with, but now they need to be manually specified for this case.
I was hoping to have a script that my team runs which launches @github/copilot with a MCP server config that we generate based on their current env variables, and that seems easiest by passing in a JSON string. But it sounds like maybe I'll have to mess around with making temporary JSON files that use the generated config?
Alternatively, if there was a way for the mcp config to let me say "set these specific environment variables to whatever the outer environment variable is", I think that would also solve my problem without needing to generate a new file each time. ie if the config supported "key": "%EnvVariable%"
Anyway, the quoting issue is still not solved for me, but may be out of scope for this project since it seems that it might just be a Windows issue.
Alternatively, if there was a way for the mcp config to let me say "set these specific environment variables to whatever the outer environment variable is", I think that would also solve my problem without needing to generate a new file each time. ie if the config supported "key": "%EnvVariable%"
You should be able to do this in your env block of a configuration of a server:
{
"type": "local",
"command": "npx",
"args": ["tsx", "/Users/matell/dd/github/sweagentd/runtime/test/mcp-client/test-mcp-server.ts"],
"tools": ["*"],
"env": {
"KEY": "${EnvVariable}"
}
}
This will cause an environment varaible named "KEY" to be created in the subprocess that runs the local mcp server, and the value of that will be whatever EnvVariable is set to in the environment of the copilot process.
I think this is what you want and should work for you.