-
Notifications
You must be signed in to change notification settings - Fork 3
Configuration Methods
The McpServerInfoBuilder
implements IMcpServerInfoBuilder
and provides numerous methods to configure your MCP server. This document details all available configuration methods with examples.
Loads and parses an OpenAPI/Swagger specification from a URL.
serverInfoBuilder.FromUrl("https://petstore.swagger.io/v2/swagger.json");
Loads and parses an OpenAPI/Swagger specification from a local file.
serverInfoBuilder.FromFile("./swagger/petstore.json");
Loads server configuration from a JSON configuration file.
serverInfoBuilder.FromConfiguration("./config/mcp_server_config.json");
Configures the server using a BuilderConfig
object.
var config = new BuilderConfig
{
Type = "openapi",
ServerName = "PetStore",
ApiSpecUrl = "https://petstore.swagger.io/v2/swagger.json",
// Other configuration properties...
};
serverInfoBuilder.WithConfig(config);
Sets the base URL for API requests.
serverInfoBuilder.WithBaseUrl("https://api.example.com/v1");
Sets a custom HttpClient
instance for making API requests.
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("User-Agent", "Custom Client");
serverInfoBuilder.WithHttpClient(httpClient);
Adds a default header to all HTTP requests.
serverInfoBuilder.AddDefaultHeader("User-Agent", "QuickMCP Client");
serverInfoBuilder.AddDefaultHeader("Accept-Language", "en-US");
Sets the timeout duration for HTTP requests.
serverInfoBuilder.WithTimeout(TimeSpan.FromSeconds(30));
Excludes paths based on a predicate function.
serverInfoBuilder.ExcludePaths(path => path.StartsWith("/admin") || path.Contains("internal"));
Excludes specific paths from the API.
serverInfoBuilder.ExcludePaths(new[] { "/admin/users", "/internal/logs" });
Includes only paths that match a predicate function.
serverInfoBuilder.OnlyForPaths(path => path.StartsWith("/public") || path.StartsWith("/api/v1"));
Includes only specific paths from the API.
serverInfoBuilder.OnlyForPaths(new[] { "/products", "/categories", "/orders" });
Adds an authenticator for API requests.
var apiKeyAuthenticator = new ApiKeyAuthenticator("your-api-key", "X-API-Key", "header");
serverInfoBuilder.AddAuthentication(apiKeyAuthenticator);
Sets default values for path parameters.
serverInfoBuilder.WithDefaultPathParams(new Dictionary<string, string>
{
{ "version", "v1" },
{ "format", "json" }
});
Configures logging for operations and events.
var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddConsole();
builder.SetMinimumLevel(LogLevel.Information);
});
serverInfoBuilder.AddLogging(loggerFactory);
Builds and registers all configured tools with the MCP server.
var serverInfo = await serverInfoBuilder.BuildAsync();
All configuration methods return the builder instance, allowing for method chaining:
var serverInfoBuilder = McpServerInfoBuilder.ForOpenApi()
.FromUrl("https://petstore.swagger.io/v2/swagger.json")
.WithBaseUrl("https://api.example.com")
.AddDefaultHeader("User-Agent", "QuickMCP Client")
.WithTimeout(TimeSpan.FromSeconds(30))
.OnlyForPaths(path => path.StartsWith("/pets"))
.AddAuthentication(new ApiKeyAuthenticator("your-api-key", "X-API-Key", "header"))
.AddLogging(loggerFactory);
var serverInfo = await serverInfoBuilder.BuildAsync();