MCP server in C# for SQL database structure/schema (in Visual Studio) for Github Copilot
04:30 29 Dec 2025

I have a project, that implements a MCP server in C#, let's say this project is called A. A gets the structure of a SQL database (table names, primary keys, foreign keys, and column names) and answers with a big JSON object (via HTTPS). A is running on an internal test server of a company.

I have another project (called B) on my local machine that has this .mcp.json file inside the solution folder (see code).

Now if I ask Github Copilot in B which table/columns does the database has, it answers that it cannot establish a connection to the MCP server. How can I fix that?

If I use cmd on my local machine with this command:

curl -k https://URL/mcp/schema -H "Content-Type": application/json" -H "Authorization: Bearer Token"

The MCP server responds with a JSON object.

Here is my endpoint of the MCP server (inside the Program.cs):

app.MapGet("/mcp/schema", async (IConfiguration config, HttpRequest request) =>
{
    var expectedToken = config["Mcp:AuthToken"];
    if (!string.IsNullOrWhiteSpace(expectedToken))
    {
        var auth = request.Headers.Authorization.ToString();
        if (auth != $"Bearer {expectedToken}")
            return Results.Unauthorized();
    }

    var cs = config.GetConnectionString("Db");
    if (string.IsNullOrEmpty(cs))
        return Results.Problem("Database connection string 'Db' is not configured.");

    try
    {
        var fullSchema = await SqlSchema.GetFullSchemaAsync(cs);
        return Results.Json(fullSchema, new JsonSerializerOptions { WriteIndented = true });
    }
    catch (Exception ex)
    {
        return Results.Problem(ex.Message);
    }
});
{
  "servers": {
    "dbschema": {
      "type": "http",
      "url": "https://URL/mcp/schema",
      "headers": {
        "Authorization": "Bearer Token"
      }
    }
  }
}
c# github-copilot model-context-protocol mcp-server