- Template: app-nolayers
- Template Type: Modern
- Created ABP Studio Version: 3.1.1
- Current ABP Studio Version: 3.1.6
- Multi-Tenancy: Yes
- UI Framework: react
- Theme: leptonx
- Theme Style: system
- Database Provider: ef
- Database Management System: sqlserver
- Public Website: Yes
- Social Login: Yes
- Include Tests: Yes
- Use Local References: No
- Optional Modules:
- GDPR
- TextTemplateManagement
- AuditLogging
- OpenIddictAdmin
- LowCode
- Elsa
- Selected Languages: Italian, English
- AI Management Enabled: Yes
- Selected AI Providers: OpenAI
- Default Language: Italian
- Create Command: abp new Nicma.Idp -t app-nolayers --modern --modular --ui-framework react --database-provider ef --database-management-system sqlserver --theme leptonx --tests --public-website --without-cms-kit --dont-run-install-libs --dont-run-bundling -no-file-management -no-language-management -low-code --elsa
Hello,
how can i use the current tenant id in a custom server MCP; AI Workspace ABP pass it in header?
My server MCP is a streamable HTTP.
3 Answer(s)
-
0
- ABP’s React UI (modern templates) keeps the selected tenant id in
sessionStorageunderabp_tenant_idand sends it to the backend with the__tenantHTTP header on requests. So, if your MCP server is a custom, separate “streamable HTTP” endpoint, ABP AI Workspace does not automatically forward the current tenant to that external MCP server unless you explicitly implement such forwarding in your MCP server integration. - Therefore, to use the current tenant inside your custom MCP server, you should read it from the incoming request header
__tenant(or, if you are calling your MCP server from your React app directly, make your client include__tenantheader using the value fromsessionStorage['abp_tenant_id']).
Practical approach (custom streamable HTTP MCP server)
Expect this header on your MCP server:
__tenant: <tenantId>(GUID as string)
In ASP.NET Core (example), read it like:
app.MapPost("/mcp", async (HttpContext httpContext) => { var tenantId = httpContext.Request.Headers["__tenant"].ToString(); // may be empty for Host // use tenantId in your logic });- If the MCP server is called from your React UI, add
__tenantheader from:
sessionStorage.getItem("abp_tenant_id")
Sources
- https://abp.io/docs/10.5/framework/ui/react/permission-management (validated)
- https://abp.io/docs/10.2/modules/ai-management (validated)
This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) - ABP’s React UI (modern templates) keeps the selected tenant id in
-
0Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
-
0
Hi,
AI Workspace doesn't forward the current tenant id to MCP servers. The headers you set on the MCP server in AI Management are shared by all tenants, so they can't carry it either.
You can add the header yourself with a message handler on the
HttpClientthat AI Management uses for your MCP server. The client name isMcpClient_+ theNameof your MCP server in AI Management.using System.Net.Http; using System.Threading; using System.Threading.Tasks; using Volo.Abp.DependencyInjection; using Volo.Abp.MultiTenancy; namespace Nicma.Idp; public class McpTenantHeaderHandler : DelegatingHandler, ITransientDependency { private readonly ICurrentTenant _currentTenant; public McpTenantHeaderHandler(ICurrentTenant currentTenant) { _currentTenant = currentTenant; } protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { request.Headers.Remove("__tenant"); if (_currentTenant.Id.HasValue) { request.Headers.TryAddWithoutValidation("__tenant", _currentTenant.Id.Value.ToString()); } return base.SendAsync(request, cancellationToken); } }Then register it in
ConfigureServicesof your host module:context.Services.AddHttpClient("McpClient_<your-mcp-server-name>") .AddHttpMessageHandler<McpTenantHeaderHandler>();When there is no current tenant (host), the header isn't sent. In that case your Node code falls back to
process.env.ABP_TENANT, so remove that fallback if host calls shouldn't use a fixed tenant.AI Management reuses the same MCP session for all tenants of that server. So read
__tenantfrom each tool call's request, not from the request that started the session.Thanks
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
