跳至主要內容
hs-sql-agent

ASP.NET Core · NuGet

只組合你的 .NET host 真正需要的 hs-sql-agent capabilities。

HsSqlAgent.Server 2.0.2 是可嵌入的 ASP.NET Core class library。既有應用保留自己的 authentication 與 controller mapping,再依需求選擇 Admin API、MCP、built-in identity 或 Admin UI。

01

AddHsSqlAgentCore

新 integration 從 optionless core 起手,不再把 legacy all-in-one preset 當主路徑。

02

Composable capabilities

Runtime、Admin store/API、MCP、telemetry、built-in identity 都可以分開選。

03

Host-owned pipeline

既有應用繼續掌握 authentication、authorization middleware 與 MapControllers()。

嵌入既有 ASP.NET Core Host

HsSqlAgent.Server 是 class-library integration surface,不是在你的 application 裡偷偷再開一個 web host。2.0.2 的新 integration 從 AddHsSqlAgentCore() 開始,再明確選擇需要的 capabilities。

如果 application 已經有自己的 login 與 permissions,就把 Admin authorization 委派給 host policy,不需要再安裝 hs-sql-agent 的 built-in member/role identity stack。

ASP.NET Core 2.0.2
var hs = builder.Services.AddHsSqlAgentCore();

hs.AddHsSqlAgentRuntime();
hs.AddHsSqlAgentAdminStore(options =>
{
    options.Provider = "Postgres";
    options.ConnectionString =
        builder.Configuration.GetConnectionString("HsSqlAgent")!;
});
hs.AddHsSqlAgentHostAuthorization("SqlAgentAdmin");
hs.AddHsSqlAgentAdminApi();
hs.AddHsSqlAgentMcp(options =>
{
    options.PublicEndpoint = "https://example.com/mcp";
    options.HmacSecretKey = builder.Configuration["HMAC_KEY"]!;
});

var app = builder.Build();

app.UseAuthentication();
app.UseAuthorization();
app.UseHsSqlAgentMcp();
app.UseHsSqlAgentAdminApi();
app.MapControllers();

Built-in Identity 與 Admin UI 都是 Opt-in

如果 host 想使用 hs-sql-agent 自己的 JWT/member/role model,就選 AddHsSqlAgentBuiltInAuth(),而不是 host authorization;兩種 authorization mode 互斥。

Bundled Admin UI 也不是強制項目。既有 application 可以只 expose Admin API、使用自己的 frontend;需要完整管理介面時再加入 packaged UI。

Embedding 不會改變 SQL Safety Boundary

Hosting topology 改變,但 query compilation、Safe DML、MCP-key scope、policy、provider capability checks 與 audit 仍然走同一條 hs-sql-agent runtime boundary。