Skip to content

Add Agent Tools: application services as governed AI tools, with an MCP endpoint and OpenIddict helpers - #26564

Merged
enisn merged 8 commits into
devfrom
feature/agent-tools
Nov 27, 2026
Merged

enisn merged 8 commits into
devfrom
feature/agent-tools

Conversation

@MansurBesleney

Copy link
Copy Markdown
Contributor

Description

No linked issue. This PR adds Agent Tools to the open source framework, with tests and documentation. It replaces the documentation-only draft #26532.

1. Summary

Agent Tools turns the application services and controllers of an ABP application into AI tools that the application governs. Each tool is one HTTP API action, discovered from ABP's API description model and called in-process through its service interface. Every call is permission-checked and tenant-scoped, runs in its own unit of work, and is audit-logged when an audit scope is active (as in HTTP requests). A per-tool policy in appsettings.json or code decides whether a tool is enabled and whether it requires human approval. Any IChatClient can use the tools, and external agents such as Claude Code can use them over an MCP endpoint that needs a bearer token. Nothing is exposed unless the application opts in.

Why in the framework: the value of a tool call is that it runs through ABP's own permissions, tenant, unit of work and audit. Every ABP application has these, so the runtime belongs next to them. Management on top of it (a policy stored per tenant, management pages) is not part of this PR: the commercial module builds on these packages.

2. Packages

Package Place Content Direct dependencies
Volo.Abp.AgentTools.Abstractions framework/src [AgentTool], [DisableAgentTool], AgentToolKind, error codes, feature name, localization (en, tr) Volo.Abp.Localization
Volo.Abp.AgentTools framework/src options, tool definition, schema and validation, argument redaction, provider / invoker / catalog / observer contracts, policy options and the default policy store, feature definition Abstractions, Volo.Abp.Features, Microsoft.Extensions.AI.Abstractions
Volo.Abp.AgentTools.AspNetCore framework/src catalog (discovery), invoker, provider, AI function, startup checks Volo.Abp.AgentTools, Volo.Abp.AspNetCore.Mvc
Volo.Abp.AgentTools.Mcp framework/src the MCP endpoint and its options AspNetCore, ModelContextProtocol.AspNetCore
Volo.Abp.OpenIddict.AgentTools modules/openiddict/src scope and client seed, resource registration, resource permission sync, token audience handler, startup validator Volo.Abp.OpenIddict.AspNetCore

Module classes: AbpAgentToolsAbstractionsModule, AbpAgentToolsModule, AbpAgentToolsAspNetCoreModule, AbpAgentToolsMcpModule, AbpOpenIddictAgentToolsModule. Volo.Abp.AgentTools does not depend on Volo.Abp.Ddd.Domain or MVC.

Existing files changed: framework/Volo.Abp.slnx, modules/openiddict/Volo.Abp.OpenIddict.slnx and .abpmdl, nupkg/common.ps1, Directory.Packages.props (section 5).

3. How it works

  • Discovery uses ABP's API description model, the model of conventional controllers and proxy generation. Exposure is opt-in (AbpAgentToolOptions: remote service name, root path or type predicate), with a MaxTools guard (default 150) that fails at startup. Never tools: anonymous actions, integration services, non-JSON inputs, parameters bound from services or headers, [DisableAgentTool], [RemoteService(false)].
  • Invocation is in-process through the service interface, without an HTTP self-call. Where a service has no interceptor proxy, the invoker runs ABP's authorization, feature, validation and audit services itself. A tool failure is an error line for the model, not an exception (the caller's own cancellation is rethrown).
  • Approval defaults follow the HTTP verb: GET needs no approval; POST, PUT, PATCH and DELETE do. [AgentTool] overrides this in code.
  • Input schemas are built from the interface method and validated at startup. A tool with an invalid schema is left out with an error log (or stops startup, opt-in), because one invalid schema makes a provider refuse the whole request.
  • Chat clients: IAgentToolProvider gives the current user's tools as AIFunctions. A tool that requires approval is wrapped in ApprovalRequiredAIFunction, and is left out for a client without approval support.
  • Feature AgentTools.Enable (default true): when it is off for a tenant, the tool list is empty and every call is refused.
  • Observers: every IAgentToolCallObserver gets one record per call, with redacted arguments.

Policy in appsettings.json

{
  "AgentTools": {
    "Tools": {
      "Product_Delete": { "Enabled": false },
      "Product_Create": { "RequiresApproval": false }
    }
  }
}
  • Per field: the configured value, else the value set with Configure<AbpAgentToolPolicyOptions>, else the code default. It is the same for the host and every tenant, and is read once at startup. The configuration beats Configure on purpose, so a Configure call cannot re-enable what appsettings.json disables. A later PostConfigure or a replaced policy store still can.
  • The section is read strictly. A tool that is not an object, an unknown field or a value other than true / false stops startup, and the message names the key, not the value. The configuration binder is not used here: even with ErrorOnUnknownConfiguration it takes "" and [] as "not set", which would leave a tool enabled.
  • A tool name that is not in the catalog, and settings that look like a policy but are outside the section (a misspelled Tools, a tool directly under AgentTools), are logged as errors at startup. Startup continues, because a configuration may serve several applications.
  • IAgentToolPolicyStore can be replaced. The startup checks run whatever store is registered.

MCP endpoint

  • Stateless Streamable HTTP at /mcp (AbpAgentToolsMcpOptions.Path), mapped by the module through UseConfiguredEndpoints, with an RFC 9728 metadata document at the path-specific well-known URL (/.well-known/oauth-protected-resource/mcp), which the 401 names. The bare well-known path is left to the application.
  • The endpoint has no approval step, so tools that require approval are not listed and are refused by name. The endpoint is therefore read-only by default.
  • A request needs a bearer token in the header (never a cookie), a dedicated scope (AgentTools), a user, and must not name a tenant other than the token's (active) tenant. The application does not start when the endpoint's scheme is not registered or is a cookie or policy scheme.
  • A private MCP server. The MCP SDK keeps its server options (tools, handlers, filters) and transport options once per service container and serves them on every MapMcp endpoint. With a shared registration, two modules that each map an MCP endpoint would serve each other's tools, each without the other's checks, and would share the session mode. So this endpoint has a small service container of its own. McpServerOptions, tools and filters of the application or of another module do not reach it, and no other endpoint serves the agent tools. Other MCP endpoints keep their own AddMcpServer, tools, authorization and metadata.

OpenIddict helpers

  • ABP builds a token's audience from the resources of the requested scopes, and the seeded scope's resource is the MCP URL. A validation handler keeps the tokens of MCP clients at the MCP endpoint: a token whose only API scope is AgentTools (standard scopes such as openid and offline_access do not count) is accepted at the endpoint only, whatever its audiences; so is a token that has the MCP URL as audience and no other audience that the host accepts. The server refuses with invalid_scope a token request of a grant whose only API scope is AgentTools when its scope parameter leaves that scope out. In a host that restricts the audiences it accepts, as the templates do, this keeps a client that is granted only this scope away from the REST API behind the tools it is not offered (the docs tell to restrict them). ConfineScopeToMcpEndpoint = false leaves the decision to the audiences, for an application that gives the scope an API resource on purpose. This applies to hosts that load the package and validate with OpenIddict (not to the endpoints of the OpenIddict server itself); a JwtBearer host uses a scheme of its own for the endpoint (documented).
  • Scope seed, client seed from AgentTools:Mcp:Clients, resource permission sync (every application with the scope gets rsrc:<MCP URL>, which clients that send RFC 8707 resource need), optional S256-only PKCE, token entry validation on by default, and a startup validator (it logs an error when the stored scope does not have the MCP URL as a resource).
  • A separate auth server can use the package: it does not depend on the MCP package.

4. Security notes

  • The tool list is a convenience. The boundary is ABP's check on every call. The policy can only narrow what a user may do.
  • Global MVC filters, the fallback policy and endpoint RequireAuthorization are not applied in-process. Attributes are.
  • Argument redaction works by property name, nested values and JSON inside string values included, within bounds of length and nesting.
  • Error texts for the model are what ABP sends to an HTTP client; stack traces are never included.
  • The endpoint is stateless by construction. The MCP SDK version (1.1.0) is one of the versions that advisory GHSA-x863-g495-4cjc lists for stateful sessions of users without a user id claim. This endpoint keeps no sessions and requires a user. An application that maps a stateful MCP endpoint of its own is responsible for it; the docs say so.
  • The documentation lists the production checklist and the known limits.

5. Compatibility

  • New packages only; no existing public API changes and no behaviour change for an application that does not reference them.
  • For applications that add the packages: Volo.Abp.OpenIddict.AgentTools turns on token entry validation application-wide (one read of the token entry per bearer request; EnableTokenEntryValidation = false opts out), replaces the OpenIddict application store with a subclass, and needs the MCP URL (App:SelfUrl or McpResource) at startup while the resource permission sync is on. Tool schemas list non-nullable value-type DTO properties without a default as required (RequireNonNullableValueTypes); ABP paging and sorting members are exempt.
  • ModelContextProtocol moves from 0.5.0-preview.1 to 1.1.0 (used by Volo.Abp.Cli.Core), so that a stable package does not depend on a preview. ModelContextProtocol.AspNetCore 1.1.0 and Microsoft.Extensions.AI.Abstractions 10.3.0 are new pins. Later SDK versions need a newer Microsoft.Extensions.AI, which has to move together with Semantic Kernel; that is left to a separate change. Volo.Abp.AI still resolves the versions it did.

6. Documentation

Open source pages under docs/en/framework/infrastructure/artificial-intelligence/agent-tools/ (overview, exposing tools, chat clients, policy, MCP endpoint, OpenIddict setup, security notes), and the pages of the commercial module under docs/en/modules/agent-tools/. docs-nav.json, the AI overview page, the module lists, the AI Management page, the React Admin Console page and the licence comparison follow. All relative links and anchors resolve. The C# samples were compiled against the packages, and the startup and precedence rules of the policy page were run in a throwaway application.

7. Testing

Project Tests
framework/test/Volo.Abp.AgentTools.Tests 135
framework/test/Volo.Abp.AgentTools.AspNetCore.Tests 144
framework/test/Volo.Abp.AgentTools.Mcp.Tests 319
modules/openiddict/test/Volo.Abp.OpenIddict.AgentTools.Tests 166
Total 764

All pass, none skipped, after a merge of dev and from clean builds. Also run: Volo.Abp.AI.Tests 13, Volo.Abp.Cli.Core.Tests 246, and the existing OpenIddict tests (AspNetCore 40, Domain 94, EntityFrameworkCore 37, MongoDB 35).

  • The endpoint isolation tests cover both registration orders, attribute tools and handlers, stateful and stateless neighbours and every kind of caller. The policy tests cover the reader, real application starts, the provider, the invoker and MCP list and call. The OpenIddict tests use real tokens and the real endpoint.
  • framework/Volo.Abp.slnx and modules/openiddict/Volo.Abp.OpenIddict.slnx build with 0 errors. The only new warnings are NU1902 (SourceLink), which every project has; one existing NU1903 of Volo.Abp.Cli.Core names another version.
  • dotnet pack of the five packages and of Volo.Abp.Cli.Core succeeds. The four test projects also pass in Release.
  • A throwaway application that references only ABP packages (Kestrel, JwtBearer, the MCP client of the SDK) listed and called tools, answered MCP tools/list and tools/call, refused the bad tokens, and followed the policy from files and environment variables, in Debug and in a published Release build. A second one, built from the packed packages before the last small fixes of this branch, had OpenIddict as the issuer in the application (scope and client seed, code + PKCE, consent, refresh, revocation, two tenants) and clients of the MCP SDK (1.1.0 and 2.4.0) in a separate process.

Not checked: Linux; calls of a model through an MCP client application (Claude Code was connected with claude mcp login and claude mcp list in the demo host of the commercial module, without a model); a running tiered solution (the JwtBearer setup of the docs is compiled, not run); MCP SDK 2.x on the server beyond a probe; framework tests outside the projects above; nupkg/pack.ps1 as a whole; the rendered documentation site.

8. Known limits and follow-ups

  • No approvals over MCP.
  • The resource permission is synchronized in hosts that load Volo.Abp.OpenIddict.AgentTools, and when data is seeded. With a separate auth server, an application saved through another host gets it with the next seed.
  • A misspelled root section (AgentTool:Tools), AgentTools:Enabled directly and scalar values in a misspelled section are not noticed. null (or {}) for a field in a later configuration source undoes an earlier value.
  • The data seeder does not change an existing scope: after a change of the MCP URL, update the scope's resources so that MCP clients are accepted again (an error at startup says so). Tokens whose only API scope is AgentTools stay confined to the endpoint meanwhile.
  • The confinement covers the tokens above. A host that accepts any audience also accepts tokens that were not issued for one of its APIs, so restrict the audiences (documented).
  • Arguments of a tool include input members and parameters that MVC would not fill from the query (for example [BindNever] members of a query DTO); the docs list these cases.

9. Related PRs and merge order

Merge this PR first. The commercial module builds on these packages and follows.

Checklist

  • I fully tested it as developer / designer and created unit / integration tests
  • I documented it (or no need to document or I will create a separate documentation issue)

How to test it?

  1. Create an application with an application service. Add Volo.Abp.AgentTools.Mcp and Volo.Abp.OpenIddict.AgentTools, include the service with AbpAgentToolOptions, and seed a client from AgentTools:Mcp:Clients (see the "OpenIddict Setup" page).
  2. Connect Claude Code: claude mcp add --transport http --client-id claude-code --callback-port 33418 my-app https://<app>/mcp. The list has the read tools that the signed-in user may call.
  3. Set AgentTools:Tools:<tool>:Enabled to false and restart: the tool is gone. Set RequiresApproval to false on a write tool: it is listed.
  4. Misspell a field: the application does not start, and the message names the key.

🤖 Generated with Claude Code

MansurBesleney and others added 7 commits November 18, 2026 14:11
- New docs/en/modules/agent-tools: overview, installation, exposing tools,
  policy and management page, chat clients, MCP endpoint, OpenIddict setup,
  AI Management integration, security notes
- docs-nav.json entry next to AI Management; Agent Tools integration section
  in the AI Management docs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Agent Tools exposes the application services and controllers of an
application as AI tools. Each tool is an HTTP API action, called in-process
through its service interface with ABP's authorization, tenant, unit of work
and audit logging. Nothing is exposed unless the application opts in.

- Volo.Abp.AgentTools.Abstractions: attributes, error codes, feature name and
  localization.
- Volo.Abp.AgentTools: options, abstractions, input schemas, argument
  redaction and the tool policy in appsettings.json or code.
- Volo.Abp.AgentTools.AspNetCore: tool discovery, invocation and the tool
  provider for IChatClient.
- Volo.Abp.AgentTools.Mcp: a stateless MCP endpoint.
- Volo.Abp.OpenIddict.AgentTools: scope, resource and client seed, resource
  permissions and token confinement for the MCP endpoint.

ModelContextProtocol moves to 1.1.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The open source pages (overview, exposing tools, chat clients, policy, MCP
endpoint, OpenIddict setup, security notes) are under the artificial
intelligence section. The Agent Tools module pages cover the per-tenant
management.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MansurBesleney MansurBesleney mentioned this pull request Nov 26, 2026
1 of 2 tasks
@MansurBesleney MansurBesleney self-assigned this Nov 27, 2026
@MansurBesleney MansurBesleney added this to the 11.1-preview milestone Nov 27, 2026
@MansurBesleney
MansurBesleney marked this pull request as ready for review November 27, 2026 08:30
@maliming maliming added the dependency-change Indicates a version change of a dependency (typically, upgrade) label Nov 27, 2026
@enisn
enisn merged commit 4c9fce6 into dev Nov 27, 2026
1 check passed
@enisn
enisn deleted the feature/agent-tools branch November 27, 2026 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

abp-framework dependency-change Indicates a version change of a dependency (typically, upgrade)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants