Passing arguments to my console application #166
-
How can I access command-line arguments (like --token) passed to my MCP server in the JSON configuration? I'm setting up a tool with "args": ["--token", "my-token-value"] in the config, but I'm not sure how to retrieve these arguments in my C# implementation. I've successfully implemented the static class example from the readme and it works fine in Claude, but I'm struggling to figure out how to pass the token argument from the JSON config into my tool. Is there a recommended pattern for accessing these values in my tool handlers? I'm a bit new to this, so any guidance would be appreciated |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I think better option is env element than arguments. So, in the client code, you can do something like this var client = await McpClientFactory.CreateAsync(new()
{
Id = "everything",
Name = "Everything",
TransportType = TransportTypes.StdIo,
TransportOptions = new()
{
["command"] = "dotnet",
["arguments"] = @"EveryThingServer.dll",
["env:TOKEN"] = "THIS IS THE TOKEN FROM CLIENT"
}
}, new()
{
ClientInfo = new()
{
Name = "Everything Client",
Version = "1.0.0",
}
}); And in Server you will be able to access it via var token = Environment.GetEnvironmentVariable("TOKEN"); |
Beta Was this translation helpful? Give feedback.
I think better option is env element than arguments. So, in the client code, you can do something like this
And in Server you will be able to access it via
Environment
methods, like this.